Take control over email subject in rails
-
01-10-2019 - |
Pergunta
I need to change the subject of the emails on a low level. What rails does is encoding the subject as quoted in whatever encoding is set. What I need is to make it quoted but split into chunks of 64 byte, as hotmail doesn't really goes with the standards :/
How do I tell rails to take the subject as is?
Solução
I had a look at this as a follow up to my answer to the previous question. The problem lies with TMail. It automatically removes and carriage returns from the subject. I created the following monkey patch as it seems to be the only solution to stop TMail's behaviour.
module TMail
class SubjectHeaderField < UnstructuredHeader
def parse
#Do nothing
end
end
class HeaderField
FNAME_TO_CLASS = FNAME_TO_CLASS.merge('subject' => SubjectHeaderField)
end
end
If you include it in the mailer in Rails 2.3.x it should work. Alternatively you might want to look at http://github.com/mikel/mail/ which is the default mailer in Rails 3?
Then you can set the header before encoding as the previous answer showed.
Outras dicas
"This is a very very long subject line of an email that hotmail has problems processing".scan(/.{1,16}/)
#=> ["This is a very v", "ery long subject", " line of an emai", "l that hotmail h", "as problems proc", "essing"]
I have done it at 16 chars, here's a link to the doc http://www.ruby-doc.org/core/classes/String.html#M000812
HTH