From 67f0678b1d13f5192f06b03da505a1a8e4029aa7 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Tue, 1 Sep 2020 22:39:50 +1000 Subject: [PATCH] Geary.Imap: Don't cancel waiting for responses for submitted commands The IMAP protocol does not allow commands to be cancelled once sent over the wire to the server. However `IMAP.Command` objects are currently submitted to be send with a cancellable, which may be cancelled before the response is received from the server. If this happens, the repsonse to the command from the server is not waited for, and untagged data from the cancelled command may end up being handled by the subsequent command, which is bad. After submitting a command to the connection, don't supply the given cancellable to the command's wait method, so it hangs around to handle any tagged and untagged responses as required. --- src/engine/imap/transport/imap-client-session.vala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/imap/transport/imap-client-session.vala b/src/engine/imap/transport/imap-client-session.vala index 27e84837..6edbacf0 100644 --- a/src/engine/imap/transport/imap-client-session.vala +++ b/src/engine/imap/transport/imap-client-session.vala @@ -1785,7 +1785,12 @@ public class Geary.Imap.ClientSession : BaseObject, Logging.Source { throw new ImapError.NOT_CONNECTED("Not connected to %s", imap_endpoint.to_string()); this.cx.send_command(cmd); - yield cmd.wait_until_complete(cancellable); + + // Once a command has been sent over the wire, it can't be + // cancelled until a response is received, because the server + // will send a response back anyway and so the command needs + // to be around for it. + yield cmd.wait_until_complete(null); // This won't be null since the Command.wait_until_complete // will throw an error if it is.