Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding choosing for body content.Set charset for alternative views... #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexSte
Copy link

@AlexSte AlexSte commented Jun 19, 2014

2 changes -

  1. To correctly process body of emails with non ASCII encoding we need to use encoding that was set in server. if not explicitly set - use ASCII.
  2. sometime is usefull to know which encoding is using in alternative views.(can be different from body encoding). so setting charset param to alternative view object will solve this issue.

@Desteny
Copy link

Desteny commented Jul 30, 2014

Thanks for this,
I can confirm the Bug, and i confirm your Pull request as a Solution.

I have tested your fix with several cCents in different Usecases, and i found a missing Part:

Your Solution doesn't work for "FetchOptions.Normal" cause of IMapClient.GetMessageData has a internal GetData call without passing the correct encoding!

I tryed to fix this in the GetMessageData, but i'm not able to split the Response into different Bodyparts with different encoding for each one.

So i made a different Workaround, changing FetchOptions.Normal to use "GetMessage".
This solves the Problem but it requires aditional server roundtrips (fetching header and body structure)

I hope this Feature/Fix will be added soon to NuGet cause its realy important for UTF8 Mails, and maybe with proper Solution for my Problem:

Here my Patch (no pull request cause of only one line changed)

diff --git a/ImapClient.cs b/ImapClient.cs
index 033317e..2e75a87 100644
--- a/ImapClient.cs
+++ b/ImapClient.cs
@@ -1103,7 +1103,9 @@ public class ImapClient : IImapClient
                    return GetMessage(uid, p => { return p.Type == ContentType.Text; },
                        seen, mailbox);
                default:
-                   return MessageBuilder.FromMIME822(GetMessageData(uid, seen, mailbox));
+                   return GetMessage(uid, p => { return true; },
+                       seen, mailbox);
+                   //return MessageBuilder.FromMIME822(GetMessageData(uid, seen, mailbox));
            }
        }

@jstedfast
Copy link

As an alternative, you guys might consider using MailKit instead as it properly deals with charsets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants