Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- #
- # Train dspam by checking if users moved any messages
- # between the inbox and the junkbox
- #
- JUNK_BOX = '.Junk/'
- DSPAM = 'dspam'
- require 'rubygems'
- require_gem 'activerecord'
- `logger -p mail.info Training dspam`
- class User < ActiveRecord::Base
- establish_connection :adapter => 'mysql',
- :database => 'cura_prod',
- :host => 'localhost',
- :username => 'cura',
- :password => 'yakubrub'
- end
- def log(msg)
- `logger -t train_dspam -p mail.info #{msg}`
- end
- User.find(:all).each do |user|
- # Look at the user's inbox for mail
- # incorrectly labeled as spam
- log "Processing #{user.email} - inbox"
- Dir.glob(user.maildir + '{cur,new}/*').each do |file|
- `grep 'X-DSPAM-Result: Spam' #{file} 1>/dev/null`
- if $?.to_i == 0
- # If such a message is found, tell dspam about it and
- # change the header so we won't process it again
- log "Correcting a false positive"
- `#{DSPAM} --user #{user.email} --class=innocent --source=error < #{file}`
- `sed 's/X-DSPAM-Result: Spam/X-DSPAM-Result: Innocent/g' #{file} > #{file}_dspam_tmp && mv #{file}_dspam_tmp #{file}`
- end
- end
- # Now look at the junk folder
- # for mail which failed to be identified as spam
- log "Processing #{user.email} - junkbox"
- Dir.glob(user.maildir + "#{JUNK_BOX}/{cur,new}/*").each do |file|
- `grep "X-DSPAM-Result: Innocent" #{file} 1>/dev/null`
- if $?.to_i == 0
- # If such a message is found, tell dspam about it and
- # since it is spam we can just delete it
- log "Correcting a false negative"
- `#{DSPAM} --user #{user.email} --class=spam --source=error < #{file}`
- `rm -f #{file}`
- end
- end
- end
Add Comment
Please, Sign In to add comment