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.



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 = - 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,...]
      .each do |date, uids|
        destination = "%s-%s" % [mailbox, date]
        show_messages uids
        move_messages uids, destination, false if move

    log "EXPUNGE"
    imap.expunge if move unless noop?
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}" mailbox
uids_to_dates(uids) click to toggle source
# File lib/imap_processor/tidy.rb, line 70
def uids_to_dates uids
    .fetch(uids, "INTERNALDATE")
    .to_h { |fd| [fd.seqno, Time.imapdate(fd.attr["INTERNALDATE"]).yyyy_mm] }