[geary/mjog/server-quirks: 2/4] Geary.Imap.FolderSession: Move fetch header quirk to Quirks object



commit 4839ec32dcc848a978c2d641e01017bdb526f914
Author: Michael Gratton <mike vee net>
Date:   Sat May 2 15:39:54 2020 +1000

    Geary.Imap.FolderSession: Move fetch header quirk to Quirks object

 src/engine/imap/api/imap-folder-session.vala       | 16 ++++++----------
 src/engine/imap/api/imap-quirks.vala               | 18 +++++++++++++++++-
 src/engine/imap/transport/imap-client-session.vala |  4 +++-
 3 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/src/engine/imap/api/imap-folder-session.vala b/src/engine/imap/api/imap-folder-session.vala
index c94da4bc..d1450755 100644
--- a/src/engine/imap/api/imap-folder-session.vala
+++ b/src/engine/imap/api/imap-folder-session.vala
@@ -38,13 +38,7 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
     /** Determines if this folder accepts custom IMAP flags. */
     public Trillian accepts_user_flags { get; private set; default = Trillian.UNKNOWN; }
 
-    /**
-     * Set to true when it's detected that the server doesn't allow a
-     * space between "header.fields" and the list of email headers to
-     * be requested via FETCH; see:
-     * [[https://bugzilla.gnome.org/show_bug.cgi?id=714902|Bug * 714902]]
-     */
-    public bool imap_header_fields_hack { get; private set; default = false; }
+    private Quirks quirks;
 
     private Nonblocking.Mutex cmd_mutex = new Nonblocking.Mutex();
     private Gee.HashMap<SequenceNumber, FetchedData>? fetch_accumulator = null;
@@ -93,6 +87,7 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
         throws Error {
         base(session);
         this.folder = folder;
+        this.quirks = session.quirks;
 
         if (folder.properties.attrs.is_no_select) {
             throw new ImapError.NOT_SUPPORTED(
@@ -388,7 +383,8 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
             //
             // See <https://gitlab.gnome.org/GNOME/geary/issues/571>
             if (!header_fields.is_empty) {
-                if (!this.imap_header_fields_hack || header_fields.size == 1) {
+                if (!this.quirks.fetch_header_part_no_space ||
+                    header_fields.size == 1) {
                     header_specifiers = new FetchBodyDataSpecifier[1];
                     header_specifiers[0] = new FetchBodyDataSpecifier.peek(
                         FetchBodyDataSpecifier.SectionPart.HEADER_FIELDS,
@@ -412,7 +408,7 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
                 }
 
                 foreach (FetchBodyDataSpecifier header in header_specifiers) {
-                    if (this.imap_header_fields_hack) {
+                    if (this.quirks.fetch_header_part_no_space) {
                         header.omit_request_header_fields_space();
                     }
                     cmds.add(new FetchCommand.body_data_type(msg_set, header));
@@ -1119,7 +1115,7 @@ private class Geary.Imap.FolderSession : Geary.Imap.SessionObject {
                         // property was enabled after sending command but
                         // before response returned
                         if (specifier.request_header_fields_space) {
-                            this.imap_header_fields_hack = true;
+                            this.quirks.fetch_header_part_no_space = true;
                             return true;
                         }
                     }
diff --git a/src/engine/imap/api/imap-quirks.vala b/src/engine/imap/api/imap-quirks.vala
index 2c1a70c6..79ef3267 100644
--- a/src/engine/imap/api/imap-quirks.vala
+++ b/src/engine/imap/api/imap-quirks.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019-2020 Michael Gratton <mike vee net>
+ * Copyright © 2020 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
  * (version 2.1 or later). See the COPYING file in this distribution.
@@ -11,6 +11,22 @@
 public class Geary.Imap.Quirks : BaseObject {
 
 
+    /**
+     * Whether spaces are disallowed in header parts of fetch commands.
+     *
+     * If true, HEADER parts of a BODY section may not contain any
+     * spaces.
+     *
+     * E.g. this conformant form is not supported:
+     *
+     *     a008 UID FETCH * BODY.PEEK[HEADER.FIELDS (REFERENCES)]
+     *
+     * Whereas this non-conformant form is supported:
+     *
+     *     a008 UID FETCH * BODY.PEEK[HEADER.FIELDS(REFERENCES)]
+     */
+    public bool fetch_header_part_no_space { get; set; default = false; }
+
     /** The set of additional characters allowed in an IMAP flag. */
     public string? flag_atom_exceptions { get; set; }
 
diff --git a/src/engine/imap/transport/imap-client-session.vala 
b/src/engine/imap/transport/imap-client-session.vala
index f3f30a10..68e6f06e 100644
--- a/src/engine/imap/transport/imap-client-session.vala
+++ b/src/engine/imap/transport/imap-client-session.vala
@@ -286,6 +286,9 @@ public class Geary.Imap.ClientSession : BaseObject, Logging.Source {
     /** Records the actual name and delimiter used for the inbox */
     internal MailboxInformation? inbox { get; private set; default = null; }
 
+    /** The quirks being used by this session. */
+    internal Quirks quirks { get; set; }
+
     // Locations personal mailboxes for this session
     private Gee.List<Namespace> personal_namespaces = new Gee.ArrayList<Namespace>();
 
@@ -296,7 +299,6 @@ public class Geary.Imap.ClientSession : BaseObject, Logging.Source {
     private Gee.List<Namespace> shared_namespaces = new Gee.ArrayList<Namespace>();
 
     private Endpoint imap_endpoint;
-    private Quirks quirks;
     private Geary.State.Machine fsm;
     private ClientConnection? cx = null;
 


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