Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. #
  4. # Train dspam by checking if users moved any messages
  5. # between the inbox and the junkbox
  6. #
  7.  
  8. require 'rubygems'
  9. require_gem 'activerecord'
  10.  
  11. JUNKBOX = '.Junk/'
  12. DSPAM = 'dspam'
  13.  
  14. def log(msg)
  15. `logger -t train_dspam -p mail.info #{msg}`
  16. end
  17.  
  18. class User < ActiveRecord::Base
  19. establish_connection :adapter => 'mysql',
  20. :database => 'cura_prod',
  21. :host => 'localhost',
  22. :username => 'cura',
  23. :password => 'yakubrub'
  24. end
  25.  
  26. User.find(:all).each do |user|
  27. # Look at the user's inbox for mail
  28. # incorrectly labeled as spam
  29. log "Processing #{user.email} - inbox"
  30. Dir.glob(user.maildir '{cur,new}/*').each do |file|
  31. `grep 'X-DSPAM-Result: Spam' #{file} 1>/dev/null`
  32. if $?.to_i == 0
  33. # If such a message is found, tell dspam about it and
  34. # change the header so we won't process it again
  35. log "Correcting a false positive"
  36. `#{DSPAM} --user #{user.email} --class=innocent --source=error < #{file}`
  37. `sed 's/X-DSPAM-Result: Spam/X-DSPAM-Result: Innocent/g' #{file} > #{file}_dspam_tmp && mv #{file}_dspam_tmp #{file}`
  38. end
  39. end
  40.  
  41. # Now look at the junk folder
  42. # for mail which failed to be identified as spam
  43. log "Processing #{user.email} - junkbox"
  44. Dir.glob(user.maildir "#{JUNKBOX}/{cur,new}/*").each do |file|
  45. `grep "X-DSPAM-Result: Innocent" #{file} 1>/dev/null`
  46. if $?.to_i == 0
  47. # If such a message is found, tell dspam about it and
  48. # since it is spam we can just delete it
  49. log "Correcting a false negative"
  50. `#{DSPAM} --user #{user.email} --class=spam --source=error < #{file}`
  51. `rm -f #{file}`
  52. end
  53. end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement