XMPP/Jabber Notifications for new Mails (written for dovecot)

12 Jul

Have I already noted that I love Jabber? Jabber is relly great, and sometime I will write my own bot framework for it. In my oppinion jabber has great opportunities beyond pure chatting. I use Jabber as a kind of notification system for several things. E.g. for nagios (german). And since thunderbird consumes lots of ram only to show a notification about incoming mails, I decided to search a solution to provide Jabber notifications.

Well, it did not work well and the solution is kind of spooky. My first approach was to use Sieve. Sieve is great for filtering Mails on an IMAP server. It also has a module name notify, which defines support for Jabber notification in RFC 5437. Sadly, dovecot does not implement this standard. So I was on my own again.

I decided to write my own solution in Perl. The Net::XMPP Modules has fine support for sending xmpp messages. I could use a IMAP library to search new mails. But that would mark them as „not new“. I decided to take the dirty way by using the same approach that I used for learning spam and ham. I’m using the same file structure here.

First, here’s the script: mailnotify.pl

The first lines define some options:

  • $maildir: base directory to watch (the pattern /var/vmail/domain/user/… is used here)
  • $seenFile: cache which mails were already reported
  • $ignorepattern: pattern which directories are not scanned
  • $user, $server, $pass, $tls: jabber account setup
  • %users: which mail address should be reported to which jabber-account?

If a mail contains a „plain/text“ part, the first 128 characters are sent. Else, if a „text/html“ part is found, the first characters of this part is sent (html tags are removed). Encrypted content is recognized, but cannot be decrypted.

The script runs every few minutes in a cron-job. As in „learning spam and ham“, the script must be able to read the mails. So it has to be run as the mail-user (or as root, which is never good).

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert