From afe779973ae059f78acf19241c1a6f2b817de295 Mon Sep 17 00:00:00 2001 From: DavidM77 Date: Sat, 25 Apr 2015 11:59:02 +0100 Subject: [PATCH] Fixes problem when moving an email between folders with gmail Problem was, in response to xm010 UID COPY 488 "ABC/XYZ" gmail returns * 1 FETCH (UID 488 FLAGS (\Seen)) before the OK status --- ImapClient.cs | 7 ++++++- Pop3Client.cs | 5 +++++ TextClient.cs | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ImapClient.cs b/ImapClient.cs index 16a00a0..d5c617e 100644 --- a/ImapClient.cs +++ b/ImapClient.cs @@ -254,7 +254,7 @@ public virtual void Copy(string messageset, string destination) { prefix = "UID "; } string command = string.Concat(GetTag(), prefix, "COPY ", messageset, " " + destination.QuoteString()); - SendCommandCheckOK(command); + SendCommandCheckOK(command, s => { } ); IdleResume(); } @@ -826,5 +826,10 @@ internal bool IsResultOK(string response) { response = response.Substring(response.IndexOf(" ")).Trim(); return response.ToUpper().StartsWith("OK"); } + + protected override bool isUntaggedResponse(string response) + { + return response.Trim().StartsWith("* "); + } } } diff --git a/Pop3Client.cs b/Pop3Client.cs index 5de8bd4..9d5881a 100644 --- a/Pop3Client.cs +++ b/Pop3Client.cs @@ -82,5 +82,10 @@ public virtual void DeleteMessage(int index) { public virtual void DeleteMessage(AE.Net.Mail.MailMessage msg) { DeleteMessage(msg.Uid); } + + protected override bool isUntaggedResponse(string response) + { + return false; + } } } \ No newline at end of file diff --git a/TextClient.cs b/TextClient.cs index 6795dd0..e4e886a 100644 --- a/TextClient.cs +++ b/TextClient.cs @@ -33,6 +33,7 @@ public TextClient() { internal abstract void OnLogin(string username, string password); internal abstract void OnLogout(); internal abstract void CheckResultOK(string result); + protected abstract bool isUntaggedResponse(string response); protected virtual void OnConnected(string result) { CheckResultOK(result); @@ -117,6 +118,23 @@ protected virtual string GetResponse(int timeout) { return _Stream.ReadLine(ref max, Encoding, null, timeout); } + protected virtual void SendCommandCheckOK(string command, Action unilateralUntaggedCallback) + { + SendCommand(command); + + while (true) + { + var response = GetResponse(); + if (isUntaggedResponse(response)) + unilateralUntaggedCallback(response); + else + { + CheckResultOK(response); + return; + } + } + } + protected virtual void SendCommandCheckOK(string command) { CheckResultOK(SendCommandGetResponse(command)); }