Roundcube Community Forum

 

Replacement of Easy SpamAssassin Filtering

Started by midnightz, February 09, 2008, 04:52:43 AM

Previous topic - Next topic

midnightz

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 [email protected] - SPAM FIX
 $n_of_spam = 0;
// END MODIFICATION BY [email protected] - SPAM FIX

     
 // create row for each message
 foreach ($a_headers as $i => $header) //while (list($i, $header) = each($a_headers))
  {  
   
// START MODIFICATION BY [email protected] - 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 [email protected] - SPAM FIX


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

// START MODIFICATION BY [email protected] - 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 [email protected] - 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 [email protected] - SPAM FIX
 $n_of_spam = 0;
// END MODIFICATION BY [email protected] - 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 [email protected] - 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 [email protected] - 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 [email protected] - 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 [email protected] - SPAM FIX


}

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


tman

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.

midnightz

I have found special char in your pasted code.

 // START MODIFICATION BY [email protected] - 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 [email protected] - SPAM FIX


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

evilbunny

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.

tman

Would you believe those bad chars did not show up in my editor (BBedit). Change back to Dreamweaver and everything is good. Thanks.

lhwparis

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!

midnightz

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.. :)