Multiple concurrent fetchmails

There's one very useful feature that I recently discovered that fetchmail can't do. While it has wonderful support for IMAP IDLE on a single server, it cannot do multiple concurrent IDLEs on servers. Polling yes, but not IDLEing.

The solution, you might think, is to run multiple instances of fetchmail. Indeed it is; it's just non-trivial to arrange this. Without some careful poking, it's difficult to arrange for this. The trick is to use the $FETCHMAILHOME environment variable to override where fetchmail looks for its config files.

The following script, therefore, automatically does this, based on a setup of config files. Each instance of fetchmail that is required, has associated with it, a config directory. All these directories live in some main home.

In its default setup, the directories all live in $HOME/etc/fetchmail. Each directory within this is then used, by the script, to contain the config and run-time files for one instance of fetchmail. Instances can be started and stopped all together, or individually, and the running state can be inspected. All of these are available as command-line options, and are documented by the --help option.

This script has the .sh extension just for the benefit of the web browser, and should be installed somewhere in the $PATH and marked as executable.