[geary/mjog/rfc822-cleanup-part-deux: 2/8] Geary.RFC822.{MessageID, MessageIdList}: Throw error parsing empty rfc822



commit f1fe8f83c5dc0b0670df6614e043db48263c5fe2
Author: Michael Gratton <mike vee net>
Date:   Tue Jun 30 11:55:47 2020 +1000

    Geary.RFC822.{MessageID,MessageIdList}: Throw error parsing empty rfc822
    
    An empty string is not a valid RFC822 message id or message id list, so
    don't treat it as such.

 src/engine/rfc822/rfc822-message-data.vala | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/rfc822/rfc822-message-data.vala b/src/engine/rfc822/rfc822-message-data.vala
index 01a854e98..91ec0f8ce 100644
--- a/src/engine/rfc822/rfc822-message-data.vala
+++ b/src/engine/rfc822/rfc822-message-data.vala
@@ -41,13 +41,16 @@ public interface Geary.RFC822.EncodedMessageData :
 public class Geary.RFC822.MessageID :
     Geary.MessageData.StringMessageData, DecodedMessageData {
 
-    private string rfc822;
+    private string rfc822 = null;
 
     public MessageID(string value) {
         base(value);
     }
 
-    public MessageID.from_rfc822_string(string rfc822) {
+    public MessageID.from_rfc822_string(string rfc822) throws Error {
+        if (String.is_empty_or_whitespace(rfc822)) {
+            throw new Error.INVALID("Empty RFC822 message id: %s", rfc822);
+        }
         base(GMime.utils_decode_message_id(rfc822));
         this.rfc822 = rfc822;
     }
@@ -96,7 +99,8 @@ public class Geary.RFC822.MessageIDList :
         list.add(msg_id);
     }
 
-    public MessageIDList.from_rfc822_string(string value) {
+    public MessageIDList.from_rfc822_string(string rfc822)
+        throws Error {
         this();
 
         // Have seen some mailers use commas between Message-IDs and whitespace inside Message-IDs,
@@ -117,7 +121,7 @@ public class Geary.RFC822.MessageIDList :
         char ch;
         bool in_message_id = false;
         bool bracketed = false;
-        while (Ascii.get_next_char(value, ref index, out ch)) {
+        while (Ascii.get_next_char(rfc822, ref index, out ch)) {
             bool add_char = false;
             switch (ch) {
                 case '<':
@@ -176,8 +180,9 @@ public class Geary.RFC822.MessageIDList :
         if (!String.is_empty(canonicalized.str))
             list.add(new MessageID(canonicalized.str));
 
-        // don't assert that list.size > 0; even though this method should generated a decoded ID
-        // from any non-empty string, an empty Message-ID (i.e. "<>") won't.
+        if (this.list.is_empty) {
+            throw new Error.INVALID("Empty RFC822 message id list: %s", rfc822);
+        }
     }
 
     /** Returns the id at the given index, if it exists. */


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