[geary/wip/543-append-failure] Clean up Imap.LiteralCommand API



commit f16f518137ba6bfafa06eabe002469a7e5ff3137
Author: Michael Gratton <mike vee net>
Date:   Thu Aug 29 22:57:16 2019 +1000

    Clean up Imap.LiteralCommand API
    
    Expose value buffer as a RO property, remove redundant method calls,
    fix call sites.

 .../imap/command/imap-authenticate-command.vala    |  4 +-
 src/engine/imap/command/imap-command.vala          |  2 +-
 src/engine/imap/parameter/imap-list-parameter.vala |  6 +--
 .../imap/parameter/imap-literal-parameter.vala     | 47 +++++++---------------
 .../imap/response/imap-fetch-data-decoder.vala     |  9 ++---
 5 files changed, 26 insertions(+), 42 deletions(-)
---
diff --git a/src/engine/imap/command/imap-authenticate-command.vala 
b/src/engine/imap/command/imap-authenticate-command.vala
index acf49f3d..c3dfa694 100644
--- a/src/engine/imap/command/imap-authenticate-command.vala
+++ b/src/engine/imap/command/imap-authenticate-command.vala
@@ -64,7 +64,9 @@ public class Geary.Imap.AuthenticateCommand : Command {
         // Wait to either get a response or a continuation request
         yield this.error_lock.wait_async(cancellable);
         if (this.response_literal != null) {
-            yield this.response_literal.serialize_data(ser, cancellable);
+            yield ser.push_literal_data(
+                this.response_literal.value, cancellable
+            );
             ser.push_eol(cancellable);
             yield ser.flush_stream(cancellable);
         }
diff --git a/src/engine/imap/command/imap-command.vala b/src/engine/imap/command/imap-command.vala
index 318772fc..2bebba1e 100644
--- a/src/engine/imap/command/imap-command.vala
+++ b/src/engine/imap/command/imap-command.vala
@@ -181,7 +181,7 @@ public class Geary.Imap.Command : BaseObject {
                     debug("Waiting for continuation");
                     yield this.literal_spinlock.wait_async(cancellable);
                     debug("Got continuation");
-                    yield literal.serialize_data(ser, cancellable);
+                    yield ser.push_literal_data(literal.value, cancellable);
                 }
             }
         }
diff --git a/src/engine/imap/parameter/imap-list-parameter.vala 
b/src/engine/imap/parameter/imap-list-parameter.vala
index 4a6b4859..d580830a 100644
--- a/src/engine/imap/parameter/imap-list-parameter.vala
+++ b/src/engine/imap/parameter/imap-list-parameter.vala
@@ -217,7 +217,7 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
             return stringp;
 
         LiteralParameter? literalp = param as LiteralParameter;
