views:

80

answers:

2

Hi,

Sending emails works perfectly for all major email clients, except for hotmail (and some other), it shows as:

=?windows-1255?Q?Z33=30_=F9=22=E7=20=F2=E1=E5=F8_=F9=E5=E1=F8=20=E1=F9=E5=E5=E9=20=36=30_=F9=22=E7=20=EC=22=EE=F8=E2=E5=E6=E4=22=2C_=E1=E9=FA_=F7=F4=E4=20=E5=EE=E0=F4=E9=E9=E4_=EE=F9=F4=E7=FA=E9=FA=2C=20=E1=EE=FA=E7=ED=20=F9=E5=F7=20=E4=F4=F9=F4=

Dosn't matter if it's utf8 or not. It seems like hotmail can't read long quoted subjects, because for shorter ones it shows up ok.

AFAIK what gmail does for example is to split the subject to pieces, 64 (or something) chars long... But I can't figure out how to do that in rails (2.3.8). Rails encodes the subject by default, in quoted form, can't find how to override that so I could split it by myself...

Thanks.

A: 

Hey,

If you have a really long subject line then you might need to split it onto multiple lines using ?= like the following:

Subject: =?iso-8859-1?Q?This_is_a_really_long_subject_that_should_need_so?=
 =?iso-8859-1?Q?me_encoding_to_make_sure_that_it_all_fits_correct?=
 =?iso-8859-1?Q?ly_=E7?=

I had to put a 'ç' in at the end of the subject line to get apple mail to quote it but it should give you the picture. I can't remember exactly how long it should be before you split it I think its 78 after encoding but not 100% sure, 64 will be safe if that is what you are seeing.

Steve Smith
Hey, thanks for answering, but I know this method, what I can't figure out is how to do that in rails...
Devenv
A: 

This is what worked for me:

module ActionMailer
  module Quoting
    def quoted_printable(text, charset)
      require 'base64'
      #text.scan_utf8(/.{1,64}/m).map{|text| "=?#{charset}?B?#{Base64.b64encode(text)}?="}.join("\n")
      "=?#{charset}?B?#{Base64.b64encode(text).gsub(/\n/, '')}?="
    end
  end
end

module TMail
  class SubjectHeaderField < UnstructuredHeader
    def parse
      #Do nothing
    end
  end

  class HeaderField
    FNAME_TO_CLASS = FNAME_TO_CLASS.merge('subject' => SubjectHeaderField)
  end
end
Devenv