mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-08 00:13:21 +00:00
fix(mail): pick proper "from" address when replying/forwarding
Fixes #5056
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
#import <Mailer/SOGoDraftObject.h>
|
||||
#import <Mailer/SOGoDraftsFolder.h>
|
||||
#import <SOGo/NSArray+Utilities.h>
|
||||
#import <SOGo/NSDictionary+Utilities.h>
|
||||
#import <SOGo/NSObject+Utilities.h>
|
||||
#import <SOGo/NSString+Utilities.h>
|
||||
#import <SOGo/SOGoDomainDefaults.h>
|
||||
@@ -98,19 +99,34 @@
|
||||
|
||||
/* compose */
|
||||
|
||||
- (NSString *) _emailFromIdentity: (NSDictionary *) identity
|
||||
{
|
||||
NSString *fullName, *format;
|
||||
|
||||
fullName = [identity objectForKey: @"fullName"];
|
||||
if ([fullName length])
|
||||
format = @"%{fullName} <%{email}>";
|
||||
else
|
||||
format = @"%{email}";
|
||||
|
||||
return [identity keysWithFormat: format];
|
||||
}
|
||||
|
||||
- (WOResponse *) composeAction
|
||||
{
|
||||
BOOL save, isHTML;
|
||||
NSDictionary *data, *identity;
|
||||
NSMutableDictionary *headers;
|
||||
NSString *accountName, *mailboxName, *messageName;
|
||||
NSString *value, *signature, *nl, *space;
|
||||
SOGoDraftObject *newDraftMessage;
|
||||
NSMutableDictionary *headers;
|
||||
NSDictionary *data;
|
||||
NSString *accountName, *mailboxName, *messageName;
|
||||
SOGoDraftsFolder *drafts;
|
||||
SOGoMailAccount *co;
|
||||
SOGoUserDefaults *ud;
|
||||
id mailTo;
|
||||
BOOL save, isHTML;
|
||||
|
||||
drafts = [[self clientObject] draftsFolderInContext: context];
|
||||
co = [self clientObject];
|
||||
drafts = [co draftsFolderInContext: context];
|
||||
newDraftMessage = [drafts newDraft];
|
||||
headers = [NSMutableDictionary dictionary];
|
||||
|
||||
@@ -134,25 +150,30 @@
|
||||
save = YES;
|
||||
}
|
||||
|
||||
if (save)
|
||||
[newDraftMessage setHeaders: headers];
|
||||
|
||||
signature = [[self clientObject] signature];
|
||||
if ([signature length])
|
||||
identity = [co defaultIdentity];
|
||||
if (identity)
|
||||
{
|
||||
ud = [[context activeUser] userDefaults];
|
||||
[newDraftMessage setIsHTML: [[ud mailComposeMessageType] isEqualToString: @"html"]];
|
||||
isHTML = [newDraftMessage isHTML];
|
||||
nl = (isHTML? @"<br />" : @"\n");
|
||||
space = (isHTML ? @" " : @" ");
|
||||
|
||||
[newDraftMessage setText: [NSString stringWithFormat: @"%@%@--%@%@%@", nl, nl, space, nl, signature]];
|
||||
[headers setObject: [self _emailFromIdentity: identity] forKey: @"from"];
|
||||
signature = [identity objectForKey: @"signature"];
|
||||
if ([signature length])
|
||||
{
|
||||
ud = [[context activeUser] userDefaults];
|
||||
[newDraftMessage setIsHTML: [[ud mailComposeMessageType] isEqualToString: @"html"]];
|
||||
isHTML = [newDraftMessage isHTML];
|
||||
nl = (isHTML? @"<br />" : @"\n");
|
||||
space = (isHTML ? @" " : @" ");
|
||||
[newDraftMessage setText: [NSString stringWithFormat: @"%@%@--%@%@%@", nl, nl, space, nl, signature]];
|
||||
}
|
||||
save = YES;
|
||||
}
|
||||
if (save)
|
||||
[newDraftMessage storeInfo];
|
||||
|
||||
accountName = [[self clientObject] nameInContainer];
|
||||
if (save)
|
||||
{
|
||||
[newDraftMessage setHeaders: headers];
|
||||
[newDraftMessage storeInfo];
|
||||
}
|
||||
|
||||
accountName = [co nameInContainer];
|
||||
mailboxName = [drafts absoluteImap4Name]; // Ex: /INBOX/Drafts/
|
||||
mailboxName = [mailboxName substringWithRange: NSMakeRange(1, [mailboxName length] -2)];
|
||||
messageName = [newDraftMessage nameInContainer];
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
NSString *sourceUID;
|
||||
NSString *sourceFolder;
|
||||
NSString *text;
|
||||
NSMutableArray *fromEMails;
|
||||
NSString *from;
|
||||
SOGoMailFolder *sentFolder;
|
||||
BOOL isHTML;
|
||||
@@ -122,7 +121,6 @@ static NSArray *infoKeys = nil;
|
||||
[priority release];
|
||||
[receipt release];
|
||||
[sentFolder release];
|
||||
[fromEMails release];
|
||||
[from release];
|
||||
[text release];
|
||||
[subject release];
|
||||
@@ -256,7 +254,7 @@ static NSArray *infoKeys = nil;
|
||||
identities = [[[self clientObject] mailAccountFolder] identities];
|
||||
if ([identities count])
|
||||
{
|
||||
if (from)
|
||||
if ([from length])
|
||||
{
|
||||
allIdentities = [identities objectEnumerator];
|
||||
valid = NO;
|
||||
@@ -278,11 +276,6 @@ static NSArray *infoKeys = nil;
|
||||
from = nil;
|
||||
}
|
||||
}
|
||||
if (!from)
|
||||
{
|
||||
from = [self _emailFromIdentity: [[context activeUser] defaultIdentity]];
|
||||
[from retain];
|
||||
}
|
||||
}
|
||||
|
||||
return from;
|
||||
@@ -413,31 +406,6 @@ static NSArray *infoKeys = nil;
|
||||
return [UIxMailSizeFormatter sharedMailSizeFormatter];
|
||||
}
|
||||
|
||||
/* from addresses */
|
||||
|
||||
- (NSArray *) fromEMails
|
||||
{
|
||||
NSArray *identities;
|
||||
int count, max;
|
||||
NSString *email;
|
||||
SOGoMailAccount *account;
|
||||
|
||||
if (!fromEMails)
|
||||
{
|
||||
account = [[self clientObject] mailAccountFolder];
|
||||
identities = [account identities];
|
||||
max = [identities count];
|
||||
fromEMails = [[NSMutableArray alloc] initWithCapacity: max];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
email = [self _emailFromIdentity: [identities objectAtIndex: count]];
|
||||
[fromEMails addObjectUniquely: email];
|
||||
}
|
||||
}
|
||||
|
||||
return fromEMails;
|
||||
}
|
||||
|
||||
/* info loading */
|
||||
|
||||
- (void) loadInfo: (NSDictionary *) _info
|
||||
|
||||
@@ -443,7 +443,7 @@
|
||||
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;
|
||||
return data.from && data.from.toLowerCase().indexOf(identity.email) !== -1;
|
||||
});
|
||||
if (identity)
|
||||
data.from = identity.full;
|
||||
|
||||
Reference in New Issue
Block a user