From 11adf388cf2b276356a6ab3051425442232f9992 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 17 Sep 2014 11:51:46 -0400 Subject: [PATCH] Cleaned the code and fixed #2894 while at it ... --- .../Appointments/SOGoAppointmentFolder.m | 1 + SoObjects/Mailer/SOGoDraftObject.m | 99 ++++++++++--------- SoObjects/Mailer/product.plist | 2 +- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index f366ad4d5..0f2bd879f 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -2369,6 +2369,7 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir valueForObject: @"" attributes: nil]]; + // See bugs #2878 and #2879 [components addObject: [SOGoWebDAVValue valueForObject: @"" attributes: nil]]; diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index b1cb2a2cc..24b84e8bd 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -45,6 +45,7 @@ #import #import #import +#import #import #import #import @@ -1781,62 +1782,62 @@ static NSString *userAgent = nil; - (NSException *) sendMail { SOGoUserDefaults *ud; + ud = [[context activeUser] userDefaults]; if ([ud mailAddOutgoingAddresses]) - { - Class contactGCSEntry; - SOGoContactFolders *contactFolders; - SOGoContactFolder *folder; - SOGoContactGCSEntry *newContact; - NGVCard *card; - NGMailAddressParser *parser; - NSArray *matchingContacts; - NSMutableArray *recipients; - NSString *recipient, *emailAddress, *addressBook, *uid; - id parsedRecipient; - int i; + { + NSString *recipient, *emailAddress, *addressBook, *uid; + NSArray *matchingContacts, *recipients; + SOGoContactFolders *contactFolders; + SOGoContactGCSEntry *newContact; + NGMailAddress *parsedRecipient; + NGMailAddressParser *parser; + SOGoContactFolder *folder; + NGVCard *card; + + int i; - // Get all the addressbooks - contactFolders = [[[context activeUser] homeFolderInContext: context] - lookupName: @"Contacts" - inContext: context - acquire: NO]; - // Get all the recipients from the current email - recipients = [self allRecipients]; - for (i = 0; i < [recipients count]; i++) - { - // The address contains a string. ex: "John Doe " - recipient = [recipients objectAtIndex: i]; - parser = [NGMailAddressParser mailAddressParserWithString: recipient]; - parsedRecipient = [parser parse]; - emailAddress = [parsedRecipient address]; + // Get all the addressbooks + contactFolders = [[[context activeUser] homeFolderInContext: context] + lookupName: @"Contacts" + inContext: context + acquire: NO]; + // Get all the recipients from the current email + recipients = [self allRecipients]; + for (i = 0; i < [recipients count]; i++) + { + // The address contains a string. ex: "John Doe " + recipient = [recipients objectAtIndex: i]; + parser = [NGMailAddressParser mailAddressParserWithString: recipient]; + parsedRecipient = [parser parse]; + emailAddress = [parsedRecipient address]; - matchingContacts = [contactFolders allContactsFromFilter: emailAddress - excludeGroups: YES - excludeLists: YES]; - } - // If we don't get any results from the autocompletion code, we add it.. - if ([matchingContacts count] == 0) - { - // Get the selected addressbook from the user preferences where the new address will be added - addressBook = [ud selectedAddressBook]; - folder = [contactFolders lookupName: addressBook inContext: context acquire: NO]; - uid = [folder globallyUniqueObjectId]; + matchingContacts = [contactFolders allContactsFromFilter: emailAddress + excludeGroups: YES + excludeLists: YES]; + } + // If we don't get any results from the autocompletion code, we add it.. + if ([matchingContacts count] == 0) + { + // Get the selected addressbook from the user preferences where the new address will be added + addressBook = [ud selectedAddressBook]; + folder = [contactFolders lookupName: addressBook inContext: context acquire: NO]; + uid = [folder globallyUniqueObjectId]; - if (folder && uid) - { - card = [NGVCard cardWithUid: uid]; - [card addEmail: emailAddress types: nil]; - - contactGCSEntry = NSClassFromString(@"SOGoContactGCSEntry"); - newContact = [contactGCSEntry objectWithName: uid - inContainer: folder]; - [newContact setIsNew: YES]; - [newContact saveComponent: card]; - } + if (folder && uid) + { + card = [NGVCard cardWithUid: uid]; + [card addEmail: emailAddress types: nil]; + [card setFn: [parsedRecipient displayName]]; + + newContact = [SOGoContactGCSEntry objectWithName: uid + inContainer: folder]; + [newContact setIsNew: YES]; + [newContact saveComponent: card]; + } + } } - } return [self sendMailAndCopyToSent: YES]; } diff --git a/SoObjects/Mailer/product.plist b/SoObjects/Mailer/product.plist index 42249f727..c477a1d73 100644 --- a/SoObjects/Mailer/product.plist +++ b/SoObjects/Mailer/product.plist @@ -1,5 +1,5 @@ { - requires = ( MAIN ); + requires = ( MAIN, Contacts ); publicResources = ( );