UPDATE:  The changes have been merged in the markasjunk2 plugin, with additional improvements. Check it out, and do not use my patch ;) https://github.com/JohnDoh/Roundcube-Plugin-Mark-as-Junk-2

I finally took the time to integrate my DSPAM setup with the Roundcube plugin markasjunk2.Roundcube DSPAM

markasjunk2 ships several drivers, one of them being cmd_learn.php which allows to send an external command to learn spam or ham.

Initially designed to be used with salearn from SpamAssassin, it can be reused with DSPAM to learn spam and ham. But the main problem I had was to retrieve the DSPAM Signature from the email headers, and use it in the command line executed by markasjunk2.

After a bit of coding (and a lot of time wasted trying to use hooks and store datas in sessions), I ended up with a very small hack of the cmd_learn.php driver. It adds two macro:

  • %i is replaced with the user's email address (used as DSPAM identifier)
  • %s is replaced with the x-dspam-signature of the message being marked (either as spam or ham)

This is used to built a command line of the type:

/usr/bin/dspam --source=error --class=spam --user %i --signature=%s

or, for ham:

/usr/bin/dspam --source=error --class=innocent --user %i --signature=%s

You can get the patched cmd_learn.php driver from here: cmd_learn-patch-dspam.php

There is also a configuration sample that I use with DSPAM: markasjunk2 config dspam

(sorry for the colors, the html is generated by vim and I didn't take the time to change the pink and light blue...)

Now your DSPAM setup needs a bit of a configuration as well. By default, your Apache/Nginx/<your webserver> should not be allowed to access DSPAM configuration file, binary, stats, etc... And we need to change that.

On my setup, I had to do the following: User www-data must be able to :

  • execute /usr/bin/dspam
chmod go+x /usr/bin/dspam
  • read /etc/dspam/dspam.conf
chmod go+x /etc/dspam
chmod go+r /etc/dspam/dspam.conf
  • Be trusted in dspam.conf
add "Trust www-data" to dspam.conf
  • Be in dspam group to read and write in /var/spool/dspam
usermod -a -G dspam www-data

With all that, the user www-data should be able to communicate to dspam. You can check the dspam command using su:

su www-data -c "/usr/bin/dspam --source=error --class=spam --user jean-kevin@example.net --signature=4ciuehq1092dno1i1812hd91"

And control that the corresponding message has been retrained in /var/spool/dspam/system.log.


New icons

I am far from being a designer, but I wanted icons that would be more explicit. I then changed the mail_toolbar.png from the default skin to something closer to DSPAM's icon. The result is below:
If you want to use them, replace the file mail_toolbar.png from <roundcubemail>/plugins/markasjunk2/skins/default/ with the one above.

(note: there are more icons to change, the miniatures for contextmenu, the gif for IE6. I didn't change them, but feel free to do so).

The result looks like that: