跳至内容 跳至搜索

封装一个路由,该路由可以与传入的电子邮件进行匹配,并提供匹配邮箱类的查找。有关不同路由地址以及如何在 ActionMailbox::Base 文档中使用它们的示例,请参见示例。

方法
M
N

属性

[R] address
[R] mailbox_name

类公共方法

new(address, to:)

# File actionmailbox/lib/action_mailbox/router/route.rb, line 10
def initialize(address, to:)
  @address, @mailbox_name = address, to

  ensure_valid_address
end

实例公共方法

mailbox_class()

# File actionmailbox/lib/action_mailbox/router/route.rb, line 31
def mailbox_class
  "#{mailbox_name.to_s.camelize}Mailbox".constantize
end

match?(inbound_email)

# File actionmailbox/lib/action_mailbox/router/route.rb, line 16
def match?(inbound_email)
  case address
  when :all
    true
  when String
    inbound_email.mail.recipients.any? { |recipient| address.casecmp?(recipient) }
  when Regexp
    inbound_email.mail.recipients.any? { |recipient| address.match?(recipient) }
  when Proc
    address.call(inbound_email)
  else
    address.match?(inbound_email)
  end
end