[geary/mjog/misc-fixes: 27/27] Sanitise Geary.ComposedEmail setter method inputs



commit 7d51a5183e41f015428fb9cfd60e47f1ff1542e6
Author: Michael Gratton <mike vee net>
Date:   Tue Jan 28 09:17:48 2020 +1100

    Sanitise Geary.ComposedEmail setter method inputs
    
    Ensure that if any empty mailbox or message id lists are passed to a
    setter that they are set as null instead, to conform to the
    EmailHeaderSet contract.

 src/engine/api/geary-composed-email.vala | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/api/geary-composed-email.vala b/src/engine/api/geary-composed-email.vala
index af58af9b..72f30ba8 100644
--- a/src/engine/api/geary-composed-email.vala
+++ b/src/engine/api/geary-composed-email.vala
@@ -80,22 +80,22 @@ public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
     }
 
     public ComposedEmail set_to(RFC822.MailboxAddresses? recipients) {
-        this.to = recipients;
+        this.to = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_cc(RFC822.MailboxAddresses? recipients) {
-        this.cc = recipients;
+        this.cc = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_bcc(RFC822.MailboxAddresses? recipients) {
-        this.bcc = recipients;
+        this.bcc = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_reply_to(RFC822.MailboxAddresses? recipients) {
-        this.reply_to = recipients;
+        this.reply_to = empty_to_null(recipients);
         return this;
     }
 
@@ -105,12 +105,12 @@ public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
     }
 
     public ComposedEmail set_in_reply_to(RFC822.MessageIDList? messages) {
-        this.in_reply_to = messages;
+        this.in_reply_to = empty_to_null(messages);
         return this;
     }
 
     public ComposedEmail set_references(RFC822.MessageIDList? messages) {
-        this.references = messages;
+        this.references = empty_to_null(messages);
         return this;
     }
 
@@ -165,4 +165,18 @@ public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
         return index != -1;
     }
 
+    private T empty_to_null<T>(T list) {
+        T ret = list;
+        RFC822.MailboxAddresses? addresses = list as RFC822.MailboxAddresses;
+        if (addresses != null && addresses.size == 0) {
+            ret = null;
+        } else {
+            RFC822.MessageIDList? ids = list as RFC822.MessageIDList;
+            if (ids != null && ids.list.size == 0) {
+                ret = null;
+            }
+        }
+        return ret;
+    }
+
 }


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