Class: MultiMail::Receiver::Postmark

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/multi_mail/postmark/receiver.rb

Overview

Postmark's incoming email receiver.

Instance Method Summary collapse

Methods included from Base

included, #initialize, #process, #valid?

Instance Method Details

#spam?(message) ⇒ Boolean

Returns whether the message is spam.

Parameters:

Returns:

  • (Boolean)

    whether the message is spam

See Also:



64
65
66
# File 'lib/multi_mail/postmark/receiver.rb', line 64

def spam?(message)
  message['X-Spam-Status'].value == 'Yes'
end

#transform(params) ⇒ Array<MultiMail::Message::Postmark>

Transforms the content of Postmark's webhook into a list of messages.

Parameters:

  • params (Hash)

    the content of Postmark's webhook

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/multi_mail/postmark/receiver.rb', line 11

def transform(params)
  headers = Multimap.new
  params['Headers'].each do |header|
    headers[header['Name']] = header['Value']
  end

  # Due to scoping issues, we can't call `transform_address` within `Mail.new`.
  from = transform_address(params['FromFull'])
  to   = params['ToFull'].map{|hash| transform_address(hash)}
  cc   = params['CcFull'].map{|hash| transform_address(hash)}

  message = Message::Postmark.new do
    headers    headers
    message_id params['MessageID']

    from      from
    to        to
    cc        cc
    reply_to  params['ReplyTo']
    subject   params['Subject']
    date      params['Date']

    text_part do
      body params['TextBody']
    end

    html_part do
      content_type 'text/html; charset=UTF-8'
      body CGI.unescapeHTML(params['HtmlBody'])
    end

    params['Attachments'].each do |attachment|
      add_file(:filename => attachment['Name'], :content => Base64.decode64(attachment['Content']))
    end
  end

  # Extra Postmark parameters.
  if params.key?('MailboxHash') && !params['MailboxHash'].empty?
    message.mailboxhash = params['MailboxHash']
  end
  if params.key?('MessageID') && !params['MessageID'].empty?
    message.messageid = params['MessageID']
  end
  if params.key?('Tag') && !params['Tag'].empty?
    message.tag = params['Tag']
  end

  [message]
end