1
Vote

MIME encoded-word disregards encoding

description

Cheers!
 
Thank you for a wonderful project. We're using it for our non-profit to build our own mailing lists.
 
I had some problems with my name showing incorrectly (Mikael Lönnroth) in the From field when it was base64 encoded so I tracked it down to this function:
 
private static string MyMatchEvaluatorBase64(Match m)
 
.. which is responsible for decoding the base64 encoded string in the header. Unfortunately (if I understand it correctly) it only uses UTF-7 for this, so if the headers are encoded in any other way, the special chars will decode incorrectly. I made this small change to illustrate the idea of what it should do, but please comment and correct my code as you need. The names are showing correctly now, though :)
 
private static string MyMatchEvaluatorBase64(Match m)
    {
        String encoding =
            m.Groups[0].ToString().Substring(2, m.Groups[0].ToString().IndexOf("?B") - 2);
 
        System.Text.Encoding enc =
            System.Text.Encoding.GetEncoding(encoding);
 
        // System.Text.Encoding enc = System.Text.Encoding.UTF7;
        return enc.GetString(Convert.FromBase64String(m.Groups[1].Value));
    }

comments