Module: MultiMail

Defined in:
lib/multi_mail.rb,
lib/multi_mail/service.rb,
lib/multi_mail/version.rb,
lib/multi_mail/receiver.rb,
lib/multi_mail/sender/base.rb,
lib/multi_mail/message/base.rb,
lib/multi_mail/receiver/base.rb,
lib/multi_mail/mailgun/sender.rb,
lib/multi_mail/mailgun/message.rb,
lib/multi_mail/mandrill/sender.rb,
lib/multi_mail/postmark/sender.rb,
lib/multi_mail/sendgrid/sender.rb,
lib/multi_mail/simple/receiver.rb,
lib/multi_mail/mailgun/receiver.rb,
lib/multi_mail/mandrill/message.rb,
lib/multi_mail/sendgrid/message.rb,
lib/multi_mail/mandrill/receiver.rb,
lib/multi_mail/postmark/receiver.rb,
lib/multi_mail/sendgrid/receiver.rb,
lib/multi_mail/cloudmailin/receiver.rb

Defined Under Namespace

Modules: Message, Receiver, Sender, Service Classes: Error, ForgedRequest, InvalidAPIKey, InvalidMessage, MissingBody, MissingRecipients, MissingSender, MissingSubject

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.autoresponse_patternRegExp



34
35
36
# File 'lib/multi_mail.rb', line 34

def autoresponse_pattern
  @autoresponse_pattern
end

Class Method Details

.autoresponse?(message) ⇒ Boolean

Returns whether a message is an autoresponse.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/multi_mail.rb', line 56

def autoresponse?(message)
  !!(
    # If any of the following headers are present and have the given value.
    {
      'Delivered-To'          => 'Autoresponder',
      'Precedence'            => 'auto_reply',
      'Return-Path'           => nil, # in most cases, this would signify a bounce
      'X-Autoreply'           => 'yes',
      'X-FC-MachineGenerated' => 'true',
      'X-POST-MessageClass'   => '9; Autoresponder',
      'X-Precedence'          => 'auto_reply',
    }.find do |name,value|
      message[name] && message[name].decoded == value
    end ||
    # If any of the following headers are present.
    [
      'X-Autogenerated',  # value is one of Forward, Group, Letter, Mirror, Redirect or Reply
      'X-AutoReply-From', # value is an email address
      'X-Autorespond',    # value is an email subject
      'X-Mail-Autoreply', # value is often "dtc-autoreply" but can be another tag
    ].any? do |name|
      message[name]
    end ||
    # If the Auto-Submitted header is present and is not equal to "no".
    (
      message['Auto-Submitted'] &&
      message['Auto-Submitted'].decoded != 'no'
    ) ||
    # If the message subject matches the autoresponse pattern.
    (
      MultiMail.autoresponse_pattern &&
      message.subject &&
      message.subject[MultiMail.autoresponse_pattern]
    )
  )
end

.setup {|_self| ... } ⇒ Object

Configures MultiMail.

  • autoresponse_pattern: a message whose subject matches this pattern will be considered an autoresponse

Examples:

require 'multi_mail'

MultiMail.setup do |config|
  config.autoresponse_pattern = /^Out of Office AutoReply:/i
end

Yields:

  • (_self)

Yield Parameters:

  • _self (MultiMail)

    the object that the method was called on



47
48
49
# File 'lib/multi_mail.rb', line 47

def setup
  yield self
end