class IMAPProcessor::Learn

IMAPLearn flags messages per-folder based on what you’ve flagged before.

aka part three of my Plan for Total Email Domination.

Constants

BLAND_KEYWORD

IMAP keyword for bland messages

LEARN_KEYWORD

IMAP keyword for learned messages

TASTY_KEYWORD

IMAP keyword for tasty messages

Public Class Methods

new(options) click to toggle source

Creates a new IMAPLearn from options.

Options include:

+:Threshold+:: Tastiness threshold for flagging

and all options from IMAPClient

Calls superclass method IMAPProcessor::Client::new
# File lib/imap_processor/learn.rb, line 63
def initialize(options)
  super

  @db_root = File.join '~', '.imap_learn',
                    "#{options[:User]}@#{options[:Host]}:#{options[:Port]}"
  @db_root = File.expand_path @db_root

  @threshold = options[: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
process_args(args) click to toggle source

Handles processing of args.

Calls superclass method IMAPProcessor::process_args
# 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, options|
    opts.on("-t", "--threshold THRESHOLD",
            "Flag messages more tasty than THRESHOLD",
            "Default: #{options[:Threshold].inspect}",
            "Options file name: Threshold", Float) do |threshold|
      options[:Threshold] = threshold
    end
  end
end

Public Instance Methods

run() click to toggle source

Flags tasty messages from all selected mailboxes.

# File lib/imap_processor/learn.rb, line 90
def run
  log "Flagging tasty messages"

  message_count = 0
  mailboxes = find_mailboxes

  mailboxes.each do |mailbox|
    @mailbox = mailbox
    @imap.select @mailbox
    log "Selected #{@mailbox}"

    message_count += process_unlearned_flagged
    message_count += process_tasty_unflagged
    message_count += process_bland_flagged
    message_count += process_unlearned
  end

  log "Done. Found #{message_count} messages in #{mailboxes.length} mailboxes"
end