Class: IMAPProcessor::Learn
- Inherits:
-
Client
- Object
- IMAPProcessor
- Client
- IMAPProcessor::Learn
- Defined in:
- lib/imap_processor/learn.rb
Overview
IMAPLearn flags messages per-folder based on what you’ve flagged before.
aka part three of my Plan for Total Email Domination.
Constant Summary collapse
- LEARN_KEYWORD =
IMAP keyword for learned messages
'IMAPLEARN_FLAGGED'
- TASTY_KEYWORD =
IMAP keyword for tasty messages
LEARN_KEYWORD + '_TASTY'
- BLAND_KEYWORD =
IMAP keyword for bland messages
LEARN_KEYWORD + '_BLAND'
Constants inherited from IMAPProcessor
Instance Attribute Summary
Attributes inherited from IMAPProcessor
Class Method Summary collapse
-
.process_args(args) ⇒ Object
Handles processing of
args
.
Instance Method Summary collapse
-
#initialize(options) ⇒ Learn
constructor
Creates a new IMAPLearn from
options
. -
#run ⇒ Object
Flags tasty messages from all selected mailboxes.
Methods inherited from Client
#connect, #find_mailboxes, #mark, #search
Methods inherited from IMAPProcessor
add_move, #capability, #connect, #create_mailbox, #delete_messages, #each_message, #each_part, #log, #mime_parts, #move_messages, #noop?, run, #show_messages, #verbose?
Constructor Details
#initialize(options) ⇒ Learn
Creates a new IMAPLearn from options
.
Options include:
+:Threshold+:: Tastiness threshold for flagging
and all options from IMAPClient
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/imap_processor/learn.rb', line 63 def initialize() super @db_root = File.join '~', '.imap_learn', "#{[:User]}@#{[:Host]}:#{[:Port]}" @db_root = File. @db_root @threshold = [:Threshold] @classifiers = Hash.new do |h,k| filter_db = File.join @db_root, "#{k}.db" FileUtils.mkdir_p File.dirname(filter_db) h[k] = RBayes.new filter_db end @unlearned_flagged = [] @tasty_unflagged = [] @bland_flagged = [] @tasty_unlearned = [] @bland_unlearned = [] @noop = false end |
Class Method Details
.process_args(args) ⇒ Object
Handles processing of args
.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/imap_processor/learn.rb', line 42 def self.process_args(args) @@options[:Threshold] = [0.85, 'Tastiness threshold not set'] super __FILE__, args, {} do |opts, | opts.on("-t", "--threshold THRESHOLD", "Flag messages more tasty than THRESHOLD", "Default: #{[:Threshold].inspect}", "Options file name: Threshold", Float) do |threshold| [:Threshold] = threshold end end end |
Instance Method Details
#run ⇒ Object
Flags tasty messages from all selected mailboxes.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/imap_processor/learn.rb', line 90 def run log "Flagging tasty messages" = 0 mailboxes = find_mailboxes mailboxes.each do |mailbox| @mailbox = mailbox @imap.select @mailbox log "Selected #{@mailbox}" += process_unlearned_flagged += process_tasty_unflagged += process_bland_flagged += process_unlearned end log "Done. Found #{} messages in #{mailboxes.length} mailboxes" end |