Class: Swallow::Admin
- Inherits:
-
Object
- Object
- Swallow::Admin
- Defined in:
- lib/swallow.rb
Instance Method Summary collapse
- #age ⇒ Object
- #age_to_folder(src, dst, limit) ⇒ Object
-
#initialize(config_file = nil) ⇒ Admin
constructor
A new instance of Admin.
- #process_folder(folder_name, is_spam) ⇒ Object
- #process_inbox ⇒ Object
- #process_innocent ⇒ Object
- #process_junk ⇒ Object
Constructor Details
#initialize(config_file = nil) ⇒ Admin
Returns a new instance of Admin.
10 11 12 13 14 15 16 17 18 |
# File 'lib/swallow.rb', line 10 def initialize(config_file = nil) if config_file != nil then @config_path = config_file else @config_path = "#{ENV['HOME']}/.swallow-config" end @config = YAML.load_file(@config_path) @dspam = DSpamEngine.new(:path => @config[:dspam_path]) end |
Instance Method Details
#age ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/swallow.rb', line 55 def age puts "Aging folders..." trash = MailDirFolder.new(@config[:maildir] + @config[:trash]) ruleset = RuleSet.new(@config[:files] + @config[:ruleset]) ruleset.rules.each do |rule| if rule[:folder] != nil and rule[:day_limit] != nil then puts "Folder #{rule[:folder]} has a limit of #{rule[:day_limit]}" src = MailDirFolder.new(@config[:maildir] + "." + rule[:folder]) emails = src.emails_older_than(rule[:day_limit]) puts "Moved #{emails.length} emails" trash.add(emails) end end end |
#age_to_folder(src, dst, limit) ⇒ Object
51 52 53 |
# File 'lib/swallow.rb', line 51 def age_to_folder(src, dst, limit) dst.add(src.emails_older_than(limit)) end |
#process_folder(folder_name, is_spam) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/swallow.rb', line 42 def process_folder(folder_name, is_spam) folder = MailDirFolder.new(@config[:maildir] + folder_name) if is_spam == true then @dspam.train_and_clean_folder(folder) else @dspam.train_emails_as_innocent(folder.emails) end end |
#process_inbox ⇒ Object
28 29 30 31 32 33 |
# File 'lib/swallow.rb', line 28 def process_inbox inbox = MailDirFolder.new(@config[:maildir] + @config[:inbox]) # Feed new messages under the limit in the inbox to the filter as innocent corpus @dspam.train_emails_as_innocent(inbox.emails_newer_than(@config[:limit])) end |
#process_innocent ⇒ Object
35 36 37 38 39 40 |
# File 'lib/swallow.rb', line 35 def process_innocent innocent = MailDirFolder.new(@config[:maildir] + @config[:innocent]) inbox = MailDirFolder.new(@config[:maildir] + @config[:inbox]) @dspam.train_emails_as_innocent(innocent.emails) inbox.add(innocent.emails) end |
#process_junk ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/swallow.rb', line 20 def process_junk # Create Folder Objects junk = MailDirFolder.new(@config[:maildir] + @config[:junk]) # Clean out the Junk Folder @dspam.train_and_clean_folder(junk) end |