[geary/mjog/mail-merge-plugin: 48/72] Plugin.MailMerge: Show merge virtual folder when merging
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/mail-merge-plugin: 48/72] Plugin.MailMerge: Show merge virtual folder when merging
- Date: Tue, 18 Aug 2020 06:32:45 +0000 (UTC)
commit 77b1683c42d20853b0c33de065e4443d29fa69cb
Author: Michael Gratton <mike vee net>
Date: Fri Jul 17 18:25:04 2020 +1000
Plugin.MailMerge: Show merge virtual folder when merging
Create and display mail merge virtual folder when merging.
src/client/plugin/mail-merge/mail-merge.vala | 52 ++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/src/client/plugin/mail-merge/mail-merge.vala b/src/client/plugin/mail-merge/mail-merge.vala
index 68362f491..a8a886d3e 100644
--- a/src/client/plugin/mail-merge/mail-merge.vala
+++ b/src/client/plugin/mail-merge/mail-merge.vala
@@ -18,7 +18,7 @@ public void peas_register_types(TypeModule module) {
* Plugin to Fill in and send email templates using a spreadsheet.
*/
public class Plugin.MailMerge :
- PluginBase, FolderExtension, EmailExtension {
+ PluginBase, FolderExtension, EmailExtension, TrustedExtension {
private const string FIELD_START = "{{";
@@ -54,6 +54,13 @@ public class Plugin.MailMerge :
get; set construct;
}
+ public global::Application.Client client_application {
+ get; set construct;
+ }
+
+ public global::Application.PluginManager client_plugins {
+ get; set construct;
+ }
private FolderStore? folder_store = null;
private EmailStore? email_store = null;
@@ -164,8 +171,49 @@ public class Plugin.MailMerge :
}
}
- private async void merge_email(EmailIdentifier id) {
+ private async void merge_email(EmailIdentifier id,
+ GLib.File? default_csv_file) {
+ var csv_file = default_csv_file ?? show_merge_data_chooser();
+ if (csv_file != null) {
+ try {
+ var csv_input = yield csv_file.read_async(
+ GLib.Priority.DEFAULT,
+ this.cancellable
+ );
+ var csv = yield new Util.Csv.Reader(csv_input, this.cancellable);
+ Gee.Collection<Email> emails = yield this.email_store.get_email(
+ Geary.Collection.single(id),
+ this.cancellable
+ );
+ if (!emails.is_empty) {
+ var account_context = this.client_plugins.to_client_account(
+ id.account
+ );
+ var email = Geary.Collection.first(emails);
+ var merge_folder = new Plugin.MailMergeFolder(
+ account_context.account,
+ account_context.account.local_folder_root,
+ this.client_plugins.to_engine_email(email),
+ csv
+ );
+
+ var folder_context = new global::Application.FolderContext(
+ merge_folder
+ );
+ folder_context.display_name = _("Mail Merge");
+ folder_context.icon_name = "mail-outbox-symbolic";
+ account_context.add_folders(
+ Geary.Collection.single(folder_context)
+ );
+
+ var main = this.client_application.get_active_main_window();
+ yield main.select_folder(merge_folder, true);
+ }
+ } catch (GLib.Error err) {
+ debug("Displaying merge folder failed: %s", err.message);
+ }
+ }
}
private async void update_email(Email target) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]