diff --git a/SoObjects/Mailer/SOGoMailBodyPart.h b/SoObjects/Mailer/SOGoMailBodyPart.h index c3d6509dd..0effd14cf 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.h +++ b/SoObjects/Mailer/SOGoMailBodyPart.h @@ -41,6 +41,7 @@ NSArray *pathToPart; NSString *identifier; id partInfo; + BOOL asAttachment; } /* hierarchy */ @@ -57,6 +58,8 @@ - (id) partInfo; - (NSData *) fetchBLOB; +- (void) setAsAttachment; +- (BOOL) asAttachment; /* factory */ diff --git a/SoObjects/Mailer/SOGoMailBodyPart.m b/SoObjects/Mailer/SOGoMailBodyPart.m index 0ce0fcd7f..6fac084d8 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SoObjects/Mailer/SOGoMailBodyPart.m @@ -63,13 +63,28 @@ static BOOL debugOn = NO; NSLog(@"Note(SOGoMailBodyPart): etag caching disabled!"); } -- (void)dealloc { +- (id) init +{ + if ((self = [super init])) + asAttachment = NO; + + return self; +} + +- (void) dealloc +{ [self->partInfo release]; [self->identifier release]; [self->pathToPart release]; [super dealloc]; } +- (void) setAsAttachment +{ + asAttachment = YES; +} + + /* hierarchy */ - (SOGoMailObject *)mailObject { @@ -178,6 +193,8 @@ static BOOL debugOn = NO; /* lookup body part */ if ([self isBodyPartKey:_key inContext:_ctx]) obj = [self lookupImap4BodyPartKey:_key inContext:_ctx]; + else if ([_key isEqualToString: @"asAttachment"]) + [self setAsAttachment]; /* should check whether such a filename exist in the attached names */ if (!obj) obj = self; @@ -283,14 +300,18 @@ static BOOL debugOn = NO; /* try type from body structure info */ - parts = [self contentTypeForBodyPartInfo: [self partInfo]]; - contentType = [[parts componentsSeparatedByString: @";"] objectAtIndex: 0]; - - if (![contentType length]) - { - extension = [[self nameInContainer] pathExtension]; - contentType = [self contentTypeForPathExtension: extension]; - } + if (asAttachment) + contentType = @"application/octet-stream"; + else { + parts = [self contentTypeForBodyPartInfo: [self partInfo]]; + contentType = [[parts componentsSeparatedByString: @";"] objectAtIndex: 0]; + + if (![contentType length]) + { + extension = [[self nameInContainer] pathExtension]; + contentType = [self contentTypeForPathExtension: extension]; + } + } return contentType; } @@ -301,7 +322,7 @@ static BOOL debugOn = NO; NSException *error; WOResponse *r; NSData *data; - NSString *etag, *mimeType; + NSString *etag, *mimeType, *fileName; if ((error = [self matchesRequestConditionInContext:_ctx]) != nil) { // TODO: currently we fetch the body structure to get here - check this! @@ -333,6 +354,17 @@ static BOOL debugOn = NO; [r setHeader: mimeType forKey:@"content-type"]; [r setHeader: [NSString stringWithFormat:@"%d", [data length]] forKey: @"content-length"]; + + if (asAttachment) { + fileName = [[[self partInfo] objectForKey: @"parameterList"] objectForKey: @"name"]; + if (!fileName) + fileName = [[[[self partInfo] objectForKey: @"disposition"] + objectForKey: @"parameterList"] + objectForKey: @"filename"]; + if ([fileName length]) + [r setHeader: [NSString stringWithFormat: @"attachment; filename=%@", fileName] + forKey: @"content-disposition"]; + } if ((etag = [self davEntityTag]) != nil) [r setHeader:etag forKey:@"etag"]; diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index d745a6384..5e348b6a4 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -148,7 +148,7 @@ "Create Filter From Message..." = "Create Filter From Message..."; /* Image Popup menu */ -"View Image" = "View Image"; +"Save Image" = "Save Image"; /* Mailbox popup menus */ "Open in New Mail Window" = "Open in New Mail Window"; diff --git a/UI/MailerUI/French.lproj/Localizable.strings b/UI/MailerUI/French.lproj/Localizable.strings index 46d1e9160..f2c4d6797 100644 --- a/UI/MailerUI/French.lproj/Localizable.strings +++ b/UI/MailerUI/French.lproj/Localizable.strings @@ -149,7 +149,7 @@ "Create Filter From Message..." = "Créer un filtre à partir du message..."; /* Image Popup menu */ -"View Image" = "Voir l'image"; +"Save Image" = "Enregistrer l'image"; /* Mailbox popup menus */ "Open in New Mail Window" = "Ouvrir dans une nouvelle fenétre"; diff --git a/UI/MailerUI/German.lproj/Localizable.strings b/UI/MailerUI/German.lproj/Localizable.strings index 217481932..b0b8dcef6 100644 --- a/UI/MailerUI/German.lproj/Localizable.strings +++ b/UI/MailerUI/German.lproj/Localizable.strings @@ -132,7 +132,7 @@ "Create Filter From Message..." = "Filter aus Nachricht erstellen..."; /* Image Popup menu */ -"View Image" = "View Image"; +"Save Image" = "Save Image"; /* Mailbox popup menus */ "Open in New Mail Window" = "In neuem Fenster öffnen"; diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox index 2e555aed1..355c89998 100644 --- a/UI/Templates/MailerUI/UIxMailMainFrame.wox +++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox @@ -173,7 +173,7 @@ diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 2f29b7f9d..97a2a289e 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -985,9 +985,12 @@ function onMenuViewMessageSource(event) { preventDefault(event); } -function viewImage(event) { +function saveImage(event) { var img = document.menuTarget; - window.open(img.getAttribute("src"),'_blank','resizable=1'); + var url = img.getAttribute("src"); + var urlAsAttachment = url.replace(/(\/[^\/]*)$/,"/asAttachment$1"); + + window.location.href = urlAsAttachment; } /* contacts */ @@ -1742,7 +1745,7 @@ function getMenus() { "mark-menu", "-", null, null, onMenuDeleteMessage); - menus["imageMenu"] = new Array(viewImage); + menus["imageMenu"] = new Array(saveImage); menus["messageContentMenu"] = new Array(onMenuReplyToSender, onMenuReplyToAll, onMenuForwardMessage,