From ef5e7775cdb030ecd8354cfa2c9ec934c9055909 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 11 Aug 2021 13:44:48 -0400 Subject: [PATCH] feat(mail): download message as .eml file --- UI/MailerUI/English.lproj/Localizable.strings | 6 +++++ UI/MailerUI/UIxMailActions.m | 20 +++++++++++++++++ UI/MailerUI/product.plist | 5 +++++ UI/Templates/MailerUI/UIxMailViewTemplate.wox | 12 +++++++--- .../js/Mailer/Message.service.js | 22 ++++++++++++++----- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index 73934f7bb..3c6982ad4 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -230,6 +230,12 @@ /* Message view "more" menu: create a task from message */ "Convert To Task" = "Convert To Task"; +/* Message view "more" menu: download message as an eml file */ +"Download message" = "Download message"; + +/* Message view "more" menu: download message as a zip archive */ +"Download message (zip)" = "Download message (zip)"; + /* Message view "more" menu: download all attachments as a zip archive */ "Download all attachments" = "Download all attachments"; diff --git a/UI/MailerUI/UIxMailActions.m b/UI/MailerUI/UIxMailActions.m index 2d5329677..69a27d9cf 100644 --- a/UI/MailerUI/UIxMailActions.m +++ b/UI/MailerUI/UIxMailActions.m @@ -370,4 +370,24 @@ return response; } +- (id ) exportAction +{ + NSString *disposition, *source; + SOGoMailObject *co; + WOResponse *response; + + co = [self clientObject]; + source = [co contentAsString]; + + response = [self responseWithStatus: 200]; + [response setHeader: @"message/rfc822; charset=utf-8" + forKey: @"content-type"]; + disposition = [NSString stringWithFormat: @"attachment; filename=\"%@.eml\"", [co nameInContainer]]; + [response setHeader: disposition forKey: @"Content-Disposition"]; + [response setContent: [source dataUsingEncoding: NSUTF8StringEncoding]]; + + return response; +} + + @end diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist index 906ed30b7..b707e6f5b 100644 --- a/UI/MailerUI/product.plist +++ b/UI/MailerUI/product.plist @@ -265,6 +265,11 @@ actionClass = "UIxMailActions"; actionName = "markMessageRead"; }; + export = { + protectedBy = "View"; + actionClass = "UIxMailActions"; + actionName = "export"; + }; }; }; diff --git a/UI/Templates/MailerUI/UIxMailViewTemplate.wox b/UI/Templates/MailerUI/UIxMailViewTemplate.wox index 0b4eacec9..5ac46300d 100644 --- a/UI/Templates/MailerUI/UIxMailViewTemplate.wox +++ b/UI/Templates/MailerUI/UIxMailViewTemplate.wox @@ -81,14 +81,20 @@ - - + + + + + + + ng-click="viewer.message.downloadAttachmentsArchive()"> diff --git a/UI/WebServerResources/js/Mailer/Message.service.js b/UI/WebServerResources/js/Mailer/Message.service.js index 1058e405c..71ff0ae55 100644 --- a/UI/WebServerResources/js/Mailer/Message.service.js +++ b/UI/WebServerResources/js/Mailer/Message.service.js @@ -864,12 +864,12 @@ }; /** - * @function download + * @function downloadArchive * @memberof Message.prototype - * @desc Download the current message + * @desc Download the current message as a zip archive * @returns a promise of the HTTP operation */ - Message.prototype.download = function() { + Message.prototype.downloadArchive = function() { var data, options; data = { uids: [this.uid] }; @@ -879,12 +879,22 @@ }; /** - * @function downloadAttachments + * @function download * @memberof Message.prototype - * @desc Download an archive of all attachments + * @desc Download the current message as a eml file * @returns a promise of the HTTP operation */ - Message.prototype.downloadAttachments = function() { + Message.prototype.download = function() { + return Message.$$resource.download(this.$absolutePath(), 'export'); + }; + + /** + * @function downloadAttachments + * @memberof Message.prototype + * @desc Download a zip archive of all attachments + * @returns a promise of the HTTP operation + */ + Message.prototype.downloadAttachmentsArchive = function() { var options; options = { filename: l('attachments') + "-" + this.uid + ".zip" };