Sha256: 5fa1e2d2196c36e3c4d0ea8238dcc65ec6baf494fc595b35154fa82e2f2345cc

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

require 'mail'

module Package

  class << self

    def new(message)
      mail = message[:html_body] ? mixed(message) : plain(message)
      mail.charset = 'UTF-8'

      mail['In-Reply-To'] = message[:in_reply_to] if message[:in_reply_to]
      mail['List-Archive'] = message[:list_archive] if message[:list_archive]
      mail['List-Id'] = message[:list_id] if message[:list_id]

      if message[:return_path]
        mail['Return-Path'] = message[:return_path]
        mail['Bounces-To']  = message[:return_path]
        mail['Errors-To']   = message[:return_path]
      end

      mail
    end

    def plain(message)
      mail = Mail.new do
        from        message[:from]
        to          message[:to]
        reply_to    message[:reply_to] if message[:reply_to]
        # sender    message[:sender] if message[:sender]
        subject     message[:subject]
        message_id  message[:message_id] if message[:message_id]
        body        message[:body]
      end
    end

    def mixed(message)
      mail = Mail.new do
        from        message[:from]
        to          message[:to]
        reply_to    message[:reply_to] if message[:reply_to]
        # sender    message[:sender] if message[:sender]
        subject     message[:subject]
        message_id  message[:message_id] if message[:message_id]
        text_part do
          body      message[:body]
        end
        html_part do
          content_type 'text/html; charset=UTF-8'
          body      message[:html_body]
        end
      end
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tuktuk-0.3.1 lib/tuktuk/package.rb
tuktuk-0.3.0 lib/tuktuk/package.rb
tuktuk-0.2.3 lib/tuktuk/package.rb
tuktuk-0.2.2 lib/tuktuk/package.rb
tuktuk-0.2.1 lib/tuktuk/package.rb
tuktuk-0.2.0 lib/tuktuk/package.rb
tuktuk-0.1.3 lib/tuktuk/package.rb