Sha256: 0c01087cae38c63c86cb5dfcbcd38b7e3d4a10b0326971b45f5015eebd8b66ef

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

module Mail
  class Message

    include Postmark::SharedMessageExtensions

    def html?
      content_type && content_type.include?('text/html')
    end

    def body_html
      if html_part.nil?
        body.to_s if html?
      else
        html_part.body.to_s
      end
    end

    def body_text
      if text_part.nil?
        body.to_s unless html?
      else
        text_part.body.to_s
      end
    end

    def export_attachments
      export_native_attachments + postmark_attachments
    end

    def export_headers
      [].tap do |headers|
        self.header.fields.each do |field|
          key, value = field.name, field.value
          next if bogus_headers.include? key.downcase
          name = key.split(/-/).map { |i| i.capitalize }.join('-')

          headers << { "Name" => name, "Value" => value }
        end
      end
    end

    def to_postmark_hash
      ::Postmark::MailMessageConverter.new(self).run
    end

  protected

    def export_native_attachments
      attachments.map do |attachment|
        basics = {"Name" => attachment.filename,
                  "Content" => pack_attachment_data(attachment.body.decoded),
                  "ContentType" => attachment.mime_type}
        specials = attachment.inline? ? {'ContentID' => attachment.url} : {}

        basics.update(specials)
      end
    end

    def bogus_headers
      %q[
        return-path  x-pm-rcpt
        from         reply-to
        sender       received
        date         content-type
        cc           bcc
        subject      tag
        attachment   to
      ]
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
postmark-1.2.1 lib/postmark/message_extensions/mail.rb
postmark-1.2.0 lib/postmark/message_extensions/mail.rb
postmark-1.1.2 lib/postmark/message_extensions/mail.rb
postmark-1.1.1 lib/postmark/message_extensions/mail.rb
postmark-1.1.0 lib/postmark/message_extensions/mail.rb