foens/hpop

exception " 'null' is not supported encoding name" when charset=null

Opened this issue · 1 comments

Trim commented

Hello,

We have an application relying on OpenPop to fetch email messages and their attachments on pop connection.

Recently, we had this style of error:

'null' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name

at System.Globalization.EncodingTable.internalGetCodePageFromName(String name)
at System.Globalization.EncodingTable.GetCodePageFromName(String name)
at System.Text.Encoding.GetEncoding(String name)
at OpenPop.Mime.Decode.EncodingFinder.FindEncoding(String characterSet)
at OpenPop.Mime.MessagePart.ParseBodyEncoding(String characterSet)
at OpenPop.Mime.MessagePart..ctor(Byte[] rawBody, MessageHeader headers)
at OpenPop.Mime.MessagePart.ParseMultiPartBody(Byte[] rawBody)
at OpenPop.Mime.Message..ctor(Byte[] rawMessageContent, Boolean parseBody)
at OpenPop.Pop3.Pop3Client.GetMessage(Int32 messageNumber)

My colleague has run OpenPop in debug mode and we have found that the issue seems to come from ParseBodyEncoding function in MessagePart.cs.

To fix this issue we had to modify these lines with:

if (!string.IsNullOrEmpty(characterSet) && charSet.toLower() != "null" )
  encoding = EncodingFinder.FindEncoding(characterSet);

We've found that, because the header of problematic messages contained this type of text:

Content-Type: application/pdf; charset=null;
name="SomePDF.pdf"
Content-Disposition: attachment;
filename="SomePDF.pdf"
Content-Transfer-Encoding: base64

That's a bit of workaround, I think the code could set characterSet to the real null if it detect that the string is equals to the string "null".

Thanks,
Adrien

foens commented

You can supply a custom EncodingFinder and handle the "null" parameter there.
There are lots of "special" values out there, we can't handle them all.
Thanks for reporting though. You are welcome to supply a patch, and I will then merge it in. I do not have much free time to work on this, sorry.
You can also see the example at http://hpop.sourceforge.net/exampleChangeCharacterSetMapping.php