Class: IMAPProcessor::Archive
- Inherits:
-
IMAPProcessor
- Object
- IMAPProcessor
- IMAPProcessor::Archive
- Defined in:
- lib/imap_processor/archive.rb
Overview
Archives old mail on IMAP server by moving it to dated mailboxen.
Constant Summary
Constants inherited from IMAPProcessor
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#move ⇒ Object
readonly
Returns the value of attribute move.
Attributes inherited from IMAPProcessor
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Archive
constructor
A new instance of Archive.
- #last_month ⇒ Object
-
#make_search ⇒ Object
Makes a SEARCH argument set from
keywords
. - #run ⇒ Object
- #the_first ⇒ Object
Methods inherited from IMAPProcessor
add_move, #connect, #create_mailbox, #delete_messages, #each_message, #each_part, #log, #mime_parts, #move_messages, run, #show_messages, #verbose?
Constructor Details
#initialize(options) ⇒ Archive
Returns a new instance of Archive.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/imap_processor/archive.rb', line 30 def initialize() super @list = [:List] @move = [:Move] connection = connect @imap = connection.imap end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
7 8 9 |
# File 'lib/imap_processor/archive.rb', line 7 def list @list end |
#move ⇒ Object (readonly)
Returns the value of attribute move.
7 8 9 |
# File 'lib/imap_processor/archive.rb', line 7 def move @move end |
Class Method Details
.process_args(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imap_processor/archive.rb', line 9 def self.process_args(args) = { :List => true, :Move => false, } super __FILE__, args, do |opts, | opts. << <<-EOF imap_archive archives old mail on IMAP server by moving it to dated mailboxen. EOF opts.on("--[no-]list", "Display messages (on by default)") do |list| [:List] = list end opts.on("--[no-]move", "Move the messages (off by default)") do |move| [:Move] = move end end end |
Instance Method Details
#last_month ⇒ Object
46 47 48 49 |
# File 'lib/imap_processor/archive.rb', line 46 def last_month t = the_first - 1 Time.local(t.year, t.month, 1).strftime("%Y-%m") end |
#make_search ⇒ Object
Makes a SEARCH argument set from keywords
54 55 56 |
# File 'lib/imap_processor/archive.rb', line 54 def make_search %W[SENTBEFORE #{the_first.imapdate}] end |
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/imap_processor/archive.rb', line 58 def run @boxes.each do |mailbox| destination = "#{mailbox}.#{last_month}" log "SELECT #{mailbox}" response = imap.select mailbox search = make_search log "SEARCH #{search.join ' '}" uids = imap.search search next if uids.empty? puts "#{uids.length} messages in #{mailbox}#{list ? ':' : ''}" uids uids, destination if move end end |