Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: Steve Corona on October 05, 2007, 02:40:16 PM

Title: Easy SpamAssassin Filtering
Post by: Steve Corona on October 05, 2007, 02:40:16 PM
Hi everyone. We use Roundcube for our companies webmail solution. Unfortunately, we get tons of SPAM- somewhere in the range of about 5/minute. Our MTA filters most of them out and the few that get through are processed by SpamAssassin. Our SpamAssassin setup appends "*****SPAM*****" to the subject line of the email but doesn't remove them from the inbox. This can be a real pain with webmail because the spam emails still clog up your inbox.

So, to combat this situation I wrote up a very simple patch today. It moves all of the email with a specified string into the junk folder, automatically. It's customizable so whatever your email system uses to mark spam- "[SPAM]", "*****SPAM*****", whatever, it can work. It's also very easy to install, you only need to replace one file and add a single configuration option into your main.inc.php file.

You can view the patch here:

http://fusionreactions.com/pages/rcmail (http://fusionreactions.com/pages/rcmail)

Hope it can be useful to everyone. If you have any questions post them here and I'll try to help you. Also, if you're interested in any custom patches please use the contact form on our website. We'd be glad to discuss any opportunities with you.

Enjoy,

Steve Corona
Web Director
Fusion Reactions
Title: Re: Easy SpamAssassin Filtering
Post by: SKaero on October 08, 2007, 03:27:29 AM
Thanks for the post!
Title: Re: Easy SpamAssassin Filtering
Post by: Steve Corona on October 11, 2007, 09:55:08 AM
There is a bug that I missed- SPAM filtering doesn't happen when you login, you need to click on the Inbox after logging in to remove the SPAM.

I'm currently working on a general filtering plug-in right now. I'm thinking a configuration page where you can setup rules to move mail to an arbitrary folder depending on the subject/sender/body/date/etc.

Cheers

Steve Corona
Web Director
http://www.fusionreactions.com (http://www.fusionreactions.com)
Title: Re: Easy SpamAssassin Filtering
Post by: seansan on October 20, 2007, 11:56:18 AM

Nice addition.

It would be nice if one could set the parameter in GLOBAL and this is inherited to user config. The user can then set the string in preferences (by adding label en input field)?

Would it not be nice to add the check for the SPAM string to the beginning of the loop? or add a separate loop before the column format algorithm?

Does the SPAM string need some checking against illegal characters?

regards, Sean
Title: Re: Easy SpamAssassin Filtering
Post by: mrjaguar on October 23, 2007, 03:11:48 AM
Does this filter subject only? or will it also filter by header info?
Title: Re: Easy SpamAssassin Filtering
Post by: thetimp2003 on October 23, 2007, 02:43:36 PM
I haven't been able to get this to work with version 0.1-rc2. Can anyone else confirm this?

I get a blank page after trying to log in...
Title: Re: Easy SpamAssassin Filtering
Post by: Steve Corona on October 25, 2007, 10:49:32 AM
Hi,

@seansan

What do you mean set the param in GLOBAL? The param is set in the config file to change the subject it filters.

@mrjaguar

It only filters the subject. I'd like to eventually add header filtering but I don't have the time yet.

@thetimp2003

I havn't tested it in RC2 yet. I am still running RC1, I'll let you know what changes need to be made if I get time to update our companies roundcube installation today.
Title: Re: Easy SpamAssassin Filtering
Post by: seansan on October 25, 2007, 02:34:37 PM

I mean that a user can set the string in the CONFIG (actually the admin). This variable is then set as default on the user level. I can imagine that different users (maybe not on your system) have different SPAM strings in the attachment. The variable is then also accesible via the preferences window - where a user can override the default value.
Title: Re: Easy SpamAssassin Filtering
Post by: Steve Corona on October 26, 2007, 10:05:46 AM
Quote from: seansan

I mean that a user can set the string in the CONFIG (actually the admin). This variable is then set as default on the user level. I can imagine that different users (maybe not on your system) have different SPAM strings in the attachment. The variable is then also accesible via the preferences window - where a user can override the default value.

Ah- so you are saying, a per user spam string rather than a global one? When I get some time I'd like to improve this script, we'll see what I'm up to this weekend.

