Class: IMAPProcessor::Tidy
- Inherits:
-
IMAPProcessor
- Object
- IMAPProcessor
- IMAPProcessor::Tidy
- Defined in:
- lib/imap_processor/tidy.rb
Overview
Whereas Archive moves all mail before this month into a dated mailbox, and whereas Cleanse deletes all read unflagged mail over N days old, Tidy moves all read unflagged mail into a dated mailbox.
It’s somewhere in-between Archive and Cleanse in that it is used for mail you want to keep, but also keep out of the way of your active inbox.
Constant Summary
Constants inherited from IMAPProcessor
Instance Attribute Summary collapse
-
#move ⇒ Object
Whether to move the mail or just display.
Attributes inherited from IMAPProcessor
Class Method Summary collapse
-
.process_args(args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(options) ⇒ Tidy
constructor
:nodoc:.
- #run ⇒ Object
-
#search(args) ⇒ Object
Search a selected mailbox with
args
TODO: push up. -
#select(mailbox) ⇒ Object
Select a mailbox TODO: push up.
- #uids_to_dates(uids) ⇒ Object
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) ⇒ Tidy
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/imap_processor/tidy.rb', line 40 def initialize # :nodoc: super log "Tidy: #{[:Host]}" self.move = [:move] connection = connect @imap = connection.imap end |
Instance Attribute Details
#move ⇒ Object
Whether to move the mail or just display. default:false
18 19 20 |
# File 'lib/imap_processor/tidy.rb', line 18 def move @move end |
Class Method Details
.process_args(args) ⇒ Object
:nodoc:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/imap_processor/tidy.rb', line 20 def self.process_args args # :nodoc: = { :move => false, } super __FILE__, args, do |opts, | opts. << <<~EOF imap_tidy moves older messages from your mailboxen into dated mailboxen. EOF opts.on "--days=N", Integer, "Override age to move messages" do |n| [:age] = n end opts.on "--[no-]move", "Move the messages (off by default)" do |move| [:move] = move end end end |
Instance Method Details
#run ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/imap_processor/tidy.rb', line 76 def run @boxes.each do |mailbox, days_old| select mailbox before_date = Time.now - 86_400 * ([:age] || days_old) uids = search %W[SEEN UNFLAGGED BEFORE #{before_date.imapdate}] next if uids.empty? log "FOUND %p" % [uids] uids_to_dates(uids) # id => "YYYY-MM" .multi_invert # "YYYY-MM" => [id,...] .sort .each do |date, uids| destination = "%s-%s" % [mailbox, date] uids uids, destination, false if move end log "EXPUNGE" imap.expunge if move unless noop? end end |
#search(args) ⇒ Object
Search a selected mailbox with args
TODO: push up
65 66 67 68 |
# File 'lib/imap_processor/tidy.rb', line 65 def search args log "SEARCH #{args.join " "}" imap.search args end |
#select(mailbox) ⇒ Object
Select a mailbox TODO: push up
56 57 58 59 |
# File 'lib/imap_processor/tidy.rb', line 56 def select mailbox log "SELECT #{mailbox}" imap.select mailbox end |