--- controller.c.orig 2018-02-01 14:11:57.000000000 -0800 +++ controller.c 2021-10-05 15:04:37.682975000 -0700 @@ -188,6 +188,24 @@ return -1; } + /* + * Don't allow the attrib or modify flags for a directory. + * It results in a file descriptor being opened for every single file + * in the directory, which can be insane if, for example, the directory + * is a maildir folder with hundreds of thousands of messages in it. + * Unfortunately the KDE directory watcher in the kcoreaddons framework + * library always sets IN_ATTRIB and IN_MODIFY which means this will + * in fact happen with KMail. + * (The Qt filesystem watcher also uses IN_ATTRIB, which is why this + * hack is being applied here, to kill two birds with one stone.) + * Note that this is only a workaround: really the correct thing to do + * is to fix the design to eliminate this side effect, but I'm not + * sure how to do that. For now at least, this makes KMail behave. + */ + + if (S_ISDIR(st.st_mode)) + mask &= ~(IN_ATTRIB|IN_MODIFY); + worker_cmd_add (&cmd, name, mask); return worker_exec (fd, &cmd); }