On Dec 26, 2003, at 5:26, Jon Clausen wrote:
Now, since setting up {spam|ham|forget}@domain seems to require too much of the users (in that they would be required to edit the headers, before forwarding to those accounts) I think the {spam|ham|forget}-mailbox+cronjob-sa-learn is probably the better solution. Because this would only require the users to move the message(s) to said mailbox(es).
This, however, begs the next (couple of) question(s);
- I want the users to access mail through imap.
- Setting up 'shared' {spam|ham|forget}-folders should be No Big Deal, right?
This is how I set up my mail server. The only problem when you have multiple users is that one person's spam is another person's ham. In my case I am the only user so this works fine.
- In order for the sa-learn script to not have to keep processing the same messages, content will have to be removed from said folder after each run. So is it neccessary to run something like 'reconstruct' to keep Cyrus happy?
What I did was to create a new Cyrus account which has only permissions to access the shared "ham" and "spam" folders. A cron job runs a script which calls a python program that logs into the server using that account and reads the emails, processes them and then removes them. Here is the script. It can probably be improved, but it works for me. Be aware though that I am using spamassasin and amavisd-new on a Mandrake 9.1 system so it may work a bit differently under SuSE (such as file locations). First is the small shell script that calls the python script: ------------- BEGIN process_spam_and_ham ------------ #!/bin/bash /usr/local/bin/process_spam_and_ham.py spam /usr/local/bin/process_spam_and_ham.py ham ------------- END process_spam_and_ham ------------ And this is the python script: ------------- BEGIN process_spam_and_ham.py ------------ #!/usr/bin/python import imaplib, string, popen2, os, sys if len(sys.argv) <> 2 or (sys.argv[1] != 'spam' and sys.argv[1] != 'ham'): print >>os.sys.stderr, 'Usage: ' + sys.argv[0] + ' {spam|ham}' sys.exit(1) type = sys.argv[1] print 'Type: ' + type # Connect to the mail server m = imaplib.IMAP4("mail-server") m.login("username", "password") # Select the inbox m.select(type) #Get a list of messages in the mailbox status, messages = m.search(None, "ALL") # Write each message to a file using the message number for num in messages[0].split(): print 'writing message ' + num # Fetch the email status, data = m.fetch(num, "(RFC822)") # and write it into a file f=open('/var/spool/amavis/bayesian/' + num, 'w') f.write(data[0][1]) f.close() # delete the email m.store(num, 'FLAGS', r'(\Deleted)') m.close() m.logout() # Execute the Bayesian tutor os.system('/usr/bin/sa-learn --' + type + ' -p /var/lib/amavis/.spamassassin/user_prefs --dir /var/spool/amavis/bayesian/') # For each spam message invoke razor-report and then delete the message (spam and ham) for num in messages[0].split(): if os.path.exists('/var/spool/amavis/bayesian/' + num): if type == 'spam': print 'Razoring ' + num os.system('/usr/bin/razor-report -f /var/spool/amavis/bayesian/' + n um) os.unlink('/var/spool/amavis/bayesian/' + num) else: print 'Something happened to /var/spool/amavis/bayesian/' + num + '. It is missing' ------------- END process_spam_and_ham.py ------------ I hope this helps someone. Avi