Class: PollterGeist::IMAPCommands
- Inherits:
-
Object
- Object
- PollterGeist::IMAPCommands
- Defined in:
- lib/pollter_geist/imap_commands.rb
Instance Method Summary collapse
- #expunge ⇒ Object
- #fetch(uids) ⇒ Object
- #imap ⇒ Object
-
#initialize(imap, logger) ⇒ IMAPCommands
constructor
A new instance of IMAPCommands.
- #logger ⇒ Object
-
#message_uids ⇒ Array
fetches a list of message UIDs.
- #remove(uid) ⇒ Object
- #select_mailbox(mailbox) ⇒ Object
-
#wait_for(events, timeout = 29*60) ⇒ Object
Issues IDLE command for the imap server, it takes a list of events to listen for and returns once one of events occured or if there was a timeout.
- #wait_for_changes(timeout = 20*60) ⇒ Object
Constructor Details
#initialize(imap, logger) ⇒ IMAPCommands
Returns a new instance of IMAPCommands.
3 4 5 6 7 8 |
# File 'lib/pollter_geist/imap_commands.rb', line 3 def initialize imap, logger @imap = imap @logger = logger @idler = ImapIdler.new(self) end |
Instance Method Details
#expunge ⇒ Object
41 42 43 44 |
# File 'lib/pollter_geist/imap_commands.rb', line 41 def expunge @logger.debug("expunge, remove all messages with Delete flag") @imap.expunge end |
#fetch(uids) ⇒ Object
46 47 48 49 |
# File 'lib/pollter_geist/imap_commands.rb', line 46 def fetch uids logger.debug "fetching: #{uids}" @imap.uid_fetch(uids, ['RFC822']).map { |r| r.attr['RFC822'] } end |
#imap ⇒ Object
70 71 72 |
# File 'lib/pollter_geist/imap_commands.rb', line 70 def imap @imap end |
#logger ⇒ Object
66 67 68 |
# File 'lib/pollter_geist/imap_commands.rb', line 66 def logger @logger end |
#message_uids ⇒ Array
fetches a list of message UIDs
27 28 29 30 31 32 33 34 |
# File 'lib/pollter_geist/imap_commands.rb', line 27 def @logger.debug('fetching uids') # Searching for all messages where TO include @ is a workaround, since the imap#status method # does not work for some reason. = @imap.search(['TO', '@']) result = @imap.fetch(, ['UID']) result.map { |r| r.attr['UID'].to_i } end |
#remove(uid) ⇒ Object
36 37 38 39 |
# File 'lib/pollter_geist/imap_commands.rb', line 36 def remove uid @logger.debug("removing #{uid}") @imap.uid_store uid, "+FLAGS", [:Deleted] end |
#select_mailbox(mailbox) ⇒ Object
10 11 12 13 |
# File 'lib/pollter_geist/imap_commands.rb', line 10 def select_mailbox mailbox logger.debug("selecting mailbox #{mailbox}") @imap.select(mailbox) end |
#wait_for(events, timeout = 29*60) ⇒ Object
Issues IDLE command for the imap server, it takes a list of events to listen for and returns once one of events occured or if there was a timeout.
21 22 23 |
# File 'lib/pollter_geist/imap_commands.rb', line 21 def wait_for events, timeout = 29*60 @idler.idle(events, timeout) end |
#wait_for_changes(timeout = 20*60) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pollter_geist/imap_commands.rb', line 51 def wait_for_changes timeout = 20*60 logger.debug('waiting for changes in inbox') change_set = ChangeListener.new change_set.tick() result = wait_for(['RECENT', 'EXPUNGE'], timeout) logger.debug('updating current view') change_set.tick() if change_set.changed? logger.debug('changes detected!') yield(change_set) else logger.debug('no changes detected') end end |