Skip to content

Commit

Permalink
feat(mail): Add 'View raw message' mail contextual option. This optio…
Browse files Browse the repository at this point in the history
…n open message in a popup without HTML mail CSS content modification.
  • Loading branch information
WoodySlum committed May 22, 2024
1 parent 9eb8039 commit 6ac8525
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 3 deletions.
21 changes: 21 additions & 0 deletions UI/MailPartViewers/UIxMailPartAlternativeViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,34 @@
*/

@interface UIxMailPartAlternativeViewer : UIxMailPartMixedViewer
{
BOOL rawContent;
}

@end

@implementation UIxMailPartAlternativeViewer

- (id) init
{
if ((self = [super init]))
{
rawContent = NO;
}

return self;
}

- (void) dealloc
{
[super dealloc];
}

- (void)activateRawContent
{
rawContent = YES;
}

/* part selection */

- (NSArray *) childPartTypes
Expand Down Expand Up @@ -206,6 +224,9 @@ - (id) renderedPart
[viewer setAttachmentIds: attachmentIds];
if ([self decodedFlatContent])
[viewer setDecodedContent: [parts objectAtIndex: i]];

if ([viewer isKindOfClass:NSClassFromString(@"UIxMailPartHTMLViewer")] && rawContent)
[viewer activateRawContent];
[renderedParts addObject: [viewer renderedPart]];
}

Expand Down
2 changes: 2 additions & 0 deletions UI/MailPartViewers/UIxMailPartHTMLViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
{
id handler;
NSException *ex;
BOOL rawContent;
}

- (NSString *) flatContentAsString;
- (void)activateRawContent;

@end

Expand Down
22 changes: 21 additions & 1 deletion UI/MailPartViewers/UIxMailPartHTMLViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ @interface _UIxHTMLMailContentHandler : NSObject <SaxContentHandler, SaxLexicalH
BOOL inCSSDeclaration;
BOOL hasEmbeddedCSS;
xmlCharEncoding contentEncoding;
BOOL rawContent;
}

- (NSString *) result;
- (void) activateRawContent;

@end

Expand Down Expand Up @@ -161,6 +163,7 @@ - (id) init
ignoreTag = nil;
attachmentIds = nil;
contentEncoding = XML_CHAR_ENCODING_UTF8;
rawContent = NO;
}

return self;
Expand All @@ -174,6 +177,11 @@ - (void) dealloc
[super dealloc];
}

- (void)activateRawContent
{
rawContent = YES;
}

- (void) setContentEncoding: (xmlCharEncoding) newContentEncoding
{
contentEncoding = newContentEncoding;
Expand Down Expand Up @@ -376,7 +384,8 @@ - (void) _appendStyle: (unichar *) _chars
(*(currentChar-7) == 'p' || *(currentChar-7) == 'P') &&
(*(currentChar-8) == 'm' || *(currentChar-8) == 'M') &&
(*(currentChar-9) == 'i' || *(currentChar-9) == 'I') &&
*(currentChar-10) == '!'))
*(currentChar-10) == '!')
&& !rawContent)
{
length = (currentChar - start);
[declaration appendFormat: @"%@ !important;",
Expand Down Expand Up @@ -759,11 +768,17 @@ - (id) init
{
handler = nil;
ex = nil;
rawContent = NO;
}

return self;
}

- (void)activateRawContent
{
rawContent = YES;
}

- (void) dealloc
{
[handler release];
Expand Down Expand Up @@ -805,6 +820,8 @@ - (void) _parseContent
createXMLReaderForMimeType: @"text/html"];

handler = [_UIxHTMLMailContentHandler new];
if (rawContent)
[handler activateRawContent];
[handler setAttachmentIds: attachmentIds];

// Some broken email messages have some additionnal content outside the main HTML tags which are
Expand Down Expand Up @@ -920,6 +937,9 @@ - (NSString *) flatContentAsString
if (!handler)
[self _parseContent];

if (rawContent)
return [handler result];

return _sanitizeHtmlForDisplay([handler result]);
}

Expand Down
1 change: 1 addition & 0 deletions UI/MailerUI/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"Save As..." = "Save As...";
"Print Preview" = "Print Preview";
"View Message Source" = "View Message Source";
"View raw message" = "View raw message";

/* Message view "more" menu: create an event from message */
"Convert To Event" = "Convert To Event";
Expand Down
1 change: 1 addition & 0 deletions UI/MailerUI/French.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"Save As..." = "Télécharger";
"Print Preview" = "Aperçu avant impression";
"View Message Source" = "Voir le code source";
"View raw message" = "Voir le message brut";

