Class: Vmail::InboxPoller
- Inherits:
-
ImapClient
- Object
- ImapClient
- Vmail::InboxPoller
- Defined in:
- lib/vmail/inbox_poller.rb
Constant Summary
Constants included from ShowingHeaders
Instance Attribute Summary
Attributes inherited from ImapClient
Instance Method Summary collapse
- #get_message_headers(message_ids) ⇒ Object
- #log(string) ⇒ Object
-
#start_polling ⇒ Object
This is a second IMAP client operating in a separate process.
- #update ⇒ Object
Methods inherited from ImapClient
#append_to_file, #check_for_new_messages, #clear_cached_message, #close, #create_if_necessary, daemon, #decrement_max_seqno, #deliver, #format_headers, #format_sent_message, #forward_template, #get_highest_message_id, #get_mailbox_status, #handle_error, #initialize, #list_mailboxes, #mailbox_aliases, #mailboxes, #more_messages, #new_mail_from_input, #new_message_template, #open, #open_html_part, #prime_connection, #reconnect_if_necessary, #reload_mailbox, #revive_connection, #save_attachments, #select_mailbox, #signature, #smtp_settings, #spawn_thread_if_tty, start, #window_width=, #with_open
Methods included from ReplyTemplating
#reply_cc, #reply_headers, #reply_recipient, #reply_template
Methods included from FlaggingAndMoving
#convert_to_message_ids, #copy_to, #flag, #move_to
Methods included from ShowingMessage
#cached_full_message?, #current_mail, #current_message, #fetch_and_cache, #format_parts_info, #show_message
Methods included from ShowingHeaders
#extract_address, #fetch_and_cache_headers, #format_flags, #format_header_for_list, #with_more_message_line
Methods included from Searching
Methods included from AddressQuoter
Methods included from Helpers
#divider, #number_to_human_size, #retry_if_needed
Constructor Details
This class inherits a constructor from Vmail::ImapClient
Instance Method Details
#get_message_headers(message_ids) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vmail/inbox_poller.rb', line 45 def () = .map {|| m = Message[] if m.nil? raise "Message #{} not found" end m } res = .map {|m| m.sender }.join(", ") res end |
#log(string) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/vmail/inbox_poller.rb', line 57 def log(string) if string.is_a?(::Net::IMAP::TaggedResponse) string = string.raw_data end @logger.debug "[INBOX POLLER]: #{string}" end |
#start_polling ⇒ Object
This is a second IMAP client operating in a separate process
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vmail/inbox_poller.rb', line 6 def start_polling n = [`which notify-send`.chomp, `which growlnotify`.chomp].detect {|c| c != ''} if n log "Using notify tool: #{n}" @notifier = case n when /notify-send/ Proc.new {|t, m| `#{n} '#{t}' '#{m}'` } when /growlnotify/ Proc.new {|t, m| `#{n} -t '#{t}' -m '#{m}'` } end else log "No notification tool detected. INBOX polling aborted." return end log "INBOX POLLER: started polling" @mailboxes.unshift "INBOX" select_mailbox "INBOX" search "ALL" loop do log "INBOX POLLER: checking inbox" update sleep 30 end end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vmail/inbox_poller.rb', line 32 def update new_ids = if !new_ids.empty? self.max_seqno = new_ids[-1] @ids = @ids + new_ids = fetch_and_cache_headers(new_ids) res = () @notifier.call "Vmail: new email", "from #{res}" end rescue log "VMAIL_ERROR: #{[$!., $!.backtrace].join("\n")}" end |