Module: OutboundMailbox

Defined in:
lib/outbound_mailbox.rb,
lib/outbound_mailbox/engine.rb,
lib/outbound_mailbox/version.rb,
app/models/outbound_mailbox/record.rb,
lib/outbound_mailbox/mail_delivery.rb,
app/models/outbound_mailbox/outbound_email.rb,
lib/generators/outbound_mailbox/install_generator.rb

Defined Under Namespace

Classes: Engine, InstallGenerator, MailDelivery, OutboundEmail, Record

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.conductor_routes_enabled_for_delivery_method?(delivery_method) ⇒ Boolean

True when delivery_method is configured as outbound_mailbox for Action Mailer. See also mount_conductor_routes? for overriding via config.outbound_mailbox.mount_conductor.

Returns:

  • (Boolean)


13
14
15
# File 'lib/outbound_mailbox.rb', line 13

def self.conductor_routes_enabled_for_delivery_method?(delivery_method)
  delivery_method&.to_sym == :outbound_mailbox
end

.mail_message_from_raw_source(source) ⇒ Object

Same behavior as Action Mailbox’s Mail.from_source, without pulling in that gem.



43
44
45
# File 'lib/outbound_mailbox.rb', line 43

def self.mail_message_from_raw_source(source)
  Mail.new(Mail::Utilities.binary_unsafe_to_crlf(source.to_s))
end

.mount_conductor_routes?(app) ⇒ Boolean

Whether conductor routes should be drawn (config/routes.rb).

config.outbound_mailbox.mount_conductor must be one of:

  • nil (default) — mount only when conductor_routes_enabled_for_delivery_method? is true for app.config.action_mailer.delivery_method.

  • true / false — force conductor routes on or off (ignore delivery method). Use true if you persist mail without setting Action Mailer to :outbound_mailbox but still want the UI.

  • Anything responding to call (Proc, method object, …) — invoked as callable.call(app); the return value is coerced with !! so use a boolean return for clarity.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/outbound_mailbox.rb', line 26

def self.mount_conductor_routes?(app)
  raw = app.config.outbound_mailbox.mount_conductor
  case raw
  when nil
    conductor_routes_enabled_for_delivery_method?(app.config.action_mailer.delivery_method)
  when true, false
    raw
  else
    unless raw.respond_to?(:call)
      raise ArgumentError, "config.outbound_mailbox.mount_conductor must be nil, true/false, or callable; got #{raw.class}"
    end

    !!raw.call(app)
  end
end