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

This commit is contained in:
Michael Gratton 2020-05-02 15:39:54 +10:00 committed by Michael James Gratton
parent 69304f8228
commit 16b7d6528d
3 changed files with 26 additions and 12 deletions

View file

@ -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;
}
}

View file

@ -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; }

View file

@ -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;