From 53b31d9cce6bdf612fbe2e8733bb92b8320866da Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 30 Sep 2008 19:34:31 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: c052846d400add7f419d4d1ffe4c900df5f4302a Monotone-Revision: f0940e9496d2f6b614f37aed2fd66c564c0df278 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2008-09-30T19:34:31 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 ++ UI/MailPartViewers/UIxMailPartHTMLViewer.h | 4 +- UI/MailPartViewers/UIxMailPartHTMLViewer.m | 46 ++++++++++++++++++- UI/MailPartViewers/UIxMailRenderingContext.h | 2 + UI/MailPartViewers/UIxMailRenderingContext.m | 26 +++++++++-- UI/MailerUI/UIxMailView.m | 7 ++- .../MailPartViewers/UIxMailPartHTMLViewer.wox | 2 + UI/Templates/MailerUI/UIxMailView.wox | 3 ++ UI/WebServerResources/MailerUI.css | 7 +++ UI/WebServerResources/MailerUI.js | 30 +++++++++++- 10 files changed, 122 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f78ab9b9..2ce3bd388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-09-30 Ludovic Marcotte + + * Implemented external loading of images + in HTML mails the same way Thunderbird does it. + 2008-09-30 Wolfgang Sourdeau * SoObjects/SOGo/SOGoLDAPUserDefaults.m ([SOGoLDAPUserDefaults diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.h b/UI/MailPartViewers/UIxMailPartHTMLViewer.h index a0df21764..dc799eab8 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.h +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.h @@ -1,6 +1,6 @@ /* UIxMailPartHTMLViewer.h - this file is part of SOGo * - * Copyright (C) 2007 Inverse inc. + * Copyright (C) 2007, 2008 Inverse inc. * * Author: Wolfgang Sourdeau * @@ -28,9 +28,11 @@ @interface UIxMailPartHTMLViewer : UIxMailPartViewer { id handler; + BOOL unsafe; } - (NSString *) flatContentAsString; +- (void) setUnsafe: (BOOL) b; @end diff --git a/UI/MailPartViewers/UIxMailPartHTMLViewer.m b/UI/MailPartViewers/UIxMailPartHTMLViewer.m index ba7f88cda..db38b231d 100644 --- a/UI/MailPartViewers/UIxMailPartHTMLViewer.m +++ b/UI/MailPartViewers/UIxMailPartHTMLViewer.m @@ -103,6 +103,8 @@ _xmlCharsetForCharset (NSString *charset) BOOL inScript; BOOL inCSSDeclaration; BOOL hasEmbeddedCSS; + BOOL hasExternalImages; + BOOL unsafe; NSMutableArray *crumb; xmlCharEncoding contentEncoding; } @@ -135,6 +137,16 @@ _xmlCharsetForCharset (NSString *charset) [super dealloc]; } +- (BOOL) hasExternalImages +{ + return hasExternalImages; +} + +- (BOOL) setUnsafe: (BOOL) b +{ + unsafe = b; +} + - (void) setContentEncoding: (xmlCharEncoding) newContentEncoding { contentEncoding = newContentEncoding; @@ -292,8 +304,14 @@ _xmlCharsetForCharset (NSString *charset) value = [attachmentIds objectForKey: cid]; skipAttribute = (value == nil); } - else - skipAttribute = YES; + else if ([_rawName caseInsensitiveCompare: @"img"] == NSOrderedSame) + { + hasExternalImages = YES; + + if (!unsafe) skipAttribute = YES; + } + else + skipAttribute = YES; } else if ([name caseInsensitiveCompare: @"href"] == NSOrderedSame || [name caseInsensitiveCompare: @"action"] == NSOrderedSame) @@ -520,10 +538,17 @@ _xmlCharsetForCharset (NSString *charset) handler = [_UIxHTMLMailContentHandler new]; [handler setAttachmentIds: [mail fetchAttachmentIds]]; [handler setContentEncoding: [self _xmlCharEncoding]]; + [handler setUnsafe: unsafe]; + [parser setContentHandler: handler]; [parser parseFromSource: preparsedContent]; } +- (BOOL) hasExternalImages +{ + return [handler hasExternalImages]; +} + - (NSString *) cssContent { NSString *cssContent, *css; @@ -550,6 +575,23 @@ _xmlCharsetForCharset (NSString *charset) return [handler result]; } +- (void) setUnsafe: (BOOL) b +{ + unsafe = b; +} + +- (BOOL) displayLoadImages +{ + BOOL b; + + b = [handler hasExternalImages]; + + if (b && unsafe) + return NO; + + return b; +} + @end @implementation UIxMailPartExternalHTMLViewer diff --git a/UI/MailPartViewers/UIxMailRenderingContext.h b/UI/MailPartViewers/UIxMailRenderingContext.h index 1ac62538f..9edcf1ca9 100644 --- a/UI/MailPartViewers/UIxMailRenderingContext.h +++ b/UI/MailPartViewers/UIxMailRenderingContext.h @@ -43,6 +43,7 @@ WOComponent *viewer; /* non-retained! */ WOContext *context; /* non-retained! */ NSDictionary *flatContents; /* IMAP4 name to NSData */ + BOOL unsafe; } - (id) initWithViewer: (WOComponent *) _viewer @@ -51,6 +52,7 @@ /* state */ - (void) reset; +- (void) setUnsafe: (BOOL) b; /* fetching */ diff --git a/UI/MailPartViewers/UIxMailRenderingContext.m b/UI/MailPartViewers/UIxMailRenderingContext.m index 38e3cd218..b52596d46 100644 --- a/UI/MailPartViewers/UIxMailRenderingContext.m +++ b/UI/MailPartViewers/UIxMailRenderingContext.m @@ -86,6 +86,11 @@ static BOOL showNamedTextAttachmentsInline = NO; flatContents = nil; } +- (void) setUnsafe: (BOOL) b +{ + unsafe = b; +} + /* fetching */ - (NSDictionary *) flatContents @@ -152,7 +157,12 @@ static BOOL showNamedTextAttachmentsInline = NO; - (WOComponent *) htmlViewer { - return [viewer pageWithName: @"UIxMailPartHTMLViewer"]; + id o; + + o = [viewer pageWithName: @"UIxMailPartHTMLViewer"]; + [o setUnsafe: unsafe]; + + return o; } - (WOComponent *) messageViewer @@ -307,7 +317,8 @@ static BOOL showNamedTextAttachmentsInline = NO; /* debugging */ -- (BOOL)isDebuggingEnabled { +- (BOOL) isDebuggingEnabled +{ return NO; } @@ -318,10 +329,13 @@ static BOOL showNamedTextAttachmentsInline = NO; static NSString *MRK = @"UIxMailRenderingContext"; -- (void)pushMailRenderingContext:(UIxMailRenderingContext *)_mctx { +- (void) pushMailRenderingContext: (UIxMailRenderingContext *) _mctx +{ [self setObject:_mctx forKey:MRK]; } -- (UIxMailRenderingContext *)popMailRenderingContext { + +- (UIxMailRenderingContext *) popMailRenderingContext +{ UIxMailRenderingContext *mctx; if ((mctx = [self objectForKey:MRK]) == nil) @@ -331,7 +345,9 @@ static NSString *MRK = @"UIxMailRenderingContext"; [self removeObjectForKey:MRK]; return mctx; } -- (UIxMailRenderingContext *)mailRenderingContext { + +- (UIxMailRenderingContext *) mailRenderingContext +{ return [self objectForKey:MRK]; } diff --git a/UI/MailerUI/UIxMailView.m b/UI/MailerUI/UIxMailView.m index ca7077408..fcf350dcb 100644 --- a/UI/MailerUI/UIxMailView.m +++ b/UI/MailerUI/UIxMailView.m @@ -207,13 +207,18 @@ static NSString *mailETag = nil; inContext: (WOContext *) _ctx { UIxMailRenderingContext *mctx; + WORequest *request; + NSString *unsafe; + request = [_ctx request]; + unsafe = [request formValueForKey: @"unsafe"]; + if (mailETag != nil) [[_ctx response] setHeader:mailETag forKey:@"etag"]; mctx = [[UIxMailRenderingContext alloc] initWithViewer: self context: _ctx]; - + [mctx setUnsafe: (unsafe != nil ? YES : NO)]; [_ctx pushMailRenderingContext: mctx]; [mctx release]; diff --git a/UI/Templates/MailPartViewers/UIxMailPartHTMLViewer.wox b/UI/Templates/MailPartViewers/UIxMailPartHTMLViewer.wox index c4bd4faea..8a7b2a110 100644 --- a/UI/Templates/MailPartViewers/UIxMailPartHTMLViewer.wox +++ b/UI/Templates/MailPartViewers/UIxMailPartHTMLViewer.wox @@ -7,6 +7,8 @@ xmlns:rsrc="OGo:url" xmlns:label="OGo:label"> +
diff --git a/UI/Templates/MailerUI/UIxMailView.wox b/UI/Templates/MailerUI/UIxMailView.wox index fd454765f..78fdcec03 100644 --- a/UI/Templates/MailerUI/UIxMailView.wox +++ b/UI/Templates/MailerUI/UIxMailView.wox @@ -9,6 +9,9 @@ > + diff --git a/UI/WebServerResources/MailerUI.css b/UI/WebServerResources/MailerUI.css index 0a098da8f..d9d8bfc23 100644 --- a/UI/WebServerResources/MailerUI.css +++ b/UI/WebServerResources/MailerUI.css @@ -356,6 +356,13 @@ INPUT#editDraftButton right: 1em; } +INPUT#loadImagesButton +{ + position: absolute; + top: 2.5em; + right: 1em; +} + TABLE.mailer_fieldtable { top: 0px; left: 0px; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index e936a49d8..585b89316 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -752,6 +752,20 @@ function loadMessage(idx) { configureLinksInMessage(); resizeMailContent(); } + + configureLoadImagesButton(); +} + +function configureLoadImagesButton() { + // We show/hide the "Load Images" button + var loadImagesButton = $("loadImagesButton"); + var displayLoadImages = $("displayLoadImages"); + + if (typeof(displayLoadImages) == "undefined" || + displayLoadImages == null || + displayLoadImages.value == 0) { + loadImagesButton.style.display = 'none'; + } } function configureLinksInMessage() { @@ -779,6 +793,11 @@ function configureLinksInMessage() { editDraftButton.observe("click", onMessageEditDraft.bindAsEventListener(editDraftButton)); + var loadImagesButton = $("loadImagesButton"); + if (loadImagesButton) + loadImagesButton.observe("click", + onMessageLoadImages.bindAsEventListener(loadImagesButton)); + configureiCalLinksInMessage(); } @@ -885,6 +904,14 @@ function onMessageEditDraft(event) { return openMessageWindowsForSelection("edit", true); } +function onMessageLoadImages(event) { + var msguid = Mailer.currentMessages[Mailer.currentMailbox]; + var url = (ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" + + msguid + "/view?noframe=1&unsafe=1"); + document.messageAjaxRequest + = triggerAjaxRequest(url, messageCallback, msguid); +} + function onEmailAddressClick(event) { popupMenu(event, 'addressMenu', this); preventDefault(event); @@ -910,7 +937,8 @@ function messageCallback(http) { div.update(http.responseText); configureLinksInMessage(); resizeMailContent(); - + configureLoadImagesButton(); + if (http.callbackData) { var cachedMessage = new Array(); cachedMessage['idx'] = Mailer.currentMailbox + '/' + http.callbackData;
: