Module: MultiMail

Defined in:
lib/multi_mail/multimap.rb,
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/postmark/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/message.rb,
lib/multi_mail/cloudmailin/receiver.rb

Overview

Note:

The multimap gem was yanked, so we re-implement its functionality.

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.1.6"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.autoresponse_patternRegExp

Returns a message whose subject matches this pattern will be considered an autoresponse.

Returns:

  • (RegExp)

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



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

def autoresponse_pattern
  @autoresponse_pattern
end

Class Method Details

.autoresponse?(message) ⇒ Boolean

Returns whether a message is an autoresponse.

Parameters:

Returns:

  • (Boolean)

    whether a message is an autoresponse

See Also:



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
92
93
94
95
96
97
98
99
100
# File 'lib/multi_mail.rb', line 65

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



56
57
58
# File 'lib/multi_mail.rb', line 56

def setup
  yield self
end