From 948a1f1c991fae91ff71458dbe95ee26f7100b47 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 16 Dec 2014 15:47:34 -0500 Subject: [PATCH] Improve webmail editor - Fixed handling of saving drafts - Fixed handling of message type (HTML/plain) - Added primitive handling of attachments --- UI/MailerUI/UIxMailAccountActions.m | 4 +- UI/MailerUI/UIxMailEditor.m | 77 ++++++++++++------- UI/MailerUI/UIxMailView.m | 14 ---- UI/Templates/MailerUI/UIxMailEditor.wox | 12 +++ UI/WebServerResources/bower.json | 1 + .../js/Mailer/account-model.js | 36 ++++++++- .../js/Mailer/mailbox-model.js | 2 +- .../js/Mailer/message-model.js | 52 +++++++++---- 8 files changed, 137 insertions(+), 61 deletions(-) diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index 7c6c103e8..2b5795f06 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -1,6 +1,6 @@ /* UIxMailAccountActions.m - this file is part of SOGo * - * Copyright (C) 2007-2013 Inverse inc. + * Copyright (C) 2007-2014 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -126,7 +126,7 @@ data = [NSDictionary dictionaryWithObjectsAndKeys: accountName, @"accountId", mailboxName, @"mailboxPath", - messageName, @"uid", nil]; + messageName, @"draftId", nil]; return [self responseWithStatus: 201 andString: [data jsonRepresentation]]; diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index eab72e820..901d74f23 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -113,7 +113,7 @@ static NSArray *infoKeys = nil; @"subject", @"to", @"cc", @"bcc", @"from", @"inReplyTo", @"replyTo", - @"priority", @"receipt", + @"priority", @"receipt", @"isHTML", @"text", nil]; } @@ -439,7 +439,7 @@ static NSArray *infoKeys = nil; [self setValuesForKeysWithDictionary:_info]; } -- (NSDictionary *) storeInfo +- (NSDictionary *) infoFromRequest { WORequest *request; NSDictionary *params, *filteredParams; @@ -452,6 +452,7 @@ static NSArray *infoKeys = nil; [self setTo: [filteredParams objectForKey: @"to"]]; [self setCc: [filteredParams objectForKey: @"cc"]]; [self setBcc: [filteredParams objectForKey: @"bcc"]]; + [self setIsHTML: [[filteredParams objectForKey: @"isHTML"] boolValue]]; [self setText: [filteredParams objectForKey: @"text"]]; return filteredParams; @@ -592,46 +593,53 @@ static NSArray *infoKeys = nil; WORequest *request; NSEnumerator *allAttachments; NSDictionary *attrs, *filenames; - NGMimeType *mimeType; id httpBody; SOGoDraftObject *co; error = nil; request = [context request]; - mimeType = [[request httpRequest] contentType]; - if ([[mimeType type] isEqualToString: @"multipart"]) - { - httpBody = [[request httpRequest] body]; - filenames = [self _scanAttachmentFilenamesInRequest: httpBody]; + httpBody = [[request httpRequest] body]; + filenames = [self _scanAttachmentFilenamesInRequest: httpBody]; - co = [self clientObject]; - allAttachments = [filenames objectEnumerator]; - while ((attrs = [allAttachments nextObject]) && !error) - { - error = [co saveAttachment: (NSData *) [attrs objectForKey: @"body"] - withMetadata: attrs]; - // Keep the name of the last attachment saved - ASSIGN(currentAttachment, [attrs objectForKey: @"filename"]); - } + co = [self clientObject]; + allAttachments = [filenames objectEnumerator]; + while ((attrs = [allAttachments nextObject]) && !error) + { + error = [co saveAttachment: (NSData *) [attrs objectForKey: @"body"] + withMetadata: attrs]; + // Keep the name of the last attachment saved + ASSIGN(currentAttachment, [attrs objectForKey: @"filename"]); } return error; } -- (NSException *) _saveFormInfo +/** + * Save received data to the filesystem, either the attached files or the message itself. + */ +- (NSException *) _saveRequestInfo { NSDictionary *info; NSException *error; + NGMimeType *mimeType; + WORequest *request; SOGoDraftObject *co; + error = nil; + request = [context request]; + mimeType = [[request httpRequest] contentType]; + co = [self clientObject]; [co fetchInfo]; - error = [self _saveAttachments]; - if (!error) + if ([[mimeType type] isEqualToString: @"multipart"]) { - info = [self storeInfo]; + error = [self _saveAttachments]; + } + else if ([[mimeType subType] isEqualToString: @"json"]) + { + info = [self infoFromRequest]; [co setHeaders: info]; [co setIsHTML: isHTML]; [co setText: (isHTML ? [NSString stringWithFormat: @"%@", text] : text)];; @@ -712,8 +720,9 @@ static NSArray *infoKeys = nil; [self setSourceFolder: [co sourceFolder]]; data = [NSMutableDictionary dictionaryWithObjectsAndKeys: - [self from], @"from", + [self from], @"from", [self localeCode], @"locale", + [NSNumber numberWithBool: [self isHTML]], @"isHTML", text, @"text", nil]; if ((value = [self replyTo])) @@ -740,19 +749,33 @@ static NSArray *infoKeys = nil; { id result; NSArray *attrs; + NSDictionary *data; + SOGoDraftObject *co; + co = [self clientObject]; [self setIsHTML: [self isHTML]]; - result = [self _saveFormInfo]; + + result = [self _saveRequestInfo]; if (!result) { - result = [[self clientObject] save]; + // Save message to IMAP server + result = [co save]; } if (!result) { + // Save new UID to plist + [self setSourceUID: [co IMAP4ID]]; + [co storeInfo]; + + // Prepare response attachmentAttrs = nil; attrs = [self attachmentAttrs]; + data = [NSDictionary dictionaryWithObjectsAndKeys: + [self sourceUID], @"uid", + attrs, @"lastAttachmentAttrs", + nil]; result = [self responseWithStatus: 200 - andString: [attrs jsonRepresentation]]; + andString: [data jsonRepresentation]]; } else result = [self failedToSaveFormResponse: [result reason]]; @@ -826,8 +849,8 @@ static NSArray *infoKeys = nil; co = [self clientObject]; - /* first, save form data */ - error = [self _saveFormInfo]; + // First, save form data to filesystem + error = [self _saveRequestInfo]; if (!error) { error = [self validateForSend]; diff --git a/UI/MailerUI/UIxMailView.m b/UI/MailerUI/UIxMailView.m index 8d7e2752e..299fa4f33 100644 --- a/UI/MailerUI/UIxMailView.m +++ b/UI/MailerUI/UIxMailView.m @@ -295,20 +295,6 @@ static NSString *mailETag = nil; if ((addresses = [addressFormatter dictionariesForArray: [co replyToEnvelopeAddresses]])) [data setObject: addresses forKey: @"reply-to"]; - if ([self mailIsDraft]) - { - SOGoMailAccount *account; - SOGoDraftsFolder *folder; - SOGoDraftObject *newMail; - - account = [co mailAccountFolder]; - folder = [account draftsFolderInContext: context]; - newMail = [folder newDraft]; - [newMail fetchMailForEditing: co]; - [newMail storeInfo]; - [data setObject: [newMail nameInContainer] forKey: @"draftId"]; - } - response = [self responseWithStatus: 200 andString: [data jsonRepresentation]]; diff --git a/UI/Templates/MailerUI/UIxMailEditor.wox b/UI/Templates/MailerUI/UIxMailEditor.wox index e6fba33bb..a3caae396 100644 --- a/UI/Templates/MailerUI/UIxMailEditor.wox +++ b/UI/Templates/MailerUI/UIxMailEditor.wox @@ -19,6 +19,18 @@ + +