thoughtbot/griddler — pull request #63 by georgebrock (2013-06-25 17:04:21+00:00)
Title: Easily reply to Griddler::Emails with ActionMailer

Extracted from a side project I'm working on that runs emails through Google
Translate and replies with an English version. The tests are a little repetitive,
but I'd appreciate feedback on the concept before I do the final tidying up.

Provides a mixin that can be included into ActionMailer::Base subclasses to
easily create replies to Griddler emails that are compliant with the various
reply-related requirements of RFC 5322:

* Selecting the correct recipient using Reply-To or From (§ 3.6.2)
* Setting the In-Reply-To and References headers for message threading (§ 3.6.4)
* Prefixing the subject with "Re:" while avoiding double-prefixes (§ 3.6.5)

Example use:

# app/mailers/my_mailer.rb
require 'griddler/reply_mixin'

class MyMailer
include Griddler::ReplyMixin

default from: 'info@example.com'

def response(email)
reply(email, subject: 'Override the default reply subject')
end
end

# app/models/email_processor.rb
class EmailProcessor
def self.process(email)
MyMailer.response(email).deliver
end
end