[geary/mjog/mail-merge-plugin: 147/157] Plugin.Email: Add load_body_as method and implement it
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 147/157] Plugin.Email: Add load_body_as method and implement it
- Date: Fri, 3 Jul 2020 08:13:55 +0000 (UTC)
commit 13754d377f8b9775af402a8ecf8e05b40a4498ae
Author: Michael Gratton <mike vee net>
Date: Thu May 7 17:25:31 2020 +1000
Plugin.Email: Add load_body_as method and implement it
Allows email plugins access to email boxy text.
.../application-email-store-factory.vala | 34 ++++++++++++++++++++
src/client/plugin/plugin-email.vala | 36 ++++++++++++++++++++++
2 files changed, 70 insertions(+)
---
diff --git a/src/client/application/application-email-store-factory.vala
b/src/client/application/application-email-store-factory.vala
index 542ab5022..6816dbaa3 100644
--- a/src/client/application/application-email-store-factory.vala
+++ b/src/client/application/application-email-store-factory.vala
@@ -189,6 +189,40 @@ internal class Application.EmailStoreFactory : Geary.BaseObject {
return Util.Email.get_primary_originator(this.backing);
}
+ public async string load_body_as(Plugin.Email.BodyType type,
+ bool convert,
+ GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ if (!(Geary.Email.REQUIRED_FOR_MESSAGE in this.backing.fields)) {
+ Geary.Account account = this.account.backing.account;
+ this.backing = yield account.local_fetch_email_async(
+ this.backing.id,
+ Geary.Email.REQUIRED_FOR_MESSAGE | this.backing.fields,
+ cancellable
+ );
+ }
+
+ Geary.RFC822.Message message = this.backing.get_message();
+ string body = "";
+ switch (type) {
+ case PLAIN:
+ if (message.has_plain_body()) {
+ body = message.get_plain_body(false, null) ?? "";
+ } else {
+ body = message.get_searchable_body(false) ?? "";
+ }
+ break;
+
+ case HTML:
+ if (message.has_html_body()) {
+ body = message.get_html_body(null) ?? "";
+ } else {
+ body = message.get_plain_body(true, null) ?? "";
+ }
+ break;
+ }
+ return body;
+ }
}
diff --git a/src/client/plugin/plugin-email.vala b/src/client/plugin/plugin-email.vala
index 1ae5b0853..1a9656c33 100644
--- a/src/client/plugin/plugin-email.vala
+++ b/src/client/plugin/plugin-email.vala
@@ -15,6 +15,15 @@ public interface Plugin.Email :
Geary.EmailHeaderSet {
+ /** Defines the formats that email body text can be loaded as. */
+ public enum BodyType {
+ /** Specifies `text/plain` body parts. */
+ PLAIN,
+ /** Specifies `text/html` body parts. */
+ HTML;
+ }
+
+
/** Returns a unique identifier for this email. */
public abstract EmailIdentifier identifier { get; }
@@ -31,6 +40,33 @@ public interface Plugin.Email :
*/
public abstract Geary.RFC822.MailboxAddress? get_primary_originator();
+ /**
+ * Load the text of the email body as the given type.
+ *
+ * This method traverses the MIME multipart structure of the email
+ * body finding inline text parts and assembles them into a
+ * complete email body, as would be displayed to a person reading
+ * the email. If multiple matching parts are found, they will be
+ * concatenated.
+ *
+ * If no alternative parts for the requested type exist and
+ * `convert` is true, if alternatives for other supported types
+ * are present, an attempt will be made to convert to the
+ * requested type. For example, requesting HTML for an email with
+ * plain text only will attempt to reformat the plain text by
+ * inserting HTML tags. Otherwise an {@link Error.NOT_SUPPORTED}
+ * error is thrown.
+ *
+ * An error will be thrown if no body parts could be found, for
+ * example if an email has not completely been downloaded from the
+ * server.
+ */
+ public abstract async string load_body_as(
+ BodyType type,
+ bool convert,
+ GLib.Cancellable? cancellable
+ ) throws GLib.Error;
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]