Sha256: e5b606d48f6ede06e4c6a66a0ba9e2ec1754b4314f793edf3133578a2247bb88

Contents?: true

Size: 731 Bytes

Versions: 5

Compression:

Stored size: 731 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|
        part.body.raw_source.gsub!(/%7B%7BMAILKICK_TOKEN%7D%7D/, token)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mailkick-0.1.0 lib/mailkick/processor.rb
mailkick-0.0.6 lib/mailkick/processor.rb
mailkick-0.0.5 lib/mailkick/processor.rb
mailkick-0.0.4 lib/mailkick/processor.rb
mailkick-0.0.3 lib/mailkick/processor.rb