[geary/mjog/mail-merge-plugin: 7/12] Geary.EmailHeaderSet: Seal setting properties off from sub-classes



commit fa204af36bf267d3d92bc02f9f2a32c51d3d4aea
Author: Michael Gratton <mike vee net>
Date:   Thu May 7 17:20:12 2020 +1000

    Geary.EmailHeaderSet: Seal setting properties off from sub-classes
    
    Remove setters for all properties, so plugins can't create sub-classes
    of instances and set these values. Fix implementations.

 src/engine/api/geary-composed-email.vala   | 55 +++++++++++-------
 src/engine/api/geary-email-header-set.vala | 26 ++++-----
 src/engine/api/geary-email.vala            | 92 +++++++++++++++++-------------
 src/engine/rfc822/rfc822-message.vala      | 81 ++++++++++++++------------
 4 files changed, 144 insertions(+), 110 deletions(-)
---
diff --git a/src/engine/api/geary-composed-email.vala b/src/engine/api/geary-composed-email.vala
index a1409cba..96c7aa24 100644
--- a/src/engine/api/geary-composed-email.vala
+++ b/src/engine/api/geary-composed-email.vala
@@ -22,37 +22,48 @@ public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
     );
 
     /** {@inheritDoc} */
-    public RFC822.Date? date { get; protected set; }
+    public RFC822.MailboxAddresses? from { get { return this._from; } }
+    private RFC822.MailboxAddresses? _from  = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? from { get; protected set; }
+    public RFC822.MailboxAddress? sender { get { return this._sender; } }
+    private RFC822.MailboxAddress? _sender = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddress? sender { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? reply_to { get { return this._reply_to; } }
+    private RFC822.MailboxAddresses? _reply_to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? to { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? to { get { return this._to; } }
+    private RFC822.MailboxAddresses? _to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? cc { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? cc { get { return this._cc; } }
+    private RFC822.MailboxAddresses? _cc = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? bcc { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? bcc { get { return this._bcc; } }
+    private RFC822.MailboxAddresses? _bcc = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? reply_to { get; protected set; default = null; }
+    public RFC822.MessageID? message_id { get { return this._message_id; } }
+    private RFC822.MessageID? _message_id = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageID? message_id { get; protected set; default = null; }
+    public RFC822.MessageIDList? in_reply_to { get { return this._in_reply_to; } }
+    private RFC822.MessageIDList? _in_reply_to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageIDList? in_reply_to { get; protected set; default = null; }
+    public RFC822.MessageIDList? references { get { return this._references; } }
+    private RFC822.MessageIDList? _references = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageIDList? references { get; protected set; default = null; }
+    public RFC822.Subject? subject { get { return this._subject; } }
+    private RFC822.Subject? _subject = null;
 
     /** {@inheritDoc} */
-    public RFC822.Subject? subject { get; protected set; default = null; }
+    public RFC822.Date? date { get { return this._date; } }
+    private RFC822.Date? _date = null;
 
     public string? body_text { get; set; default = null; }
     public string? body_html { get; set; default = null; }
@@ -70,52 +81,52 @@ public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
     public string img_src_prefix { get; set; default = ""; }
 
     public ComposedEmail(DateTime date, RFC822.MailboxAddresses from) {
-        this.date = new RFC822.Date(date);
-        this.from = from;
+        this._date = new RFC822.Date(date);
+        this._from = from;
     }
 
     public ComposedEmail set_sender(RFC822.MailboxAddress? sender) {
-        this.sender = sender;
+        this._sender = sender;
         return this;
     }
 
     public ComposedEmail set_to(RFC822.MailboxAddresses? recipients) {
-        this.to = empty_to_null(recipients);
+        this._to = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_cc(RFC822.MailboxAddresses? recipients) {
-        this.cc = empty_to_null(recipients);
+        this._cc = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_bcc(RFC822.MailboxAddresses? recipients) {
-        this.bcc = empty_to_null(recipients);
+        this._bcc = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_reply_to(RFC822.MailboxAddresses? recipients) {
-        this.reply_to = empty_to_null(recipients);
+        this._reply_to = empty_to_null(recipients);
         return this;
     }
 
     public ComposedEmail set_message_id(RFC822.MessageID? id) {
-        this.message_id = id;
+        this._message_id = id;
         return this;
     }
 
     public ComposedEmail set_in_reply_to(RFC822.MessageIDList? messages) {
-        this.in_reply_to = empty_to_null(messages);
+        this._in_reply_to = empty_to_null(messages);
         return this;
     }
 
     public ComposedEmail set_references(RFC822.MessageIDList? messages) {
-        this.references = empty_to_null(messages);
+        this._references = empty_to_null(messages);
         return this;
     }
 
     public ComposedEmail set_subject(string? subject) {
-        this.subject = (
+        this._subject = (
             String.is_empty_or_whitespace(subject)
             ? null
             : new RFC822.Subject(subject)
diff --git a/src/engine/api/geary-email-header-set.vala b/src/engine/api/geary-email-header-set.vala
index bb8f62ae..7e1b0489 100644
--- a/src/engine/api/geary-email-header-set.vala
+++ b/src/engine/api/geary-email-header-set.vala
@@ -10,37 +10,37 @@
  */
 public interface Geary.EmailHeaderSet : BaseObject {
 
-    /** Value of the RFC 822 Date header. */
-    public abstract RFC822.Date? date { get; protected set; }
-
     /** Value of the RFC 822 From header, an originator field. */
-    public abstract RFC822.MailboxAddresses? from { get; protected set; }
+    public abstract RFC822.MailboxAddresses? from { get; }
 
     /** Value of the RFC 822 Sender header, an originator field. */
-    public abstract RFC822.MailboxAddress? sender { get; protected set; }
+    public abstract RFC822.MailboxAddress? sender { get; }
 
     /** Value of the RFC 822 Reply-To header, an originator field. */
-    public abstract RFC822.MailboxAddresses? reply_to { get; protected set; }
+    public abstract RFC822.MailboxAddresses? reply_to { get; }
 
     /** Value of the RFC 822 To header, a recipient field. */
-    public abstract RFC822.MailboxAddresses? to { get; protected set; }
+    public abstract RFC822.MailboxAddresses? to { get; }
 
     /** Value of the RFC 822 Cc header, a recipient field. */
-    public abstract RFC822.MailboxAddresses? cc { get; protected set; }
+    public abstract RFC822.MailboxAddresses? cc { get; }
 
     /** Value of the RFC 822 Bcc header, a recipient field. */
-    public abstract RFC822.MailboxAddresses? bcc { get; protected set; }
+    public abstract RFC822.MailboxAddresses? bcc { get; }
 
     /** Value of the RFC 822 Message-Id header, a reference field. */
-    public abstract RFC822.MessageID? message_id { get; protected set; }
+    public abstract RFC822.MessageID? message_id { get; }
 
     /** Value of the RFC 822 In-Reply-To header, a reference field. */
-    public abstract RFC822.MessageIDList? in_reply_to { get; protected set; }
+    public abstract RFC822.MessageIDList? in_reply_to { get; }
 
     /** Value of the RFC 822 References header, a reference field. */
-    public abstract RFC822.MessageIDList? references { get; protected set; }
+    public abstract RFC822.MessageIDList? references { get; }
 
     /** Value of the RFC 822 Subject header. */
-    public abstract RFC822.Subject? subject { get; protected set; }
+    public abstract RFC822.Subject? subject { get; }
+
+    /** Value of the RFC 822 Date header. */
+    public abstract RFC822.Date? date { get; }
 
 }
diff --git a/src/engine/api/geary-email.vala b/src/engine/api/geary-email.vala
index d6a0fe6d..1eb67ffc 100644
--- a/src/engine/api/geary-email.vala
+++ b/src/engine/api/geary-email.vala
@@ -193,79 +193,90 @@ public class Geary.Email : BaseObject, EmailHeaderSet {
     /**
      * {@inheritDoc}
      *
-     * Value will be valid if {@link Field.DATE} is set.
+     * Value will be valid if {@link Field.ORIGINATORS} is set.
      */
-    public Geary.RFC822.Date? date { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? from { get { return this._from; } }
+    private RFC822.MailboxAddresses? _from  = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.ORIGINATORS} is set.
      */
-    public Geary.RFC822.MailboxAddresses? from { get; protected set; default = null; }
+    public RFC822.MailboxAddress? sender { get { return this._sender; } }
+    private RFC822.MailboxAddress? _sender = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.ORIGINATORS} is set.
      */
-    public Geary.RFC822.MailboxAddress? sender { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? reply_to { get { return this._reply_to; } }
+    private RFC822.MailboxAddresses? _reply_to = null;
 
     /**
      * {@inheritDoc}
      *
-     * Value will be valid if {@link Field.ORIGINATORS} is set.
+     * Value will be valid if {@link Field.RECEIVERS} is set.
      */
-    public Geary.RFC822.MailboxAddresses? reply_to { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? to { get { return this._to; } }
+    private RFC822.MailboxAddresses? _to = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.RECEIVERS} is set.
      */
-    public Geary.RFC822.MailboxAddresses? to { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? cc { get { return this._cc; } }
+    private RFC822.MailboxAddresses? _cc = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.RECEIVERS} is set.
      */
-    public Geary.RFC822.MailboxAddresses? cc { get; protected set; default = null; }
+    public RFC822.MailboxAddresses? bcc { get { return this._bcc; } }
+    private RFC822.MailboxAddresses? _bcc = null;
 
     /**
      * {@inheritDoc}
      *
-     * Value will be valid if {@link Field.RECEIVERS} is set.
+     * Value will be valid if {@link Field.REFERENCES} is set.
      */
-    public Geary.RFC822.MailboxAddresses? bcc { get; protected set; default = null; }
+    public RFC822.MessageID? message_id { get { return this._message_id; } }
+    private RFC822.MessageID? _message_id = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.REFERENCES} is set.
      */
-    public Geary.RFC822.MessageID? message_id { get; protected set; default = null; }
+    public RFC822.MessageIDList? in_reply_to { get { return this._in_reply_to; } }
+    private RFC822.MessageIDList? _in_reply_to = null;
 
     /**
      * {@inheritDoc}
      *
      * Value will be valid if {@link Field.REFERENCES} is set.
      */
-    public Geary.RFC822.MessageIDList? in_reply_to { get; protected set; default = null; }
+    public RFC822.MessageIDList? references { get { return this._references; } }
+    private RFC822.MessageIDList? _references = null;
 
     /**
      * {@inheritDoc}
      *
-     * Value will be valid if {@link Field.REFERENCES} is set.
+     * Value will be valid if {@link Field.SUBJECT} is set.
      */
-    public Geary.RFC822.MessageIDList? references { get; protected set; default = null; }
+    public RFC822.Subject? subject { get { return this._subject; } }
+    private RFC822.Subject? _subject = null;
 
     /**
      * {@inheritDoc}
      *
-     * Value will be valid if {@link Field.SUBJECT} is set.
+     * Value will be valid if {@link Field.DATE} is set.
      */
-    public Geary.RFC822.Subject? subject { get; protected set; default = null; }
+    public RFC822.Date? date { get { return this._date; } }
+    private RFC822.Date? _date = null;
 
     /**
      * {@inheritDoc}
@@ -365,10 +376,9 @@ public class Geary.Email : BaseObject, EmailHeaderSet {
         return email_flags != null ? Trillian.from_boolean(email_flags.load_remote_images()) : 
Trillian.UNKNOWN;
     }
 
-    public void set_send_date(Geary.RFC822.Date? date) {
-        this.date = date;
-
-        fields |= Field.DATE;
+    public void set_send_date(RFC822.Date? date) {
+        this._date = date;
+        this.fields |= Field.DATE;
     }
 
     /**
@@ -378,41 +388,43 @@ public class Geary.Email : BaseObject, EmailHeaderSet {
      * and From not be identical, and that both From and ReplyTo are
      * optional.
      */
-    public void set_originators(Geary.RFC822.MailboxAddresses? from,
-                                Geary.RFC822.MailboxAddress? sender,
-                                Geary.RFC822.MailboxAddresses? reply_to)
+    public void set_originators(RFC822.MailboxAddresses? from,
+                                RFC822.MailboxAddress? sender,
+                                RFC822.MailboxAddresses? reply_to)
         throws Error {
         // XXX Should be throwing an error here if from is empty or
         // sender is same as from
-        this.from = from;
-        this.sender = sender;
-        this.reply_to = reply_to;
+        this._from = from;
+        this._sender = sender;
+        this._reply_to = reply_to;
 
-        fields |= Field.ORIGINATORS;
+        this.fields |= Field.ORIGINATORS;
     }
 
-    public void set_receivers(Geary.RFC822.MailboxAddresses? to,
-        Geary.RFC822.MailboxAddresses? cc, Geary.RFC822.MailboxAddresses? bcc) {
-        this.to = to;
-        this.cc = cc;
-        this.bcc = bcc;
+    public void set_receivers(RFC822.MailboxAddresses? to,
+                              RFC822.MailboxAddresses? cc,
+                              RFC822.MailboxAddresses? bcc) {
+        this._to = to;
+        this._cc = cc;
+        this._bcc = bcc;
 
-        fields |= Field.RECEIVERS;
+        this.fields |= Field.RECEIVERS;
     }
 
-    public void set_full_references(Geary.RFC822.MessageID? message_id, Geary.RFC822.MessageIDList? 
in_reply_to,
+    public void set_full_references(RFC822.MessageID? message_id,
+                                    RFC822.MessageIDList? in_reply_to,
         Geary.RFC822.MessageIDList? references) {
-        this.message_id = message_id;
-        this.in_reply_to = in_reply_to;
-        this.references = references;
+        this._message_id = message_id;
+        this._in_reply_to = in_reply_to;
+        this._references = references;
 
-        fields |= Field.REFERENCES;
+        this.fields |= Field.REFERENCES;
     }
 
     public void set_message_subject(Geary.RFC822.Subject? subject) {
-        this.subject = subject;
+        this._subject = subject;
 
-        fields |= Field.SUBJECT;
+        this.fields |= Field.SUBJECT;
     }
 
     public void set_message_header(Geary.RFC822.Header header) {
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 1c780e06..fcbdbcfc 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -65,37 +65,48 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
     // set in Message.from_gmime_message(), below.
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? from { get; protected set; default = null; }
+    public MailboxAddresses? from { get { return this._from; } }
+    private MailboxAddresses? _from  = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddress? sender { get; protected set; default = null; }
+    public MailboxAddress? sender { get { return this._sender; } }
+    private MailboxAddress? _sender = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? to { get; protected set; default = null; }
+    public MailboxAddresses? reply_to { get { return this._reply_to; } }
+    private MailboxAddresses? _reply_to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? cc { get; protected set; default = null; }
+    public MailboxAddresses? to { get { return this._to; } }
+    private MailboxAddresses? _to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? bcc { get; protected set; default = null; }
+    public MailboxAddresses? cc { get { return this._cc; } }
+    private MailboxAddresses? _cc = null;
 
     /** {@inheritDoc} */
-    public RFC822.MailboxAddresses? reply_to { get; protected set; default = null; }
+    public MailboxAddresses? bcc { get { return this._bcc; } }
+    private MailboxAddresses? _bcc = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageID? message_id { get; protected set; default = null; }
+    public MessageID? message_id { get { return this._message_id; } }
+    private MessageID? _message_id = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageIDList? in_reply_to { get; protected set; default = null; }
+    public MessageIDList? in_reply_to { get { return this._in_reply_to; } }
+    private MessageIDList? _in_reply_to = null;
 
     /** {@inheritDoc} */
-    public RFC822.MessageIDList? references { get; protected set; default = null; }
+    public MessageIDList? references { get { return this._references; } }
+    private MessageIDList? _references = null;
 
     /** {@inheritDoc} */
-    public RFC822.Subject? subject { get; protected set; default = null; }
+    public Subject? subject { get { return this._subject; } }
+    private Subject? _subject = null;
 
     /** {@inheritDoc} */
-    public Geary.RFC822.Date? date { get; protected set; default = null; }
+    public Date? date { get { return this._date; } }
+    private Date? _date = null;
 
     /** Value of the X-Mailer header. */
     public string? mailer { get; protected set; default = null; }
@@ -130,33 +141,33 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
         throws Error {
         this.message = message;
 
-        this.from = to_addresses(message.get_from());
-        this.to = to_addresses(message.get_to());
-        this.cc = to_addresses(message.get_cc());
-        this.bcc = to_addresses(message.get_bcc());
-        this.reply_to = to_addresses(message.get_reply_to());
+        this._from = to_addresses(message.get_from());
+        this._to = to_addresses(message.get_to());
+        this._cc = to_addresses(message.get_cc());
+        this._bcc = to_addresses(message.get_bcc());
+        this._reply_to = to_addresses(message.get_reply_to());
 
         var sender = (
             message.get_sender().get_address(0) as GMime.InternetAddressMailbox
         );
         if (sender != null) {
-            this.sender = new MailboxAddress.from_gmime(sender);
+            this._sender = new MailboxAddress.from_gmime(sender);
         }
 
         var subject = message.get_subject();
         if (subject != null) {
-            this.subject = new Subject(subject);
+            this._subject = new Subject(subject);
         }
 
         // Use a pointer here to work around GNOME/vala#986
         GLib.DateTime* date = message.get_date();
         if (date != null) {
-            this.date = new Date(date);
+            this._date = new Date(date);
         }
 
         var message_id = message.get_message_id();
         if (message_id != null) {
-            this.message_id = new MessageID(message_id);
+            this._message_id = new MessageID(message_id);
         }
 
         // Since these headers may be specified multiple times, we
@@ -166,14 +177,14 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
             var header = headers.get_header_at(i);
             switch (header.get_name().down()) {
             case "in-reply-to":
-                this.in_reply_to = append_message_id(
-                    this.in_reply_to, header.get_raw_value()
+                this._in_reply_to = append_message_id(
+                    this._in_reply_to, header.get_raw_value()
                 );
                 break;
 
             case "references":
-                this.references = append_message_id(
-                    this.references, header.get_raw_value()
+                this._references = append_message_id(
+                    this._references, header.get_raw_value()
                 );
                 break;
 
@@ -218,52 +229,52 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
         //
         // Required headers
 
-        this.from = email.from;
+        this._from = email.from;
         foreach (RFC822.MailboxAddress mailbox in email.from) {
             this.message.add_mailbox(FROM, mailbox.name, mailbox.address);
         }
 
-        this.date = email.date;
+        this._date = email.date;
         this.message.set_date(this.date.value);
 
         // Optional headers
 
         if (email.to != null) {
-            this.to = email.to;
+            this._to = email.to;
             foreach (RFC822.MailboxAddress mailbox in email.to)
                 this.message.add_mailbox(TO, mailbox.name, mailbox.address);
         }
 
         if (email.cc != null) {
-            this.cc = email.cc;
+            this._cc = email.cc;
             foreach (RFC822.MailboxAddress mailbox in email.cc)
                 this.message.add_mailbox(CC, mailbox.name, mailbox.address);
         }
 
         if (email.bcc != null) {
-            this.bcc = email.bcc;
+            this._bcc = email.bcc;
             foreach (RFC822.MailboxAddress mailbox in email.bcc)
                 this.message.add_mailbox(BCC, mailbox.name, mailbox.address);
         }
 
         if (email.sender != null) {
-            this.sender = email.sender;
+            this._sender = email.sender;
             this.message.add_mailbox(SENDER, this.sender.name, this.sender.address);
         }
 
         if (email.reply_to != null) {
-            this.reply_to = email.reply_to;
+            this._reply_to = email.reply_to;
             foreach (RFC822.MailboxAddress mailbox in email.reply_to)
                 this.message.add_mailbox(REPLY_TO, mailbox.name, mailbox.address);
         }
 
         if (message_id != null) {
-            this.message_id = new MessageID(message_id);
+            this._message_id = new MessageID(message_id);
             this.message.set_message_id(message_id);
         }
 
         if (email.in_reply_to != null) {
-            this.in_reply_to = email.in_reply_to;
+            this._in_reply_to = email.in_reply_to;
             // We could use `this.message.add_mailbox()` in a similar way like
             // we did for the other headers, but this would require to change
             // the type of `email.in_reply_to` and `this.in_reply_to` from
@@ -274,14 +285,14 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
         }
 
         if (email.references != null) {
-            this.references = email.references;
+            this._references = email.references;
             this.message.set_header(HEADER_REFERENCES,
                                     email.references.to_rfc822_string(),
                                     Geary.RFC822.get_charset());
         }
 
         if (email.subject != null) {
-            this.subject = email.subject;
+            this._subject = email.subject;
             this.message.set_subject(email.subject.value,
                                      Geary.RFC822.get_charset());
         }


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