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

Constant Summary collapse

DEFAULTS =

Default attributes for the mailbox configuration

{
  :search_command => 'UNSEEN',
  :delivery_method => 'postback',
  :host => 'imap.gmail.com',
  :port => 993,
  :ssl => true,
  :delete_after_delivery => false,
  :delivery_options => {}
}

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



36
37
38
39
40
# File 'lib/mail_room/mailbox.rb', line 36

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

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

Instance Method Details

#deliver(message) ⇒ Object

deliver the imap email message

Parameters:

  • message (Net::IMAP::FetchData)


60
61
62
63
64
65
# File 'lib/mail_room/mailbox.rb', line 60

def deliver(message)
  message = message.attr['RFC822']
  return true unless message
  
  delivery_klass.new(parsed_delivery_options).deliver(message)
end

#delivery_klassObject

move to a mailbox deliverer class?



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mail_room/mailbox.rb', line 43

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