Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

5 Answers 5

up vote 6 down vote accepted

A quick google throws up IMAPFilter which looks like it does what you want:

  • Searching of messages using many available criteria in the IMAP protocol, such as:
    • Status (recent, unread, etc.) of a message.
    • Size of a message.
    • Age of a message.
    • Matching of a string or a regular expression pattern in the headers or the body of a message.
  • Ability to use logical operators (and/or/not) while searching messages.
  • Different capabilities available to process messages, including:
    • Deleting messages.
    • Moving messages to a mailbox in the same or different servers
    • Copying messages to a mailbox in the same or different servers.
    • Marking messages or changing message flags.
  • Listing of the available and/or subscribed mailboxes, along with support for the IMAP CHILDREN extension.
  • Creating, deleting, renaming, subscribing or unsubscribing mailboxes
  • Internationalisation (I18N) support.
  • Server namespace support using the IMAP NAMESPACE extension.
  • Secure Socket Layer (SSL) or Transport Layer Security (TLS) encrypted imaps (port 993) connections.
  • Encrypted connections using the IMAP STARTTLS extension.
  • User authentication with the Challenge-Response Authentication Mechanism (CRAM), specifically CRAM-MD5.
  • Perl Compatible Regular Expressions (PCRE) support.
share|improve this answer

Depending on your IMAP server, you could simply use some implementation of sieve. I think the best support for sieve is provided by cyrus.

share|improve this answer
    
Well - the solution i'm looking for cannot depend in any way on the server. I have to assume the server is just a dumb IMAP, with no support to nothing smart. –  user13185 Jul 24 '09 at 11:33

For sheer lightweightness, you could give Sift a try.

share|improve this answer
    
i wish i had tried this before imapfilter. –  Good Time Tribe Feb 16 '13 at 5:51

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.

share|improve this answer

On Linux and Unix operating systems, you can use fetchmail to poll your IMAP e-mail account, and pass any new messages to procmail. 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:

# .fetchmailrc checks my e-mail account for new messages, sends them to procmail

set logfile /home/myusername/fetchmail.log

poll mail.domain.com protocol IMAP
    user "emailaccountname"
    password 'emailpassword'
    folder 'INBOX'
    keep
    ssl
    mda "/usr/bin/procmail -f %F"

Note the keep directive above, which ensures that messages are not removed from the IMAP server after they're retrieved.

In ~/.procmailrc:

# .procmailrc received e-mails from fetchmail and runs a script
PATH=/usr/bin:/usr/local/bin
LOGFILE=/home/username/procmail.log
SHELL=/bin/sh

# This rule triggers for every e-mail message:
:0
| `/home/username/myscript.sh`

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 or fetchmail -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 the set daemon 600 directive in .fetchmailrc (where 600 is the number of seconds between polls).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.