views:

34

answers:

2

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?

+1  A: 
"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

Anand
Hey, thanks :) but I didn't meant this problem, I know how to split a string.the problem is that the subject is sent as one line, and I need it to be with \n after each 32 bytes...
Devenv
+1  A: 

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.

Steve Smith
Thanks, that actually worked...But hotmail still shows half line ok and half the quoted_printable gibberish...Any idea why?
Devenv
I can only imagine it's something to do with the quoting and encoding (=?iso-8859-1?Q?content?=\n[single space indent]something else?=)I just tried it with my exact content from http://stackoverflow.com/questions/3545916/rails-email-subject-is-gibberish-in-hotmail and it seems to work fine?
Steve Smith
Doing it with base64 encoding worked :/
Devenv