Class: MailRoom::Mailbox
- Inherits:
-
Struct
- Object
- Struct
- MailRoom::Mailbox
- 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
- IMAP_IDLE_TIMEOUT =
Keep it to 29 minutes or less The IMAP serve will close the connection after 30 minutes of inactivity (which sending IDLE and then nothing technically is), so we re-idle every 29 minutes, as suggested by the spec: tools.ietf.org/html/rfc2177
29 * 60
- IMAP_CONFIGURATION =
29 minutes in in seconds
[:name, :email, :password, :host, :port].freeze
- MICROSOFT_GRAPH_CONFIGURATION =
[:name, :email].freeze
- MICROSOFT_GRAPH_INBOX_OPTIONS =
[:tenant_id, :client_id, :client_secret].freeze
- DEFAULTS =
Default attributes for the mailbox configuration
{ search_command: 'UNSEEN', delivery_method: 'postback', host: 'imap.gmail.com', port: 993, ssl: true, start_tls: false, limit_max_unread: 0, idle_timeout: IMAP_IDLE_TIMEOUT, delete_after_delivery: false, expunge_deleted: false, delivery_options: {}, arbitration_method: 'noop', arbitration_options: {}, logger: {} }
Instance Method Summary collapse
- #arbitration_klass ⇒ Object
- #arbitrator ⇒ Object
- #context ⇒ Object
-
#deliver(message) ⇒ Object
deliver the email message.
- #deliver?(uid) ⇒ Boolean
- #delivery ⇒ Object
- #delivery_klass ⇒ Object
- #imap? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Mailbox
constructor
Store the configuration and require the appropriate delivery method.
- #logger ⇒ Object
- #microsoft_graph? ⇒ Boolean
-
#ssl_options ⇒ Object
true, false, or ssl options hash.
- #validate! ⇒ Object
Constructor Details
Instance Method Details
#arbitration_klass ⇒ Object
93 94 95 |
# File 'lib/mail_room/mailbox.rb', line 93 def arbitration_klass Arbitration[arbitration_method] end |
#arbitrator ⇒ Object
101 102 103 |
# File 'lib/mail_room/mailbox.rb', line 101 def arbitrator @arbitrator ||= arbitration_klass.new() end |
#context ⇒ Object
126 127 128 |
# File 'lib/mail_room/mailbox.rb', line 126 def context { email: self.email, name: self.name } end |
#deliver(message) ⇒ Object
deliver the email message
113 114 115 116 117 118 119 |
# File 'lib/mail_room/mailbox.rb', line 113 def deliver() body = .body return true unless body logger.info({context: context, uid: .uid, action: "sending to deliverer", deliverer: delivery.class.name, byte_size: body.bytesize}) delivery.deliver(body) end |
#deliver?(uid) ⇒ Boolean
105 106 107 108 109 |
# File 'lib/mail_room/mailbox.rb', line 105 def deliver?(uid) logger.info({context: context, uid: uid, action: "asking arbiter to deliver", arbitrator: arbitrator.class.name}) arbitrator.deliver?(uid) end |
#delivery ⇒ Object
97 98 99 |
# File 'lib/mail_room/mailbox.rb', line 97 def delivery @delivery ||= delivery_klass.new() end |
#delivery_klass ⇒ Object
89 90 91 |
# File 'lib/mail_room/mailbox.rb', line 89 def delivery_klass self[:delivery_klass] ||= Delivery[delivery_method] end |
#imap? ⇒ Boolean
130 131 132 |
# File 'lib/mail_room/mailbox.rb', line 130 def imap? !microsoft_graph? end |
#logger ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mail_room/mailbox.rb', line 78 def logger @logger ||= case self[:logger] when Logger self[:logger] else self[:logger] ||= {} MailRoom::Logger::Structured.new(normalize_log_path(self[:logger][:log_path])) end end |
#microsoft_graph? ⇒ Boolean
134 135 136 |
# File 'lib/mail_room/mailbox.rb', line 134 def microsoft_graph? self[:inbox_method].to_s == 'microsoft_graph' end |
#ssl_options ⇒ Object
true, false, or ssl options hash
122 123 124 |
# File 'lib/mail_room/mailbox.rb', line 122 def replace_verify_mode(ssl) end |
#validate! ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/mail_room/mailbox.rb', line 138 def validate! if microsoft_graph? validate_microsoft_graph! else validate_imap! end end |