Class: MailRoom::MailboxHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/mailbox_handler.rb

Overview

Fetches new email messages for delivery

Author:

  • Tony Pitale

Instance Method Summary collapse

Constructor Details

#initialize(mailbox, imap) ⇒ MailboxHandler

build a handler for this mailbox and our imap connection

Parameters:

  • mailbox (MailRoom::Mailbox)

    the mailbox configuration

  • imap (Net::IMAP::Connection)

    the open connection to gmail



8
9
10
11
# File 'lib/mail_room/mailbox_handler.rb', line 8

def initialize(mailbox, imap)
  @mailbox = mailbox
  @imap = imap
end

Instance Method Details

#processObject

deliver each of the new messages



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mail_room/mailbox_handler.rb', line 14

def process
  # return if idling? || !running?

  new_messages.each do |msg|
    # puts msg.attr['RFC822']

    # loop over delivery methods and deliver each
    delivered = @mailbox.deliver(msg)

    if delivered && @mailbox.delete_after_delivery
      @imap.store(msg.seqno, "+FLAGS", [Net::IMAP::DELETED])
    end
  end

  @imap.expunge if @mailbox.delete_after_delivery
end