/* Message view "more" menu: create an event from message */
"Convert To Event" = "Convertir en événement";
Expand Down
16 changes: 16 additions & 0 deletions UI/MailerUI/UIxMailView.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ - (id) contentViewerComponent
/* actions */

- (id <WOActionResults>) defaultAction
{
return [self view: NO];
}

- (id <WOActionResults>) viewRawAction
{
return [self view: YES];
}

- (id <WOActionResults>) view: (BOOL)raw
{
WOResponse *response;
NSMutableDictionary *data;
Expand Down Expand Up @@ -336,6 +346,12 @@ those are the IMAP4 flags (and annotations, which we do not use).
}

viewer = [self contentViewerComponent]; // set attachmentIds for common parts

if (raw && ([viewer isKindOfClass: NSClassFromString(@"UIxMailPartHTMLViewer")]
|| [viewer isKindOfClass: NSClassFromString(@"UIxMailPartAlternativeViewer")])) {
// In this case, disable html mail content modification by SOGo
[viewer activateRawContent];
}
renderedPart = [viewer renderedPart]; // set attachmentIds for encrypted & TNEF parts

data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
Expand Down
5 changes: 5 additions & 0 deletions UI/MailerUI/product.plist
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
pageName = "UIxMailView";
actionName = "default";
};
viewRaw = {
protectedBy = "View";
pageName = "UIxMailView";
actionName = "viewRaw";
};
sendMDN = {
protectedBy = "View";
pageName = "UIxMailView";
Expand Down
6 changes: 6 additions & 0 deletions UI/Templates/MailerUI/UIxMailViewTemplate.wox
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<var:string label:value="View Message Source"/>
</md-button>
</md-menu-item>
<md-menu-item ng-hide="::isPopup">
<md-button label:aria-label="View raw message"
ng-click="viewer.activateRawContent($event)">
<var:string label:value="View raw message"/>
</md-button>
</md-menu-item>
<md-menu-item>
<md-button label:aria-label="Print..."
ng-click="viewer.print()">
Expand Down
25 changes: 25 additions & 0 deletions UI/WebServerResources/js/Mailer/Mailer.popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
stateMessage: stateMessage
}
})
.state('mail.account.mailbox.messageRaw', {
url: '/:messageId/viewRaw',
views: {
'message@': {
templateUrl: 'UIxMailViewTemplate', // UI/Templates/MailerUI/UIxMailViewTemplate.wox
controller: 'MessageController',
controllerAs: 'viewer'
}
},
resolve: {
stateMessage: stateMessageRaw
}
})
.state('mail.account.mailbox.message.edit', {
url: '/edit',
views: {
Expand Down Expand Up @@ -254,6 +267,18 @@
}
}

/**
* @ngInject
*/
stateMessageRaw.$inject = ['encodeUriFilter', '$stateParams', 'stateMailbox', 'Message'];
function stateMessageRaw(encodeUriFilter, $stateParams, stateMailbox, Message) {
var data, message;

data = { uid: $stateParams.messageId.toString() };
message = new Message(stateMailbox.$account.id, stateMailbox, data);
return message.$reload({ useCache: false, raw: true });
}

/**
* @ngInject
*/
Expand Down
7 changes: 5 additions & 2 deletions UI/WebServerResources/js/Mailer/Message.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@
* @function $reload
* @memberof Message.prototype
* @desc Fetch the viewable message body along with other metadata such as the list of attachments.
* @param {object} [options] - set {useCache: true} to use already fetched data
* @param {object} [options] - set {useCache: true} to use already fetched data, {raw: true} to remove web mail alteration
* @returns a promise of the HTTP operation
*/
Message.prototype.$reload = function (options) {
Expand All @@ -813,7 +813,10 @@
return this;
}

futureMessageData = Message.$$resource.fetch(this.$absolutePath(options), 'view');
if (options && options.raw)
futureMessageData = Message.$$resource.fetch(this.$absolutePath(options), 'viewRaw');
else
futureMessageData = Message.$$resource.fetch(this.$absolutePath(options), 'view');

return this.$unwrap(futureMessageData);
};
Expand Down
4 changes: 4 additions & 0 deletions UI/WebServerResources/js/Mailer/MessageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@
}
};

this.activateRawContent = function ($event) {
this.openInPopup('viewRaw');
};

this.print = function($event) {
$window.print();
};
Expand Down

0 comments on commit 6ac8525

Please sign in to comment.