Skip to content

Commit

Permalink
better support for AppendMail #44. There is still much work left to d…
Browse files Browse the repository at this point in the history
…o. The `MailMessage.Save(...)` method doesn't yet support extended characters or attachments.
  • Loading branch information
andyedinborough committed Mar 13, 2012
1 parent 50e33cd commit 360cae0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,26 @@ protected override void OnDispose() {
}
}

public void AppendMail(string mailbox, MailMessage email) {
public void AppendMail(MailMessage email, string mailbox = null) {
IdlePause();

string flags = String.Empty;
string size = (email.Body.Length - 1).ToString();
var body = new StringBuilder();
using (var txt = new System.IO.StringWriter(body))
email.Save(txt);

string size = body.Length.ToString();
if (email.RawFlags.Length > 0) {
flags = string.Concat("(", string.Join(" ", email.Flags), ")");
flags = " (" + string.Join(" ", email.Flags) + ")";
}
string command = GetTag() + "APPEND " + mailbox.QuoteString() + " " + flags + " {" + size + "}";

if (mailbox == null) CheckMailboxSelected();
mailbox = mailbox ?? _SelectedMailbox;

string command = GetTag() + "APPEND " + (mailbox ?? _SelectedMailbox).QuoteString() + flags + " {" + size + "}";
string response = SendCommandGetResponse(command);
if (response.StartsWith("+")) {
response = SendCommandGetResponse(email.Body);
response = SendCommandGetResponse(body.ToString());
}
IdleResume();
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ public void TestIssue49() {
}
}

[TestMethod]
public void TestAppendMail() {
using (var client = GetClient<ImapClient>()) {
var msg = new MailMessage {
Subject = "TEST",
Body = "Appended!"
};
msg.Date = DateTime.Now;

client.AppendMail("Inbox", msg);
}
}

[TestMethod]
public void TestParseImapHeader() {
var header = @"X-GM-THRID 1320777376118077475 X-GM-MSGID 1320777376118077475 X-GM-LABELS () UID 8286 RFC822.SIZE 9369 FLAGS (\Seen) BODY[] {9369}";
Expand Down

0 comments on commit 360cae0

Please sign in to comment.