Sha256: ab2658e329a65b53e946bbb51dd8fd4bd035f22374aa5982c11b2b766366d445

Contents?: true

Size: 821 Bytes

Versions: 3

Compression:

Stored size: 821 Bytes

Contents

module Mailkick
  class Processor
    attr_reader :message

    def initialize(message)
      @message = message
    end

    def process
      email = message.to.first
      user = Mailkick.user_method.call(email) if Mailkick.user_method
      list = message[:mailkick_list].try(:value)
      if list
        # remove header
        message[:mailkick_list] = nil
      end

      verifier = ActiveSupport::MessageVerifier.new(Mailkick.secret_token)
      token = verifier.generate([email, user.try(:id), user.try(:class).try(:name), list])

      parts = message.parts.any? ? message.parts : [message]
      parts.each do |part|
        if part.content_type.match(/text\/(html|plain)/)
          part.body = part.body.decoded.gsub(/%7B%7BMAILKICK_TOKEN%7D%7D/, CGI.escape(token))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mailkick-0.2.1 lib/mailkick/processor.rb
mailkick-0.2.0 lib/mailkick/processor.rb
mailkick-0.1.6 lib/mailkick/processor.rb