Accented chars in mail subject

Jul 25, 2008 at 11:11 AM


If there are accented chars in the subject of a mail, ImapMailboxMessage.Subject contains the encoded subject in utf8. Is there a way to fix this?


Aug 28, 2008 at 12:04 PM
Edited Aug 28, 2008 at 12:05 PM

Hi again,

I've found the solution, the answer is in RFC2047. The problem is that Koolwired doesn't take into account that a header can have the "B" encoding as defined in section 4.1 of the RFC, it always considers that headers are in the "Q" encoding of section 4.2. The fix is to extend the method string ImapDecode.Decode(string input) to take this into account:

internal static string Decode(string input)
if (input == "" || input == null)
return "";
Regex regex = new Regex(@"=\?(?<Encoding>[^\?]+)\?(?<Method>[^\?]+)\?(?<Text>[^\?]+)\?=");
MatchCollection matches = regex.Matches(input);
string ret = input;
foreach (Match match in matches)
string encoding = match.Groups["Encoding"].Value;
string method = match.Groups["Method"].Value;
string text = match.Groups["Text"].Value;
string decoded;
if (method == "B") {
byte[] bytes = Convert.FromBase64String(text);
Encoding enc = Encoding.GetEncoding(encoding);
decoded = enc.GetString(bytes);
else {
decoded = Decode(text, Encoding.GetEncoding(encoding));
ret = ret.Replace(match.Groups[0].Value, decoded);
return ret;

Hope this helps. It would be cool if the maintainer of the project could update the library. I can send him the corrected source file if he wishes.