Author Topic: Replacement of Easy SpamAssassin Filtering  (Read 11401 times)

Offline midnightz

  • Jr. Member
  • **
  • Posts: 10
Replacement of Easy SpamAssassin Filtering
« on: February 09, 2008, 04:52:43 AM »
This modification supports to:
 - Filter your spam mail after you have loged in.
 - Filter your spam mail after click any mailbox, except Junk and Trash.

Based on Steve Corona's modification at http://roundcubeforum.net/forum/index.php?topic=2205.0


Adding codes in config/main.inc.php.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// keyword for subject filtering and move to Junk box
$rcmail_config['spam_subject'] = '/^\*\*\*SPAM\*\*\*/';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Adding a message in program/localization//messages.inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$messages['spammessagesfound'] = '$nr of your spam message(s) was moved to $mbox';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Modify codes in program/step/mail/func.inc (SVN 1032)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// return the message list as HTML table
function rcmail_message_list($attrib)
  :
  :
 $a_js_message_arr = array();
     
// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
 $n_of_spam = 0;
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX

     
 // create row for each message
 foreach ($a_headers as $i => $header) //while (list($i, $header) = each($a_headers))
  {  
   
// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
  $cont = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));
   
  // Check to see if this subject contains our spam line and is not in the
  // designated junk mailbox
     
  if ( ( $mbox!=$CONFIG['trash_mbox'] ) && ( $mbox!=$CONFIG['junk_mbox'] ) ){
   if ( preg_match($CONFIG['spam_subject'], $cont) ){
    $n_of_spam += 1;
    // Move the message from this mailbox to the junk mail box
    $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
    continue;
   }
  }
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


  $message_icon = $attach_icon = '';
  $js_row_arr = array();
  $zebra_class = $i%2 ? 'even' : 'odd';
  :
  :
 $OUTPUT->include_script('list.js');

// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
 if ( $n_of_spam ) {
  $OUTPUT->command('set_unread_count', $CONFIG['junk_mbox'], $IMAP->messagecount($CONFIG['junk_mbox'], 'UNSEEN'));
  $OUTPUT->show_message('spammessagesfound', 'warning', array('nr' => $n_of_spam, 'mbox' => rcube_label("junk")));
 }
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


 return $out;

}
:
:
// return javascript commands to add rows to the message list
function rcmail_js_message_list($a_headers, $insert_top=FALSE)
  :
  :
 $OUTPUT->command('set_message_coltypes', $a_show_cols);

// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
 $n_of_spam = 0;
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


 // loop through message headers
 foreach ($a_headers as $n => $header)
  {
  $a_msg_cols = array();
  $a_msg_flags = array();

  if (empty($header))
   continue;

// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
  $cont = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));
  if ( ( $mbox!=$CONFIG['trash_mbox'] ) && ( $mbox!=$CONFIG['junk_mbox'] ) ){
   if ( preg_match($CONFIG['spam_subject'],$cont) ){
    $n_of_spam += 1;
    $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
    continue;
   }
  }
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


  // format each col; similar as in rcmail_message_list()
  foreach ($a_show_cols as $col)
  :
  :
  $OUTPUT->command('add_message_row',
   $header->uid,
   $a_msg_cols,
   $a_msg_flags,
   preg_match("/multipart\/m/i", $header->ctype),
   $insert_top);
  }

// START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
  if ( $n_of_spam ) {
   $OUTPUT->command('set_unread_count', $CONFIG['junk_mbox'], $IMAP->messagecount($CONFIG['junk_mbox'], 'UNSEEN'));
   $OUTPUT->show_message('spammessagesfound', 'warning', array('nr' => $n_of_spam, 'mbox' => rcube_label("junk")));
  }
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Offline tman

  • Newbie
  • *
  • Posts: 2
Re: Replacement of Easy SpamAssassin Filtering - Problem
« Reply #1 on: February 12, 2008, 12:50:40 AM »
Thanks for the code. I have performed the above code snippet inserts, and just end up with a blank page once logged in. I have triple checked my code and it seems right.

Any idea's? I have attached my func.inc.

I am running latest SVN.

Offline midnightz

  • Jr. Member
  • **
  • Posts: 10
Re: Replacement of Easy SpamAssassin Filtering
« Reply #2 on: February 13, 2008, 01:15:27 PM »
I have found special char in your pasted code.

 // START MODIFICATION BY midnightz@hotmail.com - SPAM FIX
ส ส $cont = Q(rcube_imap::decode_mime_string($header->subject, $header->charset));
ส ส ส ส
ส ส // Check to see if this subject contains our spam line and is not in the
ส ส // designated junk mailbox
ส ส ส ส ส
ส ส if ( ( $mbox!=$CONFIG['trash_mbox'] ) && ( $mbox!=$CONFIG['junk_mbox'] ) ){
ส ส ส if ( preg_match($CONFIG['spam_subject'], $cont) ){
ส ส ส ส $n_of_spam += 1;
ส ส ส ส // Move the message from this mailbox to the junk mail box
ส ส ส ส $IMAP->move_message( array($header->uid), $CONFIG['junk_mbox'], $mbox );
ส ส ส ส continue;
ส ส ส }
ส ส }
// END MODIFICATION BY midnightz@hotmail.com - SPAM FIX


You need to remove those chars.
May be couse of 'Copy & Paste'.

Offline evilbunny

  • Jr. Member
  • **
  • Posts: 13
Re: Replacement of Easy SpamAssassin Filtering
« Reply #3 on: February 14, 2008, 01:37:25 AM »
Erm why not just filter spam into a junk folder on the server, then you wouldn't need to take hackish actions to achive the same thing but better.

Offline tman

  • Newbie
  • *
  • Posts: 2
Re: Replacement of Easy SpamAssassin Filtering
« Reply #4 on: February 15, 2008, 01:43:24 AM »
Would you believe those bad chars did not show up in my editor (BBedit). Change back to Dreamweaver and everything is good. Thanks.

Offline lhwparis

  • Newbie
  • *
  • Posts: 3
Re: Replacement of Easy SpamAssassin Filtering
« Reply #5 on: March 06, 2008, 03:29:07 AM »
is this code working with v0.1 ? i have tried this but it not work :( can you say me which row in v0.1 i have to post ? thanks!

Offline midnightz

  • Jr. Member
  • **
  • Posts: 10
Re: Replacement of Easy SpamAssassin Filtering
« Reply #6 on: March 07, 2008, 09:48:45 PM »
This are my raw files on 0.1-stable

program/step/mail/func.in
program/localization/en_US/messages.inc

File 'message.inc' was updated. Who's downloaded, please download a new one.

Sorry.. :)