Class: Incoming::Strategies::Postmark

Inherits:
Object
  • Object
show all
Includes:
Incoming::Strategy
Defined in:
lib/incoming/strategies/postmark.rb

Instance Attribute Summary

Attributes included from Incoming::Strategy

#message

Instance Method Summary collapse

Methods included from Incoming::Strategy

#authenticate, included, #receive

Constructor Details

#initialize(request) ⇒ Postmark

Returns a new instance of Postmark.



9
10
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
# File 'lib/incoming/strategies/postmark.rb', line 9

def initialize(request)
  source = JSON.parse(request.body.read)

  headers = parse_headers(source['Headers'])
  from    = parse_address(source['FromFull'])
  to      = source['ToFull'].map{|h| parse_address(h)}
  cc      = source['CcFull'].map{|h| parse_address(h)}

  @message = Mail.new do
    headers   headers
    from      from
    to        to
    cc        cc
    reply_to  source['ReplyTo']
    subject   source['Subject']
    date      source['Date']

    body source['TextBody']

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

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

    %w(MailboxHash MessageID Tag).each do |key|
      if source[key] =~ /\S/
        header[key] = source[key]
      end
    end
  end
end