Steve Corona
Web Director
Fusion Reactions
Title: Re: Easy SpamAssassin Filtering
Post by: Steve Corona on November 02, 2007, 11:03:54 AM
This patch is broken in RC2. I'm going to have a fix out today :)
Title: Re: Easy SpamAssassin Filtering
Post by: Le Veilleur on November 05, 2007, 04:14:59 AM
Quote from: Steve Corona
This patch is broken in RC2. I'm going to have a fix out today :)
Nice, I'm waiting for it :)

Thank you very much for your work.
Title: Re: Easy SpamAssassin Filtering
Post by: Le Veilleur on November 06, 2007, 09:11:35 AM
Quote from: Steve Corona
This patch is broken in RC2. I'm going to have a fix out today :)

I've modded your patch for the RC2, You can dl it here : http://temp.leveilleur.net/func.rar

So, Your patch work very well, just the little bug that you already know. (Must click on the inbox folder after the login)
Title: Re: Easy SpamAssassin Filtering
Post by: Pierre on November 11, 2007, 05:43:42 AM
Quote from: Le Veilleur

I've modded your patch for the RC2, You can dl it here : http://temp.leveilleur.net/func.rar

So, Your patch work very well, just the little bug that you already know. (Must click on the inbox folder after the login)


I had to slightly modify your patch because strpos return 0 (==false) if the subject header begins with the SPAM tag :

if ( ( strpos( $cont, $CONFIG['spam_subject']) ) && ( $mbox != $CONFIG['junk_mbox'] ) ) {
is now
if ( ( preg_match($CONFIG['spam_subject'],$cont) ) && ( $mbox != $CONFIG['junk_mbox'] ) ) {

and my config line is now

$rcmail_config['spam_subject'] = '/^\*\*\*SPAM\*\*\*/';

as my spamassassin tags spams with ***SPAM***. Works perfectly for me now.

Thanks all for this nice patch.

Title: Re: Easy SpamAssassin Filtering
Post by: Nimrod on December 06, 2007, 10:38:44 PM
Le Veilleur's patched worked perfectly with Pierre's modification :)

Thanks very much to both of you :)

Anyone had any luck with the having to click on Inbox again issue?
Title: Re: Easy SpamAssassin Filtering
Post by: midnightz on December 08, 2007, 08:22:45 AM
I had add some code to filter only INBOX, because, some mailbox should not be filtered.

This code is for filter only in INBOX

if ( $mbox=='INBOX' ) {
 if ( ( preg_match($CONFIG['spam_subject'],$cont) ) && ( $mbox != $CONFIG['junk_mbox'] ) ) {
  $is_spam = 1;
 }
}

OR, filter for others except Trash

if ( $mbox!=$CONFIG['trash_mbox'] && $mbox!=$CONFIG['junk_mbox'] ) {
 if ( preg_match($CONFIG['spam_subject'],$cont) ) {
  $is_spam = 1;
 }
}
Title: Re: Easy SpamAssassin Filtering
Post by: skrieg on December 28, 2007, 06:00:10 AM
Hi,

