Hi I know i might get flamed for asking this in the dovecot mailing list instead of the spamassassin one but i thought someone might be kind enough to help anyway. TIA I'm trying to do site-wide spam filtering with a public namespace but it's not reading the folder i have in the public namespace This is the public namespace set in my dovecot.conf #public spam folder namespace public { separator = / prefix = Filter/ location = maildir:/home/vmail/domains/Spam/Maildir/ hidden = no } There's also a .Spam and .Non-spam folder created in that directory server:/home/vmail/domains/Spam/Maildir# ls -al total 32 drwxrwxrwx 7 vmail vmail 4096 2007-10-09 10:35 . drwxrwxrwx 3 vmail vmail 4096 2007-10-05 13:23 .. drwx------ 2 vmail vmail 4096 2007-10-09 10:35 cur drwx------ 2 vmail vmail 4096 2007-10-09 10:35 new drwxrwxrwx 5 vmail vmail 4096 2007-10-09 11:20 .Non-Spam drwxrwxrwx 5 vmail vmail 4096 2007-10-09 11:19 .Spam -rw------- 1 vmail vmail 14 2007-10-08 11:58 subscriptions drwx------ 2 vmail vmail 4096 2007-10-09 10:35 tmp I'm trying to use this script to login and get the spam from the public spam folders and send it to spamassassin to learn I've highlighted the important parts There are 13 messages in Spam There are 5 messages in Non-Spam Here's the script: ######################################################################################### #!/usr/bin/perl # # Process mail from imap server shared folder 'spam' & 'not-spam' through spamassassin sa-learn # dmz at dmzs.com - March 19, 2004 # http://www.dmzs.com/tools/files/spam.phtml # LGPL # # Things to try if it doesn't work # 1) Turn debug onto 1 and see if you connect to imap server ad get messages (yes i could have made a command line flag, just didn't see the need once I got it working :) # 2) Check your local.cf for spamassassin (in debian it's /etc/spamassassin/local.cf) bayes_path settings. # # Also be sure to check that your spamassassin is truely using the bayes files (-D manual startup of spamd to debug there) # use Mail::IMAPClient; use IO::Socket::SSL; my $debug=1; my $salearn; my $username = 'user'; my $password = 'password'; my $server = 'server.example.com'; my $ssl=new IO::Socket::SSL("$server:imaps"); die ("Error connecting - $@") unless defined $ssl; $ssl->autoflush(1); my $imap = Mail::IMAPClient->new( #Server=> 'imapmailhost:143', Socket => $ssl, User => $username, Password => $password, Debug => $debug ); if (!defined($imap)) { die "IMAP Login Failed"; } # If debugging, print out the total counts for each mailbox if ($debug) { foreach my $foldername ($imap->folders) { my $number_of_messages $imap->message_count( $foldername ); print $foldername, " is imap folder\n"; }* my $spamcount = $imap->message_count('Filter/Spam');* print $spamcount, " Spam to process\n"; * my $nonspamcount = $imap->message_count('Filter/Non-Spam');* print $nonspamcount, " Notspam to process\n" if $debug; } # Process the spam mailbox *$imap->select('Filter/Spam');* my @msgs = $imap->search("ALL"); for (my $i=0;$i <= $#msgs; $i++) { # I put it into a file for processing, doing it into a perl var & piping through sa-learn just didn't seem to work $imap->message_to_file("/tmp/salearn",$msgs[$i]); # execute sa-learn w/data # if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync --showdots --spam /tmp/salearn`; } # else { $salearn = `/usr/bin/sa-learn --no-sync --showdots --spam /tmp/salearn`; } print "-------\nSpam: ",$salearn,"\n-------\n" if $debug; # delete processed message $imap->delete_message($msgs[$i]); unlink("/tmp/salearn"); } $imap->expunge(); $imap->close(); # Process the not-spam mailbox *$imap->select('Filter/Non-spam');* my @msgs = $imap->search("ALL"); for (my $i=0;$i <= $#msgs; $i++) { $imap->message_to_file("/tmp/salearn",$msgs[$i]); # execute sa-learn w/data # if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync --showdots --ham /tmp/salearn`; } # else { $salearn = `/usr/bin/sa-learn --no-sync --showdots --ham /tmp/salearn`; } print "-------\nNotSpam: ",$salearn,"\n-------\n" if $debug; # delete processed message $imap->delete_message($msgs[$i]); unlink("/tmp/salearn"); } $imap->expunge(); $imap->close(); $imap->logout(); # integrate learned stuff my $sarebuild = `/usr/bin/sa-learn --sync`; print "-------\nRebuild: ",$sarebuild,"\n-------\n" if $debug; ######################################################################################### Results: server:/home/james# ./DMZS-sa-learn.pl Using Mail::IMAPClient version 2.2.9 and perl version 5.8.8 (5.008008) Spam to process Notspam to process . ------- Spam: Learned tokens from 0 message(s) (1 message(s) examined) ------- Autoloading: UID store +FLAGS.SILENT (\Deleted) . ------- NotSpam: Learned tokens from 1 message(s) (1 message(s) examined) ------- Autoloading: UID store +FLAGS.SILENT (\Deleted) ------- Rebuild: bayes: synced databases from journal in 0 seconds: 4 unique entries (4 total entries) -------
James wrote:> Hi I know i might get flamed for asking this in the dovecot mailing > list instead of the spamassassin one but i thought someone might be > kind enough to help anyway. > > TIA > > I'm trying to do site-wide spam filtering with a public namespace but > it's not reading the folder i have in the public namespace > > This is the public namespace set in my dovecot.conf > > #public spam folder > namespace public { > separator = / > prefix = Filter/ > location = maildir:/home/vmail/domains/Spam/Maildir/ > hidden = no > } > > There's also a .Spam and .Non-spam folder created in that directory > > server:/home/vmail/domains/Spam/Maildir# ls -al > total 32 > drwxrwxrwx 7 vmail vmail 4096 2007-10-09 10:35 . > drwxrwxrwx 3 vmail vmail 4096 2007-10-05 13:23 .. > drwx------ 2 vmail vmail 4096 2007-10-09 10:35 cur > drwx------ 2 vmail vmail 4096 2007-10-09 10:35 new > drwxrwxrwx 5 vmail vmail 4096 2007-10-09 11:20 .Non-Spam > drwxrwxrwx 5 vmail vmail 4096 2007-10-09 11:19 .Spam > -rw------- 1 vmail vmail 14 2007-10-08 11:58 subscriptions > drwx------ 2 vmail vmail 4096 2007-10-09 10:35 tmp > > > I'm trying to use this script to login and get the spam from the > public spam folders and send it to spamassassin to learn > I've highlighted the important parts > There are 13 messages in Spam > There are 5 messages in Non-Spam > > Here's the script: > > ######################################################################################### > > > #!/usr/bin/perl > # > # Process mail from imap server shared folder 'spam' & 'not-spam' > through spamassassin sa-learn > # dmz at dmzs.com - March 19, 2004 > # http://www.dmzs.com/tools/files/spam.phtml > # LGPL > # > # Things to try if it doesn't work > # 1) Turn debug onto 1 and see if you connect to imap server ad get > messages (yes i could have made a command line flag, just didn't see > the need once I got it working :) > # 2) Check your local.cf for spamassassin (in debian it's > /etc/spamassassin/local.cf) bayes_path settings. > # > # Also be sure to check that your spamassassin is truely using the > bayes files (-D manual startup of spamd to debug there) > # > > use Mail::IMAPClient; > use IO::Socket::SSL; > > my $debug=1; > my $salearn; > my $username = 'user'; > my $password = 'password'; > my $server = 'server.example.com'; > > my $ssl=new IO::Socket::SSL("$server:imaps"); > die ("Error connecting - $@") unless defined $ssl; > $ssl->autoflush(1); > > my $imap = Mail::IMAPClient->new( > #Server=> 'imapmailhost:143', > Socket => $ssl, > User => $username, > Password => $password, > Debug => $debug > ); > > if (!defined($imap)) { die "IMAP Login Failed"; } > > # If debugging, print out the total counts for each mailbox > if ($debug) { > > foreach my $foldername ($imap->folders) { > my $number_of_messages > $imap->message_count( $foldername ); > print $foldername, " is imap folder\n"; > }* > my $spamcount = $imap->message_count('Filter/Spam');* > print $spamcount, " Spam to process\n"; > > * my $nonspamcount = $imap->message_count('Filter/Non-Spam');* > print $nonspamcount, " Notspam to process\n" if $debug; > } > > # Process the spam mailbox > *$imap->select('Filter/Spam');* > my @msgs = $imap->search("ALL"); > for (my $i=0;$i <= $#msgs; $i++) > { > # I put it into a file for processing, doing it into a perl var & > piping through sa-learn just didn't seem to work > $imap->message_to_file("/tmp/salearn",$msgs[$i]); > > # execute sa-learn w/data > # if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync --showdots > --spam /tmp/salearn`; } > # else > { $salearn = `/usr/bin/sa-learn --no-sync --showdots --spam > /tmp/salearn`; } > print "-------\nSpam: ",$salearn,"\n-------\n" if $debug; > > # delete processed message > $imap->delete_message($msgs[$i]); > unlink("/tmp/salearn"); > } > $imap->expunge(); > $imap->close(); > > # Process the not-spam mailbox > *$imap->select('Filter/Non-spam');* > my @msgs = $imap->search("ALL"); > for (my $i=0;$i <= $#msgs; $i++) > { > $imap->message_to_file("/tmp/salearn",$msgs[$i]); > # execute sa-learn w/data > # if ($debug) { $salearn = `/usr/bin/sa-learn -D --no-sync --showdots > --ham /tmp/salearn`; } > # else > { $salearn = `/usr/bin/sa-learn --no-sync --showdots --ham > /tmp/salearn`; } > print "-------\nNotSpam: ",$salearn,"\n-------\n" if $debug; > > # delete processed message > $imap->delete_message($msgs[$i]); > unlink("/tmp/salearn"); > } > $imap->expunge(); > $imap->close(); > > $imap->logout(); > > # integrate learned stuff > my $sarebuild = `/usr/bin/sa-learn --sync`; > print "-------\nRebuild: ",$sarebuild,"\n-------\n" if $debug; > > ######################################################################################### > > > > Results: > server:/home/james# ./DMZS-sa-learn.pl > Using Mail::IMAPClient version 2.2.9 and perl version 5.8.8 (5.008008) > Spam to process > Notspam to process > . > ------- > Spam: Learned tokens from 0 message(s) (1 message(s) examined) > > ------- > Autoloading: UID store +FLAGS.SILENT (\Deleted) > . > ------- > NotSpam: Learned tokens from 1 message(s) (1 message(s) examined) > > ------- > Autoloading: UID store +FLAGS.SILENT (\Deleted) > ------- > Rebuild: bayes: synced databases from journal in 0 seconds: 4 unique > entries (4 total entries) > > ------- > > > >nevermind i got it working