class IMAPProcessor::Tidy
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.
Attributes
move[RW]
Whether to move the mail or just display. default:false
Public Instance Methods
run()
click to toggle source
# File lib/imap_processor/tidy.rb, line 76 def run @boxes.each do |mailbox, days_old| select mailbox before_date = Time.now - 86_400 * (options[: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] show_messages uids move_messages uids, destination, false if move end log "EXPUNGE" imap.expunge if move unless noop? end end
search(args)
click to toggle source
Search a selected mailbox with args
TODO: push up
# File lib/imap_processor/tidy.rb, line 65 def search args log "SEARCH #{args.join " "}" imap.search args end
select(mailbox)
click to toggle source
Select a mailbox TODO: push up
# File lib/imap_processor/tidy.rb, line 56 def select mailbox log "SELECT #{mailbox}" imap.select mailbox end
uids_to_dates(uids)
click to toggle source
# File lib/imap_processor/tidy.rb, line 70 def uids_to_dates uids imap .fetch(uids, "INTERNALDATE") .to_h { |fd| [fd.seqno, Time.imapdate(fd.attr["INTERNALDATE"]).yyyy_mm] } end