ActionMailer decoding multi-part w/ charset

I am using ActionMailer to parse incoming email from gmail. I found that multi-part emails coming from Outlook clients are encoded with charset='Windows-1252'. After creating a mail object (see Receiver.receive() below) each part.body has charset='UTF-8' and defaulted_charset=true. When I grab part.body.to_s the characters aren't encoded correctly (hyphen encoded as =96 results in non- printable char in UTF-8 string from to_s). I was assuming it would grab the charset off the part header, but didn't see anything in initialize that would do that (seems biased for composing email rather than parsing existing).

Is this a limitation, defect, or just my ignorance? Thanks for any help. As a workaround, I'm calling force_encoding() on the string and then explicitly encoding to UTF-8.


Rails 3.0.10

class Receiver < ActionMailer::Base   def receive(email)     email   end end

Hi Mark,

I recently came across a similar encoding problem with email and used #force_encoding as you describe. The issue is with the Mail gem that ActionMailer uses.

The gem currently has many encoding issues filed and it’s hard to see if this exact MIME part encoding problem has been raised.



Hi Andrew, thanks for the note. I found a google group for mail and found a related thread:

Looks like stepchud has a few patches for this:

but hasn't gotten around to submitting pull request.

Best, Mark