Class: ImapTickler::Tickler
- Inherits:
-
Object
- Object
- ImapTickler::Tickler
- Defined in:
- lib/imap_tickler/tickler.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(config) ⇒ Tickler
constructor
A new instance of Tickler.
- #start ⇒ Object
- #this_months_mailbox ⇒ Object
- #tickle_mailbox(mailbox) ⇒ Object
- #todays_mailbox ⇒ Object
Constructor Details
#initialize(config) ⇒ Tickler
Returns a new instance of Tickler.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/imap_tickler/tickler.rb', line 6 def initialize(config) @day_list = ["Week 1/1", "Week 1/2", "Week 1/3", "Week 1/4", "Week 1/5", "Week 1/6", "Week 1/7", "Week 2/8", "Week 2/9", "Week 2/10", "Week 2/11", "Week 2/12", "Week 2/13", "Week 2/14", "Week 3/15", "Week 3/16", "Week 3/17", "Week 3/18", "Week 3/19", "Week 3/20", "Week 3/21", "Week 4/22", "Week 4/23", "Week 4/24", "Week 4/25", "Week 4/26", "Week 4/27", "Week 4/28", "Week 5/29", "Week 5/30", "Week 5/31"] @month_list = ["Month/01 Jan", "Month/02 Feb", "Month/03 Mar", "Month/04 Apr", "Month/05 May", "Month/06 Jun", "Month/07 Jul", "Month/08 Aug", "Month/09 Sep", "Month/10 Oct", "Month/11 Nov", "Month/12 Dec"] @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/imap_tickler/tickler.rb', line 5 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/imap_tickler/tickler.rb', line 5 def connection @connection end |
Instance Method Details
#connect ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/imap_tickler/tickler.rb', line 18 def connect @connection = Net::IMAP.new(config[:mailserver], 993, true) if config[:use_ssl] @connection ||= Net::IMAP.new(config[:mailserver]) if @connection @connection.login(config[:username],config[:password]) end end |
#start ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/imap_tickler/tickler.rb', line 43 def start connect [todays_mailbox, this_months_mailbox].each do |mailbox| tickle_mailbox(mailbox) end return 0 end |
#this_months_mailbox ⇒ Object
26 27 28 |
# File 'lib/imap_tickler/tickler.rb', line 26 def this_months_mailbox @month_list[Date.today.month - 1] end |
#tickle_mailbox(mailbox) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/imap_tickler/tickler.rb', line 34 def tickle_mailbox mailbox connection.select("@Tickler/#{mailbox}") = connection.responses["EXISTS"][-1] if > 0 connection.copy(1..,"INBOX") connection.store(1..,"+FLAGS", [:Deleted]) end end |
#todays_mailbox ⇒ Object
30 31 32 |
# File 'lib/imap_tickler/tickler.rb', line 30 def todays_mailbox @day_list[Date.today.day - 1] end |