Author Topic: Easy SpamAssassin Filtering  (Read 37186 times)

Offline Steve Corona

  • Newbie
  • *
  • Posts: 7
Easy SpamAssassin Filtering
« 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

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

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: Easy SpamAssassin Filtering
« Reply #1 on: October 08, 2007, 03:27:29 AM »
Thanks for the post!

Offline Steve Corona

  • Newbie
  • *
  • Posts: 7
Re: Easy SpamAssassin Filtering
« Reply #2 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

Offline seansan

  • Jr. Member
  • **
  • Posts: 84
Re: Easy SpamAssassin Filtering
« Reply #3 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

Offline mrjaguar

  • Jr. Member
  • **
  • Posts: 16
Re: Easy SpamAssassin Filtering
« Reply #4 on: October 23, 2007, 03:11:48 AM »
Does this filter subject only? or will it also filter by header info?

Offline thetimp2003

  • Newbie
  • *
  • Posts: 1
Re: Easy SpamAssassin Filtering
« Reply #5 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...

Offline Steve Corona

  • Newbie
  • *
  • Posts: 7
Re: Easy SpamAssassin Filtering
« Reply #6 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.

Offline seansan

  • Jr. Member
  • **
  • Posts: 84
Re: Easy SpamAssassin Filtering
« Reply #7 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.

Offline Steve Corona

  • Newbie
  • *
  • Posts: 7
Re: Easy SpamAssassin Filtering
« Reply #8 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

Offline Steve Corona

  • Newbie
  • *
  • Posts: 7
Re: Easy SpamAssassin Filtering
« Reply #9 on: November 02, 2007, 11:03:54 AM »
This patch is broken in RC2. I'm going to have a fix out today :)

Offline Le Veilleur

  • Newbie
  • *
  • Posts: 6
Re: Easy SpamAssassin Filtering
« Reply #10 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.

Offline Le Veilleur

  • Newbie
  • *
  • Posts: 6
Re: Easy SpamAssassin Filtering
« Reply #11 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)

Offline Pierre

  • Newbie
  • *
  • Posts: 1
Re: Easy SpamAssassin Filtering
« Reply #12 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.


Offline Nimrod

  • Newbie
  • *
  • Posts: 3
Re: Easy SpamAssassin Filtering
« Reply #13 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?

Offline midnightz

  • Jr. Member
  • **
  • Posts: 10
Re: Easy SpamAssassin Filtering
« Reply #14 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;
 }
}