IMAP and Outlook Spam training: Difference between revisions
mNo edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{Unsupported}} | {{Unsupported}} | ||
As of 5.0.11 (or 5.0.12? please update this if you know...), Junk/Spam folders are zimbra-aware according to http://bugzilla.zimbra.com/show_bug.cgi?id=9532: | As of 5.0.11 (or 5.0.12? please update this if you know...), Junk/Spam folders are zimbra-aware according to http://bugzilla.zimbra.com/show_bug.cgi?id=9532: | ||
Revision as of 19:51, 1 June 2009
As of 5.0.11 (or 5.0.12? please update this if you know...), Junk/Spam folders are zimbra-aware according to http://bugzilla.zimbra.com/show_bug.cgi?id=9532:
When a user in imap/outlook either A) moves an email into this folder or B) clicks the "Junk" button when viewing the email, the extra step was not being performed, and the message, while it was moved to the Junk/Spam folder, was NOT queued for processing by the spam filter/trainer. All that has changed, is that this extra step is automatically, in the background, performed.
The following was once true for Zimbra version before 5.0.11:
IMAP/Outlook move to junk doesn't train anti-spam - It seems that when you move a mail to junk folder on IMAP client (like Thunderbird) anti-spam filter on MTA does not use that mail as a spam example for training... See http://bugzilla.zimbra.com/show_bug.cgi?id=9532
Here is a bash script created from the comments against this bug. I have tested it on our system and it appears to work OK. Feel free to contribute and enhance! Full credit for this script is due to bobby@zimbra.com and dmangot@terracottatech.com who wrote the bits which I just pasted together!
#!/bin/bash wikiuser=`zmprov getConfig zimbraNotebookAccount | cut -d ' ' -f 2`; hamuser=`zmprov getConfig zimbraSpamIsNotSpamAccount | cut -d ' ' -f 2`; spamuser=`zmprov getConfig zimbraSpamIsSpamAccount | cut -d ' ' -f 2`; users=`zmprov getAllAccounts | grep -v -e $wikiuser -e $hamuser -e $spamuser`; for zuser in $users do echo "Train spam for $zuser" /opt/zimbra/bin/zmtrainsa $zuser spam junk done echo "Zimbra spam training complete"
To install, save the above script as 'learnmorespam.sh', copy to /opt/zimbra/learnmorespam.sh on your Zimbra server. Set ownership and make executable:
[root@mail ~]# chmod +x /opt/zimbra/learnmorespam.sh [root@mail ~]# chown zimbra:zimbra /opt/zimbra/learnmorespam.sh
And then create this crontab entry, /etc/crontab
#Learn more spam 6am daily 0 6 * * * zimbra /opt/zimbra/learnmorespam.sh > /dev/null 2>&1
That should be it :)
Another:
#!/usr/bin/perl use strict; use warnings; use Mail::IMAPClient; my $host="<edit>"; my $username="<edit>"; my $password="<edit>"; my @real_users=`/opt/scalix/bin/omshowu -m all -i`; # get all real user names. foreach my $punter (@real_users) # Loop over them all. { chomp $punter; # Remove trailing carriage return. if ("$punter" ne "postmaster") { print "$punter\n"; # Some output. Feel free to remove. #$punter =~s/@/\\@/; my $user="mboxadmin:$username:$punter"; # Set up superuser login. my $imap = new Mail::IMAPClient( 'Server' => $host , 'User' => $user , 'Password' => $password ) or next; # connect to server. my @folders=$imap->folders; # list folders. foreach my $i ( @folders ) { print $i; } foreach my $folder (@folders) # Look through each of them. { print lc($folder),"\n"; if (lc($folder) eq "junk e-mail") # "junk email" folder. { print "Found a spam folder: $folder\n"; $imap->select($folder) or next; # Select the folder. print "Folder $folder selected.\n"; my @list=$imap->messages or next; # List all messages in folder. print scalar(@list)." messages in folder.\n"; foreach my $msg (reverse(@list)) # Loop over them all. { my @email=$imap->fetch($msg,'RFC822'); # Fetch message. open (SALEARN,"|/usr/bin/spamassassin -d | /usr/bin/sa-learn --spam") or print "$!\n"; # Feed to sa-learn. print SALEARN "$email[1]"; close SALEARN; open (REPORT,"|/usr/bin/spamassassin -d | /usr/bin/spamassassin -r") or print "$!\n"; # Report it. (SpamCop and Pyzor). print REPORT "$email[1]"; close REPORT; $imap->delete_message($msg) or next; # Delete it. } $imap->expunge($folder) or next; #Expunge folder. } elsif(lc($folder) eq "not spam") { $imap->select($folder) or next; # Select the folder. print "Folder $folder selected.\n"; my @list=$imap->messages or next; # List all messages in folder. print scalar(@list)." messages in folder.\n"; foreach my $msg (reverse(@list)) # Loop over them all. { my @email=$imap->fetch($msg,'RFC822'); # Fetch message. open (SALEARN,"|/usr/bin/spamassassin -d | /usr/bin/sa-learn --forget") or print "$!\n";# Sa-learn forget this message if already seen. print SALEARN "$email[1]"; close SALEARN or print "$!\n"; open (SALEARN,"|/usr/bin/spamassassin -d | /usr/bin/sa-learn --ham") or next; # Feed to sa-learn as ham. print SALEARN "$email[1]"; close SALEARN; $imap->delete_message($msg) or next; } $imap->expunge($folder) or next; } } } }