[geary/mjog/493-undo-send: 4/20] Make Geary.ComposedEmail implement Geary.EmailHeaderSet
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/493-undo-send: 4/20] Make Geary.ComposedEmail implement Geary.EmailHeaderSet
- Date: Tue, 12 Nov 2019 21:42:11 +0000 (UTC)
commit 4f39d63e8b94876b744536d7e670c6fa592f21fb
Author: Michael Gratton <mike vee net>
Date: Fri Nov 8 10:23:24 2019 +1100
Make Geary.ComposedEmail implement Geary.EmailHeaderSet
This allows it to be used in exchange with the Geary.Email and
RFC822.Message classes in places.
src/client/composer/composer-widget.vala | 34 +++++----
src/engine/api/geary-composed-email.vala | 118 ++++++++++++++++++++++-------
src/engine/api/geary-email-header-set.vala | 2 +-
src/engine/rfc822/rfc822-message.vala | 19 +++--
src/mailer/main.vala | 12 +--
test/integration/smtp/client-session.vala | 13 ++--
6 files changed, 137 insertions(+), 61 deletions(-)
---
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 633710c2..828feff1 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1022,23 +1022,31 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
public async Geary.ComposedEmail get_composed_email(DateTime? date_override = null,
bool only_html = false) {
Geary.ComposedEmail email = new Geary.ComposedEmail(
- date_override ?? new DateTime.now_local(), from);
-
- email.to = this.to_entry.addresses ?? email.to;
- email.cc = this.cc_entry.addresses ?? email.cc;
- email.bcc = this.bcc_entry.addresses ?? email.bcc;
- email.reply_to = this.reply_to_entry.addresses ?? email.reply_to;
+ date_override ?? new DateTime.now_local(),
+ from
+ ).set_to(
+ this.to_entry.addresses
+ ).set_cc(
+ this.cc_entry.addresses
+ ).set_bcc(
+ this.bcc_entry.addresses
+ ).set_reply_to(
+ this.reply_to_entry.addresses
+ ).set_subject(
+ this.subject
+ );
if ((this.compose_type == ComposeType.REPLY || this.compose_type == ComposeType.REPLY_ALL) &&
!this.in_reply_to.is_empty)
- email.in_reply_to =
- new Geary.RFC822.MessageIDList.from_collection(in_reply_to).to_rfc822_string();
-
- if (!Geary.String.is_empty(this.references))
- email.references = this.references;
+ email.set_in_reply_to(
+ new Geary.RFC822.MessageIDList.from_collection(this.in_reply_to)
+ );
- if (!Geary.String.is_empty(this.subject))
- email.subject = this.subject;
+ if (!Geary.String.is_empty(this.references)) {
+ email.set_references(
+ new Geary.RFC822.MessageIDList.from_rfc822_string(this.references)
+ );
+ }
email.attached_files.add_all(this.attached_files);
email.inline_files.set_all(this.inline_files);
diff --git a/src/engine/api/geary-composed-email.vala b/src/engine/api/geary-composed-email.vala
index 4c1eb9e4..04e56f26 100644
--- a/src/engine/api/geary-composed-email.vala
+++ b/src/engine/api/geary-composed-email.vala
@@ -7,35 +7,59 @@
/**
* Encapsulates a message created by the user in the composer.
*/
-public class Geary.ComposedEmail : BaseObject {
+public class Geary.ComposedEmail : EmailHeaderSet, BaseObject {
private const string IMG_SRC_TEMPLATE = "src=\"%s\"";
- public const Geary.Email.Field REQUIRED_REPLY_FIELDS =
+ public const Geary.Email.Field REQUIRED_REPLY_FIELDS = (
Geary.Email.Field.HEADER
| Geary.Email.Field.BODY
| Geary.Email.Field.ORIGINATORS
| Geary.Email.Field.RECEIVERS
| Geary.Email.Field.REFERENCES
| Geary.Email.Field.SUBJECT
- | Geary.Email.Field.DATE;
-
- public DateTime date { get; set; }
- // TODO: sender goes here, but not beyond, as it's not properly supported by GMime yet.
- public RFC822.MailboxAddress? sender { get; set; default = null; }
- public RFC822.MailboxAddresses from { get; set; }
- public RFC822.MailboxAddresses? to { get; set; default = null; }
- public RFC822.MailboxAddresses? cc { get; set; default = null; }
- public RFC822.MailboxAddresses? bcc { get; set; default = null; }
- public RFC822.MailboxAddresses? reply_to { get; set; default = null; }
- public string? in_reply_to { get; set; default = null; }
- public Geary.Email? reply_to_email { get; set; default = null; }
- public string? references { get; set; default = null; }
- public string? subject { get; set; default = null; }
+ | Geary.Email.Field.DATE
+ );
+
+ /** {@inheritDoc} */
+ public RFC822.Date? date { get; protected set; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddresses? from { get; protected set; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddress? sender { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddresses? to { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddresses? cc { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddresses? bcc { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MailboxAddresses? reply_to { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MessageID? message_id { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MessageIDList? in_reply_to { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.MessageIDList? references { get; protected set; default = null; }
+
+ /** {@inheritDoc} */
+ public RFC822.Subject? subject { get; protected set; default = null; }
+
public string? body_text { get; set; default = null; }
public string? body_html { get; set; default = null; }
public string? mailer { get; set; default = null; }
+ public Geary.Email? reply_to_email { get; set; default = null; }
+
public Gee.Set<File> attached_files { get; private set;
default = new Gee.HashSet<File>(Geary.Files.nullable_hash, Geary.Files.nullable_equal); }
public Gee.Map<string,File> inline_files { get; private set;
@@ -45,18 +69,58 @@ public class Geary.ComposedEmail : BaseObject {
public string img_src_prefix { get; set; default = ""; }
- public ComposedEmail(DateTime date, RFC822.MailboxAddresses from,
- RFC822.MailboxAddresses? to = null, RFC822.MailboxAddresses? cc = null,
- RFC822.MailboxAddresses? bcc = null, string? subject = null,
- string? body_text = null, string? body_html = null) {
- this.date = date;
+ public ComposedEmail(DateTime date, RFC822.MailboxAddresses from) {
+ this.date = new RFC822.Date.from_date_time(date);
this.from = from;
- this.to = to;
- this.cc = cc;
- this.bcc = bcc;
- this.subject = subject;
- this.body_text = body_text;
- this.body_html = body_html;
+ }
+
+ public ComposedEmail set_sender(RFC822.MailboxAddress? sender) {
+ this.sender = sender;
+ return this;
+ }
+
+ public ComposedEmail set_to(RFC822.MailboxAddresses? recipients) {
+ this.to = recipients;
+ return this;
+ }
+
+ public ComposedEmail set_cc(RFC822.MailboxAddresses? recipients) {
+ this.cc = recipients;
+ return this;
+ }
+
+ public ComposedEmail set_bcc(RFC822.MailboxAddresses? recipients) {
+ this.bcc = recipients;
+ return this;
+ }
+
+ public ComposedEmail set_reply_to(RFC822.MailboxAddresses? recipients) {
+ this.reply_to = recipients;
+ return this;
+ }
+
+ public ComposedEmail set_message_id(RFC822.MessageID? id) {
+ this.message_id = id;
+ return this;
+ }
+
+ public ComposedEmail set_in_reply_to(RFC822.MessageIDList? messages) {
+ this.in_reply_to = messages;
+ return this;
+ }
+
+ public ComposedEmail set_references(RFC822.MessageIDList? messages) {
+ this.references = messages;
+ return this;
+ }
+
+ public ComposedEmail set_subject(string? subject) {
+ this.subject = (
+ String.is_empty_or_whitespace(subject)
+ ? null
+ : new RFC822.Subject(subject)
+ );
+ return this;
}
public async Geary.RFC822.Message to_rfc822_message(string? message_id,
diff --git a/src/engine/api/geary-email-header-set.vala b/src/engine/api/geary-email-header-set.vala
index ea4a885b..bb8f62ae 100644
--- a/src/engine/api/geary-email-header-set.vala
+++ b/src/engine/api/geary-email-header-set.vala
@@ -6,7 +6,7 @@
*/
/**
- * Denotes an object that has a set of RFC822 headers.
+ * Denotes an object with the standard set of RFC822 headers.
*/
public interface Geary.EmailHeaderSet : BaseObject {
diff --git a/src/engine/rfc822/rfc822-message.vala b/src/engine/rfc822/rfc822-message.vala
index 834ed98c..f01f249b 100644
--- a/src/engine/rfc822/rfc822-message.vala
+++ b/src/engine/rfc822/rfc822-message.vala
@@ -134,7 +134,7 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
assert(email.from.size > 0);
this.sender = email.sender;
this.from = email.from;
- this.date = new RFC822.Date.from_date_time(email.date);
+ this.date = email.date;
// GMimeMessage.set_sender actually sets the From header - and
// although the API docs make it sound otherwise, it also
@@ -167,7 +167,8 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
if (email.sender != null) {
this.sender = email.sender;
- this.message.set_header(HEADER_SENDER, email.sender.to_rfc822_string());
+ this.message.set_header(HEADER_SENDER,
+ email.sender.to_rfc822_string());
}
if (email.reply_to != null) {
@@ -176,18 +177,20 @@ public class Geary.RFC822.Message : BaseObject, EmailHeaderSet {
}
if (email.in_reply_to != null) {
- this.in_reply_to = new Geary.RFC822.MessageIDList.from_rfc822_string(email.in_reply_to);
- this.message.set_header(HEADER_IN_REPLY_TO, email.in_reply_to);
+ this.in_reply_to = email.in_reply_to;
+ this.message.set_header(HEADER_IN_REPLY_TO,
+ email.in_reply_to.to_rfc822_string());
}
if (email.references != null) {
- this.references = new Geary.RFC822.MessageIDList.from_rfc822_string(email.references);
- this.message.set_header(HEADER_REFERENCES, email.references);
+ this.references = email.references;
+ this.message.set_header(HEADER_REFERENCES,
+ email.references.to_rfc822_string());
}
if (email.subject != null) {
- this.subject = new Geary.RFC822.Subject(email.subject);
- this.message.set_subject(email.subject);
+ this.subject = email.subject;
+ this.message.set_subject(email.subject.value);
}
// User-Agent
diff --git a/src/mailer/main.vala b/src/mailer/main.vala
index a639c1f7..790f2100 100644
--- a/src/mailer/main.vala
+++ b/src/mailer/main.vala
@@ -25,7 +25,7 @@ async void main_async() throws Error {
File.new_for_path(arg_full_file), true));
} else {
string subj_msg = "#%d".printf(ctr + 1);
- composed_email.subject = subj_msg;
+ composed_email.set_subject(subj_msg);
if (Geary.String.is_empty(arg_file)) {
composed_email.body_text = subj_msg;
@@ -173,10 +173,12 @@ int main(string[] args) {
);
if (arg_full_file == null) {
- composed_email = new Geary.ComposedEmail(new DateTime.now_local(),
- new Geary.RFC822.MailboxAddresses.single(new Geary.RFC822.MailboxAddress(null, arg_from)));
- composed_email.to = new Geary.RFC822.MailboxAddresses.single(
- new Geary.RFC822.MailboxAddress(null, arg_to));
+ composed_email = new Geary.ComposedEmail(
+ new GLib.DateTime.now_local(),
+ new Geary.RFC822.MailboxAddresses.single(new Geary.RFC822.MailboxAddress(null, arg_from))
+ ).set_to(
+ new Geary.RFC822.MailboxAddresses.single(new Geary.RFC822.MailboxAddress(null, arg_to))
+ );
}
main_loop = new MainLoop();
diff --git a/test/integration/smtp/client-session.vala b/test/integration/smtp/client-session.vala
index 575a1240..30b03eb4 100644
--- a/test/integration/smtp/client-session.vala
+++ b/test/integration/smtp/client-session.vala
@@ -121,14 +121,13 @@ class Integration.Smtp.ClientSession : TestCase {
Geary.RFC822.MailboxAddress to) {
Geary.ComposedEmail composed = new Geary.ComposedEmail(
new GLib.DateTime.now_local(),
- new Geary.RFC822.MailboxAddresses.single(from),
- new Geary.RFC822.MailboxAddresses.single(to),
- null,
- null,
- "Geary integration test subject",
- "Geary integration test message",
- null
+ new Geary.RFC822.MailboxAddresses.single(from)
+ ).set_to(
+ new Geary.RFC822.MailboxAddresses.single(to)
+ ).set_subject(
+ "Geary integration test subject"
);
+ composed.body_text = "Geary integration test message";
return yield new Geary.RFC822.Message.from_composed_email(
composed,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]