Skip to content

Commit

Permalink
Potential fix for #54; ensures the Encoding property of the ImapCli…
Browse files Browse the repository at this point in the history
…ent is used, and default the charset to `ISO-8859-1`.
  • Loading branch information
andyedinborough committed Apr 8, 2012
1 parent bce8c78 commit e186bd8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,24 @@ public MailMessage[] GetMessages(string start, string end, bool uid, bool header
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);
}
Expand Down
2 changes: 1 addition & 1 deletion TextClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e186bd8

Please sign in to comment.