Class: MailRoom::Mailbox

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

Overview

Holds configuration for each of the email accounts we wish to monitor

and deliver email to when new emails arrive over imap

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Mailbox

Store the configuration and require the appropriate delivery method

Parameters:

  • attributes (Hash) (defaults to: {})

    configuration options



19
20
21
22
23
# File 'lib/mail_room/mailbox.rb', line 19

def initialize(attributes={})
  super(*attributes.values_at(*members))

  require_relative("./delivery/#{(delivery_method || 'postback')}")
end

Instance Method Details

#deliver(message) ⇒ Object

deliver the imap email message

Parameters:

  • message (Net::IMAP::FetchData)


41
42
43
# File 'lib/mail_room/mailbox.rb', line 41

def deliver(message)
  delivery_klass.new(self).deliver(message.attr['RFC822'])
end

#delivery_klassObject

move to a mailbox deliverer class?



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mail_room/mailbox.rb', line 26

def delivery_klass
  case delivery_method
  when "noop"
    Delivery::Noop
  when "logger"
    Delivery::Logger
  when "letter_opener"
    Delivery::LetterOpener
  else
    Delivery::Postback
  end
end