For those of us using ActionMailer in our Ruby projects… you might want to check your subjects if you’re integrating with an automated system.
Spent a few hours debugging a situation where I was sending out emails to an automated system that parses the subject line… watched the email go through and the system send me back responses that were not paying attention to the subject data.
I started with the end points (the responses) and worked my back through code until I realized (through carefully timed queries) that when the emails leave ActionMailer and get sent through the system that a call to mail.encoded was happening:
Found in /opt/local/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer/base.rb:
def perform_delivery_sendmail(mail)
IO.popen("#{sendmail_settings[:location]} #{sendmail_settings[:arguments]}","w+") do |sm|
sm.print(mail.encoded.gsub(/\r/, ''))
sm.flush
end
end
So I checked my email record and called mail.encoded…. and to my suprise an extra “\r\n\t” appeared in my message.
After some spot checking I realized that ActionMailer was adding this when the subject line reached 190+ characters…
AHHHHHHHHH!!!!!!!!!!! These kinds of assumptions kill a person when they don’t know. I tried looking through documentation and it’s not there… and I know automated systems should account for things, well actually… RFC2822 suggests header folding, so whatever.
But at any rate… just wanted to put this out there to maybe help someone else!