[geary] engine: Fix flag being mistaken for a response code



commit efca9615a688f437615f84f7a8f106a1f67d0f38
Author: Richard Adenling <dreeze gmail com>
Date:   Sun May 8 15:15:42 2022 +0200

    engine: Fix flag being mistaken for a response code
    
    The parser would think the flag was a response code if the flag started
    with a '[' character. Flags like these are sometimes returned by Gmail
    which broke fetching emails from Gmail.
    
    This commit checks if the parser is already parsing flags and if so
    treats any starting '[' characters as part of the flag string.

 src/engine/imap/transport/imap-deserializer.vala       | 6 ++++++
 test/engine/imap/transport/imap-deserializer-test.vala | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/imap/transport/imap-deserializer.vala 
b/src/engine/imap/transport/imap-deserializer.vala
index 559a5e784..90c83549d 100644
--- a/src/engine/imap/transport/imap-deserializer.vala
+++ b/src/engine/imap/transport/imap-deserializer.vala
@@ -562,6 +562,12 @@ public class Geary.Imap.Deserializer : BaseObject, Logging.Source {
         char ch = *((char *) user);
         switch (ch) {
             case '[':
+                // "[" is a valid character for flags (and used by Gmail)
+                if (this.is_parsing_flags) {
+                    append_to_string(ch);
+                    return State.FLAG;
+                }
+
                 // open response code
                 ResponseCode response_code = new ResponseCode();
                 push(response_code);
diff --git a/test/engine/imap/transport/imap-deserializer-test.vala 
b/test/engine/imap/transport/imap-deserializer-test.vala
index e5e642dfe..b4f623053 100644
--- a/test/engine/imap/transport/imap-deserializer-test.vala
+++ b/test/engine/imap/transport/imap-deserializer-test.vala
@@ -273,7 +273,7 @@ class Geary.Imap.DeserializerTest : TestCase {
     public void gmail_broken_flags() throws GLib.Error {
         // As of 2020-05-01, GMail does not correctly quote email
         // flags. See #746
-        string flags = """* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Forwarded $MDNSent $NotPhishing 
$Phishing Junk LoadRemoteImages NonJunk OIB-Seen-INBOX OIB-Seen-Unsubscribe OIB-Seen-[Gmail]/Important 
OIB-Seen-[Gmail]/Spam OIB-Seen-[Gmail]/Tous les messages)""";
+        string flags = """* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Forwarded $MDNSent $NotPhishing 
$Phishing Junk LoadRemoteImages NonJunk OIB-Seen-INBOX OIB-Seen-Unsubscribe [GMail]/Sent_Mail 
OIB-Seen-[Gmail]/Important OIB-Seen-[Gmail]/Spam OIB-Seen-[Gmail]/Tous les messages)""";
         this.stream.add_data(flags.data);
         this.stream.add_data(EOL.data);
         this.deser.quirks = new Imap.Quirks();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]