0

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?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Boris Churzin
  • 1,245
  • 1
  • 10
  • 23

2 Answers2

1
"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 Shah
  • 14,575
  • 16
  • 72
  • 110
  • 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... – Boris Churzin Aug 26 '10 at 14:31
1

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
  • 5,146
  • 1
  • 30
  • 31
  • Thanks, that actually worked... But hotmail still shows half line ok and half the quoted_printable gibberish... Any idea why? – Boris Churzin Aug 26 '10 at 15:53
  • 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 Aug 27 '10 at 09:27