-        if (literalp != null && literalp.get_size() <= MAX_STRING_LITERAL_LENGTH)
+        if (literalp != null && literalp.value.size <= MAX_STRING_LITERAL_LENGTH)
             return literalp.coerce_to_string_parameter();
 
         throw new ImapError.TYPE_ERROR("Parameter %d not of type string or literal (is %s)", index,
@@ -246,7 +246,7 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
             return stringp;
 
         LiteralParameter? literalp = param as LiteralParameter;
-        if (literalp != null && literalp.get_size() <= MAX_STRING_LITERAL_LENGTH)
+        if (literalp != null && literalp.value.size <= MAX_STRING_LITERAL_LENGTH)
             return literalp.coerce_to_string_parameter();
 
         throw new ImapError.TYPE_ERROR("Parameter %d not of type string or literal (is %s)", index,
@@ -390,7 +390,7 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
     public Memory.Buffer? get_as_nullable_buffer(int index) throws ImapError {
         LiteralParameter? literalp = get_if_literal(index);
         if (literalp != null)
-            return literalp.get_buffer();
+            return literalp.value;
 
         StringParameter? stringp = get_if_string(index);
         if (stringp != null)
diff --git a/src/engine/imap/parameter/imap-literal-parameter.vala 
b/src/engine/imap/parameter/imap-literal-parameter.vala
index a3b1055f..379ed7d7 100644
--- a/src/engine/imap/parameter/imap-literal-parameter.vala
+++ b/src/engine/imap/parameter/imap-literal-parameter.vala
@@ -1,38 +1,30 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
+/*
+ * Copyright 2016 Software Freedom Conservancy Inc.
+ * Copyright 2019 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.
+ * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
 /**
  * A representation of an IMAP literal parameter.
  *
- * Because a literal parameter can hold 8-bit data, this is not a descendent of
- * {@link StringParameter}, although some times literal data is used to store 8-bit text (for
- * example, UTF-8).
+ * Because a literal parameter can hold 8-bit data, this is not a
+ * descendent of {@link StringParameter}, although some times literal
+ * data is used to store 8-bit text (for example, UTF-8).
  *
  * See [[http://tools.ietf.org/html/rfc3501#section-4.3]]
  */
 
 public class Geary.Imap.LiteralParameter : Geary.Imap.Parameter {
-    private Memory.Buffer buffer;
 
-    public LiteralParameter(Memory.Buffer buffer) {
-        this.buffer = buffer;
-    }
 
-    /**
-     * Returns the number of bytes in the literal parameter's buffer.
-     */
-    public size_t get_size() {
-        return buffer.size;
-    }
+    /** The value of the literal parameter. */
+    public Memory.Buffer value { get; private set; }
 
-    /**
-     * Returns the literal paremeter's buffer.
-     */
-    public Memory.Buffer get_buffer() {
-        return buffer;
+
+    public LiteralParameter(Memory.Buffer value) {
+        this.value = value;
     }
 
     /**
@@ -45,14 +37,14 @@ public class Geary.Imap.LiteralParameter : Geary.Imap.Parameter {
      * for transmitting on the wire.
      */
     public StringParameter coerce_to_string_parameter() {
-        return new UnquotedStringParameter(buffer.get_valid_utf8());
+        return new UnquotedStringParameter(this.value.get_valid_utf8());
     }
 
     /**
      * {@inheritDoc}
      */
     public override string to_string() {
-        return "{literal/%lub}".printf(get_size());
+        return "{literal/%lub}".printf(this.value.size);
     }
 
     /**
@@ -60,17 +52,8 @@ public class Geary.Imap.LiteralParameter : Geary.Imap.Parameter {
      */
     public override void serialize(Serializer ser, GLib.Cancellable cancellable)
         throws GLib.Error {
-        ser.push_unquoted_string("{%lu}".printf(get_size()), cancellable);
+        ser.push_unquoted_string("{%lu}".printf(this.value.size), cancellable);
         ser.push_eol(cancellable);
     }
 
-    /**
-     * Serialises the literal parameter data.
-     */
-    public async void serialize_data(Serializer ser,
-                                     GLib.Cancellable cancellable)
-        throws GLib.Error {
-        yield ser.push_literal_data(buffer, cancellable);
-    }
-
 }
diff --git a/src/engine/imap/response/imap-fetch-data-decoder.vala 
b/src/engine/imap/response/imap-fetch-data-decoder.vala
index 429f4979..8f9f42b9 100644
--- a/src/engine/imap/response/imap-fetch-data-decoder.vala
+++ b/src/engine/imap/response/imap-fetch-data-decoder.vala
@@ -42,7 +42,7 @@ public abstract class Geary.Imap.FetchDataDecoder : BaseObject {
             // because this method is called without the help of get_as_string() (which converts
             // reasonably-length literals into StringParameters), do so here manually
             try {
-                if (literalp.get_size() <= ListParameter.MAX_STRING_LITERAL_LENGTH)
+                if (literalp.value.size <= ListParameter.MAX_STRING_LITERAL_LENGTH)
                     return decode_string(literalp.coerce_to_string_parameter());
             } catch (ImapError imap_err) {
                 // if decode_string() throws a TYPE_ERROR, retry as a LiteralParameter, otherwise
@@ -197,7 +197,7 @@ public class Geary.Imap.RFC822HeaderDecoder : Geary.Imap.FetchDataDecoder {
     }
 
     protected override MessageData decode_literal(LiteralParameter literalp) throws ImapError {
-        return new Geary.Imap.RFC822Header(literalp.get_buffer());
+        return new Geary.Imap.RFC822Header(literalp.value);
     }
 }
 
@@ -207,7 +207,7 @@ public class Geary.Imap.RFC822TextDecoder : Geary.Imap.FetchDataDecoder {
     }
 
     protected override MessageData decode_literal(LiteralParameter literalp) throws ImapError {
-        return new Geary.Imap.RFC822Text(literalp.get_buffer());
+        return new Geary.Imap.RFC822Text(literalp.value);
     }
 
     protected override MessageData decode_nil(NilParameter nilp) throws ImapError {
@@ -221,7 +221,6 @@ public class Geary.Imap.RFC822FullDecoder : Geary.Imap.FetchDataDecoder {
     }
 
     protected override MessageData decode_literal(LiteralParameter literalp) throws ImapError {
-        return new Geary.Imap.RFC822Full(literalp.get_buffer());
+        return new Geary.Imap.RFC822Full(literalp.value);
     }
 }
-


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