Author Topic: Plugin "MarkAsJunk2" and SpamAssassin  (Read 12508 times)

Offline customhost

  • Newbie
  • *
  • Posts: 2
Plugin "MarkAsJunk2" and SpamAssassin
« on: November 23, 2010, 04:13:20 AM »
Hi all,

I'm using the Roundcube plugin "MarkAsJunk2" (Roundcube Plugins & Patches) in order to enable my clients to self-train SpamAssasin. I'm using Roundcube and SpamAssassin in connection with ISPConfig 3.

Unfortunately, the "Mark as Junk" function doesn't work as expected. Below is the corresponding snippet from my MarkAsJunk2 configuration file:


/**
 * MarkAsJunk2 configuration file
 */

// Learning driver
// Use an external process such as sa-learn to learn from spam/ham messages. Default: null.
// Please see the README for more information
$rcmail_config['markasjunk2_learning_driver'] = 'cmd_learn';

// Mark messages as read when reporting them as spam
$rcmail_config['markasjunk2_read_spam'] = true;

// Mark messages as unread when reporting them as ham
$rcmail_config['markasjunk2_unread_ham'] = false;

// When reporting a message as ham, if the orginial message is attached (like with SpamAssassin reports),
// detach the orginial message and move that to the INBOX, deleteing the spam report
$rcmail_config['markasjunk2_detach_ham'] = true;

// Add flag to messages marked as spam (flag will be removed when marking as ham)
// If you do not want to use message flags set this to null
$rcmail_config['markasjunk2_spam_flag'] = 'Junk';

// Add flag to messages marked as ham (flag will be removed when marking as spam)
// If you do not want to use message flags set this to null
$rcmail_config['markasjunk2_ham_flag'] = null;

// Write output from spam/ham commands to the log for debug
$rcmail_config['markasjunk2_debug'] = true;

// Show icon on mailbox toolbar
// The mark as spam/ham icon can either be displayed on the toolbar or as part of the mark messages menu
$rcmail_config['markasjunk2_mb_toolbar'] = true;

// cmd_learn Driver options
// ------------------------
// The command used to learn that a message is spam
// The command can contain the following macros that will be expanded as follows:
//      %u is replaced with the username (from the session info)
//      %l is replaced with the local part of the username (if the username is an email address)
//      %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
//      %f is replaced with the path to the message file (THIS SHOULD ALWAYS BE PRESENT)
// If you do not want run the command set this to null
$rcmail_config['markasjunk2_spam_cmd'] = 'sa-learn --spam %f';

// The command used to learn that a message is ham
// The command can contain the following macros that will be expanded as follows:
//      %u is replaced with the username (from the session info)
//      %l is replaced with the local part of the username (if the username is an email address)
//      %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not)
//      %f is replaced with the path to the message file (THIS SHOULD ALWAYS BE PRESENT)
// If you do not want run the command set this to null
$rcmail_config['markasjunk2_ham_cmd'] = 'sa-learn --ham %f';


The debug log shows the following entries:

Code: [Select]

[23-Nov-2010 08:05:36 +0100]: sa-learn --spam /var/www/webmail/temp/rcmSALearn2cBzEI
[23-Nov-2010 08:05:36 +0100]: array (
  0 => 'Learned tokens from 0 message(s) (1 message(s) examined)',
)


So the message location seems to be allright but SpamAssassin doesn't seem to learn from the messages because even though I mark them as Junk, they are moved to the Junk folder and the sa-learn command is executed, when a similar email message arrives later the day, it is again not tagged as Junk.

Could somebody please help me with this? I'm really clueless at the moment ...

Could this be an issue with ISPConfig 3?

Any help is greatly appreciated!

Thank you very much in advance!

Cheers,
Eric

Offline mmaraghy

  • Jr. Member
  • **
  • Posts: 28
Plugin "MarkAsJunk2" and SpamAssassin
« Reply #1 on: November 23, 2010, 07:53:22 AM »
I think the issue is with your spam and ham commands. You need to tell MarkAsJunk2 where the sa-learn command can be found and I also have my commands point the location of the user_prefs file. The commands should look something like this:

Code: [Select]

$rcmail_config['markasjunk2_spam_cmd'] = '/usr/bin/sa-learn --spam --prefs-file=/home/.spamassassin/user_prefs %f';

$rcmail_config['markasjunk2_ham_cmd'] = '/usr/bin/sa-learn --ham --prefs-file=/home/.spamassassin/user_prefs %f';


Be sure to modify the directories to reflect your configuration and watch your punctuation--I was pulling my hair out with this plugin and it turned out I missed a slash in my command.

Let us know if this works.

Offline customhost

  • Newbie
  • *
  • Posts: 2
Plugin "MarkAsJunk2" and SpamAssassin
« Reply #2 on: November 24, 2010, 04:41:34 AM »
Thank you very much for taking the time to answer my question.

Unfortunately, specifying the full file path to sa-learn doesn't help. It still says "Learned tokens from 0 message(s) (1 message(s) examined)".

Also, ISPConfig 3 seems to use Amavis to integrate SpamAssassin and only seems to have a global configuration file. I searched the whole server for any "user_prefs" folder but nothing was found.

Do you maybe have any other ideas? What does this message from SpamAssassin mean exactly, btw? Should it tell me that the message is already known by SA so that the tokens don't need to be learned? If so, why is the message not tagged as Junk then?

Thanks once again!

Cheers,
Eric

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,044
Plugin "MarkAsJunk2" and SpamAssassin
« Reply #3 on: November 24, 2010, 01:29:30 PM »
try running sa-learn in debug mode and then enabling debug mode in the plugin so you can see exactly where the problem is coming from, it could be you just need the dbpath parmater or something take a look here http://www.roundcubeforum.net/7-third-party-contributions/46-api-based-plugins/6544-markasjunk2.html
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline andros69

  • Jr. Member
  • **
  • Posts: 29
Plugin "MarkAsJunk2" and SpamAssassin
« Reply #4 on: November 24, 2010, 01:29:42 PM »
So it is possible to train SA using this plugin? I'm having a really hard time with spam, and my SA is not catching a bunch of it. Was hoping this plugin would do the trick but not being very familiar with the SA configuration found it really daunting so I didn't try.

Offline kshots

  • Newbie
  • *
  • Posts: 2
Re: Plugin "MarkAsJunk2" and SpamAssassin
« Reply #5 on: June 19, 2014, 02:44:47 PM »
Just ran into this as well. I realize this is old, but I saw no actual solutions posted looking similar to what I have... Luckily, I was able to resolve my problem. Turns out, when I turned debugging on (by passing the '-D' parameter to the sa-learn command and redirecting stderr to stdout ( 2>&1 at the tail end of the arguments)), I found a huge amount of information from sa-learn... including a permission denied in attempting to access one of my spamassassin config files (local.cf).

This file had lots of fun data like my SQL password and similar, so of course I made it world unreadable... but I had it set to be read by the group 'spamd'.

All I had to do to fix this was a 'gpasswd -a spamd apache' to add the apache user to the spamd group, restart my php-fpm service (the equivalent of apache) so that the service is now running with the spamd group privileges, and suddenly sa-learn was able to work properly. Hopefully that will save someone else some valuable time :/.