Attachment Encoding problem

Topics: Issues
May 14, 2014 at 1:46 PM

First of all thank you for this nice tool and for all the time and effort you seem to put into this.

Unfortunately, I'm experiencing an encoding problem when i download an attachment from a Gmail account.
I tried debugging to try and solve this myself, but im stuck.

It appears my Message has 3 bodyparts:
1) contains the body as text and ContentType = {text/plain; charset=iso-8859-1}
2) contains the body as html and ContentType = {text/plain; charset=iso-8859-1}
3) contains the attachment and ContentType is {application/octet-stream; name=5A48.txt}

There's no charset information in the ContentType, so the default UTF8 charset is used to decode the "QuotedPrintable" string and this gives me an incorrect result.
When i download the attachment from gmail directly, it has the correct encoding.

Is it safe to assume that as the rest of the message is iso-8859-1, that the attachment can be regarded as the same?
May 14, 2014 at 2:20 PM
Edited May 14, 2014 at 2:21 PM
Hi M_DB,

I think it's safe to assume that the attachments are encoded same as the message, because normally, if the encoding of a body part/attachment differs from the encoding of the message, the ContentType of the body part/attachment will have the charset set.

I updated the code and now it works as follows:
-> Download of a body part/attachment is invoked
-> Check if there is an encoding set for this body part/attachement (MessageContent.ContentType.CharSet)

     --> If yes, use it
     --> Otherwise, check if there's an encoding set for the message (Message.ContentType.CharSet)
           ---> If yes, use it  
           ---> Otherwise, use UTF-8
You can give it a try using the latest source code from the repository.


May 14, 2014 at 2:33 PM
Thank you for this super fast repsonse.
Unfortunately this fix doesnt work for me apparently.

The message's ContentType comes out as null because in the header it is specified as multipart/mixed;
May 15, 2014 at 8:26 AM
Hi M_DB,

hm, are you sure the attachement has no charset set? It might be a bug in the code for receiving the part itself. Can you create a log file as described in the documentation? This will help a lot.