Permalink
Browse files

Potential fix for #54; ensures the `Encoding` property of the ImapCli…

…ent is used, and default the charset to `ISO-8859-1`.
  • Loading branch information...
1 parent bce8c78 commit e186bd8df3822d8e65a8b0f4d745576f26cd015d @andyedinborough committed Apr 8, 2012
Showing with 17 additions and 13 deletions.
  1. +16 −12 ImapClient.cs
  2. +1 −1 TextClient.cs
View
@@ -424,20 +424,24 @@ public enum AuthMethods {
foreach (var key in imapHeaders.AllKeys.Except(new[] { "UID", "Flags", "BODY[]", "BODY[HEADER]" }, StringComparer.OrdinalIgnoreCase))
mail.Headers.Add(key, new HeaderValue(imapHeaders[key]));
- var body = new StringBuilder();
- int remaining = mail.Size;
- var buffer = new byte[8192];
- int read;
- while (remaining > 0) {
- read = _Stream.Read(buffer, 0, Math.Min(remaining, buffer.Length));
- body.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, read));
- remaining -= read;
- }
+ using (var body = new System.IO.MemoryStream()) {
+ int remaining = mail.Size;
+ var buffer = new byte[8192];
+ int read;
+ while (remaining > 0) {
+ read = _Stream.Read(buffer, 0, Math.Min(remaining, buffer.Length));
+ body.Write(buffer, 0, read);
+ remaining -= read;
+ }
- var next = Convert.ToChar(_Stream.ReadByte());
- System.Diagnostics.Debug.Assert(next == ')');
+ var next = Convert.ToChar(_Stream.ReadByte());
+ System.Diagnostics.Debug.Assert(next == ')');
- mail.Load(body.ToString(), headersonly);
+ body.Position = 0;
+ using (var rdr = new System.IO.StreamReader(body, Encoding)) {
+ mail.Load(rdr, headersonly);
+ }
+ }
x.Add(mail);
}
View
@@ -16,7 +16,7 @@ public abstract class TextClient : IDisposable {
public System.Text.Encoding Encoding { get; set; }
public TextClient() {
- Encoding = System.Text.Encoding.UTF8;
+ Encoding = Utilities.ParseCharsetToEncoding("ISO-8859-1");
}
internal abstract void OnLogin(string username, string password);

0 comments on commit e186bd8

Please sign in to comment.