Situation: mail server with IMAP only access. Problem: I want to be able to filter mails (put some mails to various folders, mark them as read and so on).
Most new email clients have this ability, but I want a standalone filtering program, as I need to use various email clients to connect to this server.
Generally - something like procmail, but working over IMAP.
The software will be run on Linux or Solaris.
A quick google throws up IMAPFilter which looks like it does what you want:
Depending on your IMAP server, you could simply use some implementation of sieve. I think the best support for sieve is provided by cyrus.
As you already mentioned, procmail is the right way to do this, so you could ask your email provider if they support it just in case - doesn't hurt.
Otherwise, maybe the easiest way is to have an email client always open which does the sorting etc. There used to be locking problems with multiple clients accessing the same IMAP mailbox, but I have not seen those in years.
For sheer lightweightness, you could give Sift a try.
Yet another way is to use the ruby gem imap-filter.
https://github.com/flajann2/imap-filter/blob/master/README.org
And example of the DSL,
https://github.com/flajann2/imap-filter/blob/master/examples/default.imap
The DSL is Ruby-based, but you don't need to know much Ruby to use it. The author promises to provide more examples in the near future, and is open to feature requests and pull requests.
On Linux and Unix operating systems, you can use
fetchmail
to poll your IMAP e-mail account, and pass any new messages toprocmail
. You could configure procmail to run scripts based on regular expression pattern matches in received messages.To do this, you'll need to install the fetchmail and procmail packages. The following configuration allowed me to run a script for every new e-mail message is received in my e-mail account. I used Ubuntu 12.04 LTS.
In
~/.fetchmailrc
:Note the
keep
directive above, which ensures that messages are not removed from the IMAP server after they're retrieved.In
~/.procmailrc
:There are lots of tutorials online for fetchmail and procmail, and also tutorials for how to integrate the two (that's how I came up with the above).
Now if I run
fetchmail
orfetchmail -v
the script/home/username/myscript.sh
runs once for every new message. I can run fetchmail in a cron, or configure fetchmail to run as a daemon with theset daemon 600
directive in.fetchmailrc
(where 600 is the number of seconds between polls).