Since RC2, the func file has completely changed. I cannot use the patch anymore :(

Thanks.
Title: Re: Easy SpamAssassin Filtering
Post by: Jonn3 on December 28, 2007, 09:08:02 AM
It does work. Just use Le Veilleur's file, and the optional modification below his post.
Title: Re: Easy SpamAssassin Filtering
Post by: skrieg on December 28, 2007, 09:20:02 AM
My bad.
Sorry
Works like a charm
Title: Re: Easy SpamAssassin Filtering
Post by: Jonn3 on December 29, 2007, 10:56:43 AM
There is one or two things though.
Have any of you problems deleting mail from Junk folder. If i delete a message, then go to Trash, and then go back to Junk again, it's still there.

The other stuff is in the log.

[29-Dec-2007 13:20:35] PHP Fatal error: Call to undefined function rcmail_deliver_message() in /home/httpd/html/roundcube/program/steps/mail/sendmail.inc on line 306

&

[28-Dec-2007 14:45:05] PHP Fatal error: Cannot redeclare rcmail_mailbox_list() (previously declared in /home/httpd/html/roundcube/program/include/main.inc:1595) in /home/httpd/html/roundcube/program/steps/mail/func.inc on line 144

Hopefully we can get a new file which is up to date...
Title: Re: Easy SpamAssassin Filtering
Post by: Jonn3 on December 29, 2007, 08:16:56 PM
Ok, with the old func.inc file, you can't send mail. We need an update for this asap.
Please check if you can send mail, and report back.
Title: Easy SpamAssassin Filtering
Post by: sphinx4 on February 18, 2009, 05:18:37 AM
The last post is old, i know, but if also someone is wondering, why deleted junkmails never could be deletet, just add this code

if ( $mbox=='INBOX' ) {
if ( ( preg_match($CONFIG['spam_subject'],$cont) ) && ( $mbox != $CONFIG['junk_mbox'] ) ) {
$is_spam = 1;
}
}

to the patch.

Hope this helps someone.
Title: Easy SpamAssassin Filtering
Post by: Giulio on February 18, 2009, 11:33:50 AM
Is this patch works with 0.2 stable?
Title: Easy SpamAssassin Filtering
Post by: loop on February 24, 2009, 06:31:06 AM
Hello
In 0.2 stable I manually put lines like this into func.inc:
// START MODIFICATION (1 of 4)  BY steve@fusionreactions.com - SPAM FIX
[...]
// END MODIFICATION
Because when I replace func.inc Roundcube don't work. If someone want's I can do a patch file


But problem was in main.inc:
$rcmail_config['spam_subject'] = '***SPAM***';

I don't know how describe tag which puts Spamassassin. Listed above doesn't work.

Works:
$rcmail_config['spam_subject'] = 'SPAM';

But how to do something like this /^\*\*\*SPAM\*\*\*/ in that var?

Regards, Peter
Title: Easy SpamAssassin Filtering
Post by: fkw on March 07, 2009, 02:17:00 PM
Quote from: loop;17266
I don't know how describe tag which puts Spamassassin. Listed above doesn't work.

Works:
$rcmail_config['spam_subject'] = 'SPAM';

But how to do something like this /^\*\*\*SPAM\*\*\*/ in that var?

Regards, Peter


Hello,

try something like this for ***SAPM***:
$rcmail_config['spam_subject'] = '/^\*\*\*SPAM\*\*\*/';

or you can also change the comment from SpamAssassin about your setting for the mailbox.

Regards, fkw
Title: Easy SpamAssassin Filtering
Post by: zamri on March 07, 2009, 11:29:15 PM
Does anyone prepare for 0.2stable patch of this plugin?
Title: Problems with unread messages counter
Post by: mark_valley on March 10, 2009, 03:30:27 PM
Hello everyone. It seems there isn't no comments in this topic for a long time... :confused:

I work in a brazilian university and recently we adopted Roundcube 0.2 as our webmail client.  Well, spams are a huge problem here and we have lots of users complaining about some kind of spam filtering.

To resolve this e adapted the code presented in this topic and I could get the messages tagged by spamassassin moved to the junk folder.

The problem is that the Inbox unread counter isnĀ“t updated until i click it for the second time and my users continue complaining... :mad:

In my code (inside rcmail_js_message_list function), it seems that the following line used to update INBOX doesn't work at all:

$OUTPUT->command('set_unread_count', 'INBOX', $IMAP->messagecount('INBOX', 'UNSEEN'));


I am a bit confused because after that line i added the following one to actualize the junk_box unread message counter and it worked pretty well:

$OUTPUT->command('set_unread_count', $CONFIG['junk_mbox'],         $IMAP->messagecount($CONFIG['junk_mbox'], 'UNSEEN'));


Can anyone help me?

PS.: If a solution was developed since 2007 I would be very glad to know.
Title: Easy SpamAssassin Filtering
Post by: woOtzee on April 03, 2009, 09:38:31 AM
It's sad this fix doesn't work anymore.

Will there any in the future ?
Spam is a big problem for me, i'm searching for a solution.
Title: Easy SpamAssassin Filtering
Post by: woOtzee on April 04, 2009, 01:21:27 PM
Ok.

I found a script by midnightz  ( http://www.roundcubeforum.net/plug-ins/2565-replacement-easy-spamassassin-filtering.html )

I just made it more simple :


You just have to edit ./program/steps/mail/func.inc, ~line 245

After :

  // create row for each message
  foreach ($a_headers as $i => $header)  //while (list($i, $header) = each($a_headers))
    {

Add :


  // ******************************************************
  // ADD by woOtzee.com SPAM FIX

   $spamfix_subject = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));
   if ($mbox!=$CONFIG['trash_mbox'] && $mbox!=$CONFIG['junk_mbox']) {
     if (preg_match("'^\[SPAM\]'",$spamfix_subject) && !$header->seen) {
        $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
        continue;
     }
   }

  // ADD by woOtzee.com SPAM FIX
  // ******************************************************


All unread mail marked as spam will be redirect to your junk box.
If you se a mail witch isn't spam in junk box, just mark it as read, and put it again
in the inbox box.

But, you need to clic on the mail icon on the top of the page to make it works.

If your spam tag isn't [SPAM] but, ***SPAM*** for exemple, like in the begin of
this post, just replace :
^\[SPAM\]
by :
/^\*\*\*SPAM\*\*\*/


Hope there's no mistake, it works for me !
Title: Easy SpamAssassin Filtering
Post by: lhwparis on April 24, 2009, 04:51:25 AM
Hello together,
is there now any Version of this SpamAssassin Filter which works definitivly with the newest roundcube version (0.2.1) ?
I use 0.1 untill now because i need this plugin :/

Thankst for your help.
Title: Easy SpamAssassin Filtering
Post by: dawn on April 29, 2009, 09:26:55 AM
@woOtzee: First of all thanks a lot for your fix. But do I overlook something? I've inserted your code (in my case for "***SPAM***") at the place you told, but I don't see anything happen. Do I add other code too? Is this really working for 0.2.1 stable?

Code: [Select]
   // **************************************************
    // ADD by woOtzee.com SPAM FIX

    $spamfix_subject = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));

    if ($mbox!=$CONFIG['trash_mbox'] && $mbox!=$CONFIG['junk_mbox']) {
        if (preg_match("'/^\*\*\*SPAM\*\*\*/'",$spamfix_subject) && !$header->seen) {
            $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
            continue;
        }
    }

    // ADD by woOtzee.com SPAM FIX
    // **************************************************

