diff --git a/NEWS b/NEWS index b392c230e..c68be4a39 100644 --- a/NEWS +++ b/NEWS @@ -50,6 +50,7 @@ Bug fixes - [web] retired CSS reset so the style of HTML messages is respected (#3582) - [web] fixed messages archiving as zip file - [web] adapted time picker to match changes of md calendar picker + - [web] fixed sender addresses of draft when using multiple IMAP accounts (#3577) - [dav] we now handle the default classifications for tasks (#3541) - [eas] properly unfold long mail headers (#3152) - [eas] correctly set EAS message class for S/MIME messages (#3576) diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index 2baea9791..465b232bb 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -924,6 +924,10 @@ static NSString *userAgent = nil; [info setObject: msgid forKey: @"message-id"]; addresses = [NSMutableArray array]; + [self _addEMailsOfAddresses: [sourceEnvelope from] toArray: addresses]; + if ([addresses count]) + [info setObject: [addresses objectAtIndex: 0] forKey: @"from"]; + addresses = [NSMutableArray array]; [self _addEMailsOfAddresses: [sourceEnvelope to] toArray: addresses]; [info setObject: addresses forKey: @"to"]; addresses = [NSMutableArray array]; diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index 0cf8c1ea8..39684a935 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -250,13 +250,16 @@ static NSArray *infoKeys = nil; - (NSString *) from { - NSDictionary *identity; + NSArray *identities; if (!from) { - identity = [[context activeUser] primaryIdentity]; - from = [self _emailFromIdentity: identity]; - [from retain]; + identities = [[[self clientObject] mailAccountFolder] identities]; + if ([identities count]) + { + from = [self _emailFromIdentity: [identities objectAtIndex: 0]]; + [from retain]; + } } return from; @@ -426,7 +429,7 @@ static NSArray *infoKeys = nil; { if (![_info isNotNull]) return; [self debugWithFormat:@"loading info ..."]; - [self setValuesForKeysWithDictionary:_info]; + [self setValuesForKeysWithDictionary: _info]; } - (NSDictionary *) infoFromRequest @@ -439,6 +442,7 @@ static NSArray *infoKeys = nil; filteredParams = [NSDictionary dictionaryWithObjects: [params objectsForKeys: infoKeys notFoundMarker: [NSNull null]] forKeys: infoKeys]; + [self setFrom: [filteredParams objectForKey: @"from"]]; [self setTo: [filteredParams objectForKey: @"to"]]; [self setCc: [filteredParams objectForKey: @"cc"]]; [self setBcc: [filteredParams objectForKey: @"bcc"]]; diff --git a/UI/WebServerResources/js/Mailer/MailboxController.js b/UI/WebServerResources/js/Mailer/MailboxController.js index 8f365e6a6..b5f2c6921 100644 --- a/UI/WebServerResources/js/Mailer/MailboxController.js +++ b/UI/WebServerResources/js/Mailer/MailboxController.js @@ -218,7 +218,7 @@ controller: 'MessageEditorController', controllerAs: 'editor', locals: { - stateAccounts: vm.accounts, + stateAccount: vm.account, stateMessage: message, stateRecipients: [] } diff --git a/UI/WebServerResources/js/Mailer/Message.service.js b/UI/WebServerResources/js/Mailer/Message.service.js index 06b9c4312..1eb0cf9f5 100644 --- a/UI/WebServerResources/js/Mailer/Message.service.js +++ b/UI/WebServerResources/js/Mailer/Message.service.js @@ -103,23 +103,26 @@ * @returns a string representing the path relative to the mail module */ Message.prototype.$absolutePath = function(options) { - if (angular.isUndefined(this.id) || options) { + var _this = this, id = this.id; + + function buildPath() { var path; - path = _.map(this.$mailbox.path.split('/'), function(component) { + path = _.map(_this.$mailbox.path.split('/'), function(component) { return 'folder' + component.asCSSIdentifier(); }); - path.splice(0, 0, this.accountId); // insert account ID - if (options && options.asDraft && this.draftId) { - path.push(this.draftId); // add draft ID - } - else { - path.push(this.uid); // add message UID - } - - this.id = path.join('/'); + path.splice(0, 0, _this.accountId); // insert account ID + return path.join('/'); } - return this.id; + if (angular.isUndefined(this.id) || options && options.nocache) { + this.id = buildPath() + '/' + this.uid; // add message UID + id = this.id; + } + if (options && options.asDraft && this.draftId) { + id = buildPath() + '/' + this.draftId; // add draft ID + } + + return id; }; /** @@ -129,15 +132,22 @@ * @param {number} uid - the new message UID */ Message.prototype.$setUID = function(uid) { - var oldUID = (this.uid || -1); + var oldUID = (this.uid || -1), _this = this, index; if (oldUID != parseInt(uid)) { this.uid = parseInt(uid); + this.$absolutePath({nocache: true}); if (oldUID > -1) { oldUID = oldUID.toString(); if (angular.isDefined(this.$mailbox.uidsMap[oldUID])) { - this.$mailbox.uidsMap[uid] = this.$mailbox.uidsMap[oldUID]; + index = this.$mailbox.uidsMap[oldUID]; + this.$mailbox.uidsMap[uid] = index; delete this.$mailbox.uidsMap[oldUID]; + + // Update messages list of mailbox + _.forEach(['from', 'to', 'subject'], function(attr) { + _this.$mailbox.$messages[index][attr] = _this[attr]; + }); } } else { @@ -365,6 +375,12 @@ return Message.$$resource.fetch(this.$absolutePath(), 'edit').then(function(data) { angular.extend(_this, data); return Message.$$resource.fetch(_this.$absolutePath({asDraft: true}), 'edit').then(function(data) { + // Try to match a known account identity from the specified "from" address + var identity = _.find(_this.$mailbox.$account.identities, function(identity) { + return data.from.toLowerCase().indexOf(identity.email) !== -1; + }); + if (identity) + data.from = identity.full; Message.$log.debug('editable = ' + JSON.stringify(data, undefined, 2)); angular.extend(_this.editable, data); return data.text; @@ -580,7 +596,7 @@ return Message.$$resource.save(this.$absolutePath({asDraft: true}), data).then(function(response) { Message.$log.debug('save = ' + JSON.stringify(response, undefined, 2)); _this.$setUID(response.uid); - _this.$reload({asDraft: false}); // fetch a new viewable version of the message + _this.$reload(); // fetch a new viewable version of the message _this.isNew = false; }); }; diff --git a/UI/WebServerResources/js/Mailer/MessageEditorController.js b/UI/WebServerResources/js/Mailer/MessageEditorController.js index 64f86cd7c..4d0503b18 100644 --- a/UI/WebServerResources/js/Mailer/MessageEditorController.js +++ b/UI/WebServerResources/js/Mailer/MessageEditorController.js @@ -6,8 +6,8 @@ /** * @ngInject */ - MessageEditorController.$inject = ['$window', '$stateParams', '$mdConstant', '$mdDialog', '$mdToast', 'FileUploader', 'stateAccounts', 'stateMessage', 'stateRecipients', 'encodeUriFilter', '$timeout', 'Dialog', 'AddressBook', 'Card', 'Preferences']; - function MessageEditorController($window, $stateParams, $mdConstant, $mdDialog, $mdToast, FileUploader, stateAccounts, stateMessage, stateRecipients, encodeUriFilter, $timeout, Dialog, AddressBook, Card, Preferences) { + MessageEditorController.$inject = ['$window', '$stateParams', '$mdConstant', '$mdDialog', '$mdToast', 'FileUploader', 'stateAccount', 'stateMessage', 'stateRecipients', 'encodeUriFilter', '$timeout', 'Dialog', 'AddressBook', 'Card', 'Preferences']; + function MessageEditorController($window, $stateParams, $mdConstant, $mdDialog, $mdToast, FileUploader, stateAccount, stateMessage, stateRecipients, encodeUriFilter, $timeout, Dialog, AddressBook, Card, Preferences) { var vm = this, semicolon = 186; vm.addRecipient = addRecipient; @@ -21,7 +21,7 @@ vm.send = send; vm.removeAttachment = removeAttachment; vm.contactFilter = contactFilter; - vm.identities = _.map(_.flatten(_.map(stateAccounts, 'identities')), 'full'); + vm.identities = _.map(stateAccount.identities, 'full'); vm.recipientSeparatorKeys = [$mdConstant.KEY_CODE.ENTER, $mdConstant.KEY_CODE.TAB, $mdConstant.KEY_CODE.COMMA, semicolon]; vm.uploader = new FileUploader({ url: stateMessage.$absolutePath({asDraft: true}) + '/save',