Best regards,
Dawn
Title: Easy SpamAssassin Filtering
Post by: CyborgBBR on May 14, 2009, 09:10:18 AM
Hello dawn.

I've copied your Code.
But it doesn't work.

Mails with ***SPAM*** in the subject stay in my standard inbox.

Any other idea how i can filter spam mails?
Title: Looking for a working patch, too.
Post by: akn on October 25, 2010, 11:08:17 AM
Any news here? A patch for the current version would be nice, since my provider does not use Sieve etc. I have to move the spam messages afterwards in roundcube.
Title: Looking for a working patch for the current version (0.4.2).
Post by: akn on October 25, 2010, 11:18:05 AM
The script is not working for the current version of RoundCube (0.4.2). Does anyone have a working one?
Title: Counting of unread messages in inbox folder after moving the spam message(s).
Post by: akn on October 26, 2010, 04:17:12 AM
Quote from: woOtzee;18259

  // ******************************************************
  // ADD by woOtzee.com SPAM FIX

   $spamfix_subject = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));
   if ($mbox!=$CONFIG['trash_mbox'] && $mbox!=$CONFIG['junk_mbox']) {
     if (preg_match("'^\[SPAM\]'",$spamfix_subject) && !$header->seen) {
        $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
        continue;
     }
   }

  // ADD by woOtzee.com SPAM FIX
  // ******************************************************

The script works for me even in version 0.4.2, but there's one detail: The message count in the folder panel does not work properly.

When I start roundcube and there is a spam message within the inbox, the message is moved instantly, but there remains a (1) for the inbox in folder panel until the next time roundcube checks for new mails or manual refresh.

I'm looking for some code which brings roundcube to count again after moving the message... ???
Title: Easy SpamAssassin Filtering
Post by: F0iL on November 24, 2010, 03:07:41 AM
Quote from: akn;30911
The script works for me even in version 0.4.2, but there's one detail: The message count in the folder panel does not work properly.

Where did you put this part of code?
In 0.3.1 everything was fine, but in 0.4.2 I can't find suitable place in /program/steps/email/func.php for this :(