From 76307cfaafd886f053b4f5f6436f1412f7148c83 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Mon, 24 Mar 2014 13:41:57 -0400 Subject: [PATCH] New feature : 1496; Unknown outgoing email addresses can now be automatically be added to your address books. --- .../English.lproj/Localizable.strings | 1 + SoObjects/Contacts/SOGoContactFolders.h | 8 + SoObjects/Contacts/SOGoContactFolders.m | 193 +++++++++++++++++- SoObjects/Mailer/SOGoDraftObject.h | 2 + SoObjects/Mailer/SOGoDraftObject.m | 73 ++++++- SoObjects/SOGo/SOGoDefaults.plist | 1 + SoObjects/SOGo/SOGoParentFolder.m | 31 +-- SoObjects/SOGo/SOGoUserDefaults.h | 6 + SoObjects/SOGo/SOGoUserDefaults.m | 25 ++- UI/Contacts/UIxContactFoldersView.m | 83 +------- .../English.lproj/Localizable.strings | 2 + UI/PreferencesUI/UIxPreferences.m | 64 ++++++ UI/Templates/PreferencesUI/UIxPreferences.wox | 10 + 13 files changed, 405 insertions(+), 94 deletions(-) diff --git a/SoObjects/Contacts/English.lproj/Localizable.strings b/SoObjects/Contacts/English.lproj/Localizable.strings index 56404b013..0d040749c 100644 --- a/SoObjects/Contacts/English.lproj/Localizable.strings +++ b/SoObjects/Contacts/English.lproj/Localizable.strings @@ -1 +1,2 @@ "Personal Address Book" = "Personal Address Book"; +"Collected Address Book" = "Collected Address Book"; diff --git a/SoObjects/Contacts/SOGoContactFolders.h b/SoObjects/Contacts/SOGoContactFolders.h index 1b685c85b..584fab024 100644 --- a/SoObjects/Contacts/SOGoContactFolders.h +++ b/SoObjects/Contacts/SOGoContactFolders.h @@ -25,12 +25,20 @@ @interface SOGoContactFolders : SOGoParentFolder +- (NSString *) defaultFolderName; +- (NSString *) collectedFolderName; + +- (NSException *) appendCollectedSources; - (NSException *) renameLDAPAddressBook: (NSString *) sourceID withDisplayName: (NSString *) newDisplayName; - (NSException *) removeLDAPAddressBook: (NSString *) sourceID; - (NSDictionary *) systemSources; +- (NSArray *) allContactsFromFilter: (NSString *) theFilter + excludeGroups: (BOOL) excludeGroups + excludeLists: (BOOL) excludeLists; + @end #endif /* SOGOCONTACTFOLDERS_H */ diff --git a/SoObjects/Contacts/SOGoContactFolders.m b/SoObjects/Contacts/SOGoContactFolders.m index 3c3e938f0..183d47e32 100644 --- a/SoObjects/Contacts/SOGoContactFolders.m +++ b/SoObjects/Contacts/SOGoContactFolders.m @@ -22,12 +22,18 @@ #import #import #import +#import #import #import #import #import +#import +#import +#import +#import + #import #import #import @@ -40,10 +46,17 @@ #import "SOGoContactFolders.h" +Class SOGoContactSourceFolderK; + #define XMLNS_INVERSEDAV @"urn:inverse:params:xml:ns:inverse-dav" @implementation SOGoContactFolders ++ (void) initialize +{ + SOGoContactSourceFolderK = [SOGoContactSourceFolder class]; +} + + (NSString *) gcsFolderType { return @"Contact"; @@ -110,6 +123,92 @@ return result; } +- (void) _createCollectedFolder +{ + NSArray *roles; + SOGoGCSFolder *folder; + SOGoUser *folderOwner; + + roles = [[context activeUser] rolesForObject: self inContext: context]; + folderOwner = [SOGoUser userWithLogin: [self ownerInContext: context]]; + + if (folderOwner && [folderOwner isResource]) + { + folder = [subFolderClass objectWithName: @"collected" inContainer: self]; + [folder setDisplayName: [self collectedFolderName]]; + [folder setOCSPath: [NSString stringWithFormat: @"%@/collected", OCSPath]]; + if ([folder create]) + [subFolders setObject: folder forKey: @"collected"]; + } +} + +- (NSException *) _fetchCollectedFolders: (NSString *) sql + withChannel: (EOAdaptorChannel *) fc +{ + NSArray *attrs; + NSDictionary *row; + SOGoGCSFolder *folder; + NSString *key; + NSException *error; + + if (!subFolderClass) + subFolderClass = [[self class] subFolderClass]; + + error = [fc evaluateExpressionX: sql]; + if (!error) + { + attrs = [fc describeResults: NO]; + while ((row = [fc fetchAttributes: attrs withZone: NULL])) + { + key = [row objectForKey: @"c_path4"]; + if ([key isKindOfClass: [NSString class]]) + { + folder = [subFolderClass objectWithName: key inContainer: self]; + [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", + OCSPath, key]]; + [subFolders setObject: folder forKey: key]; + } + } + + if (![subFolders objectForKey: @"collected"]) + [self _createCollectedFolder]; + } + + return error; +} + +- (NSException *) appendCollectedSources +{ + GCSChannelManager *cm; + EOAdaptorChannel *fc; + NSURL *folderLocation; + NSString *sql, *gcsFolderType; + NSException *error; + + cm = [GCSChannelManager defaultChannelManager]; + folderLocation = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; + fc = [cm acquireOpenChannelForURL: folderLocation]; + if ([fc isOpen]) + { + gcsFolderType = [[self class] gcsFolderType]; + + sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@" + @" WHERE c_path2 = '%@'" + @" AND c_folder_type = '%@'"), + [folderLocation gcsTableName], + owner, + gcsFolderType]; + error = [self _fetchCollectedFolders: sql withChannel: fc]; + [cm releaseChannel: fc]; + } + else + error = [NSException exceptionWithName: @"SOGoDBException" + reason: @"database connection could not be open" + userInfo: nil]; + + return error; +} + - (NSDictionary *) systemSources { NSMutableDictionary *systemSources; @@ -223,9 +322,9 @@ SOGoUser *currentUser; id source; - if ([sourceID isEqualToString: @"personal"]) + if ([sourceID isEqualToString: @"personal"] || [sourceID isEqualToString: @"collected"]) result = [NSException exceptionWithHTTPStatus: 403 - reason: @"folder 'personal' cannot be deleted"]; + reason: (@"folder '%@' cannot be deleted", sourceID)]; else { result = nil; @@ -250,6 +349,11 @@ return [self labelForKey: @"Personal Address Book"]; } +- (NSString *) collectedFolderName +{ + return [self labelForKey: @"Collected Address Book"]; +} + - (NSArray *) toManyRelationshipKeys { NSMutableArray *keys; @@ -371,4 +475,89 @@ asWebDAVValue]; } +- (NSArray *) allContactsFromFilter: (NSString *) theFilter + excludeGroups: (BOOL) excludeGroups + excludeLists: (BOOL) excludeLists +{ + SOGoFolder *folder; + NSString *mail, *domain; + NSArray *folders, *contacts, *descriptors, *sortedContacts; + NSMutableArray *sortedFolders; + NSMutableDictionary *contact, *uniqueContacts; + unsigned int i, j, max; + NSSortDescriptor *commonNameDescriptor; + + // NSLog(@"Search all contacts: %@", searchText); + + domain = [[context activeUser] domain]; + folders = nil; + NS_DURING + folders = [self subFolders]; + NS_HANDLER + /* We need to specifically test for @"SOGoDBException", which is + raised explicitly in SOGoParentFolder. Any other exception should + be re-raised. */ + if ([[localException name] isEqualToString: @"SOGoDBException"]) + folders = nil; + else + [localException raise]; + NS_ENDHANDLER; + max = [folders count]; + sortedFolders = [NSMutableArray arrayWithCapacity: max]; + uniqueContacts = [NSMutableDictionary dictionary]; + for (i = 0; i < max; i++) + { + folder = [folders objectAtIndex: i]; + /* We first search in LDAP folders (in case of duplicated entries in GCS folders) */ + if ([folder isKindOfClass: SOGoContactSourceFolderK]) + [sortedFolders insertObject: folder atIndex: 0]; + else + [sortedFolders addObject: folder]; + } + for (i = 0; i < max; i++) + { + folder = [sortedFolders objectAtIndex: i]; + //NSLog(@" Address book: %@ (%@)", [folder displayName], [folder class]); + contacts = [folder lookupContactsWithFilter: theFilter + onCriteria: @"name_or_address" + sortBy: @"c_cn" + ordering: NSOrderedAscending + inDomain: domain]; + for (j = 0; j < [contacts count]; j++) + { + contact = [contacts objectAtIndex: j]; + mail = [contact objectForKey: @"c_mail"]; + //NSLog(@" found %@ (%@) ? %@", [contact objectForKey: @"c_name"], mail, + // [contact description]); + if (!excludeLists && [[contact objectForKey: @"c_component"] + isEqualToString: @"vlist"]) + { + [contact setObject: [folder nameInContainer] + forKey: @"container"]; + [uniqueContacts setObject: contact + forKey: [contact objectForKey: @"c_name"]]; + } + else if ([mail length] + && [uniqueContacts objectForKey: mail] == nil + && !(excludeGroups && [contact objectForKey: @"isGroup"])) + [uniqueContacts setObject: contact forKey: mail]; + } + } + if ([uniqueContacts count] > 0) + { + // Sort the contacts by display name + commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn" + ascending:YES]; + descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil]; + [commonNameDescriptor release]; + sortedContacts = [[uniqueContacts allValues] + sortedArrayUsingDescriptors: descriptors]; + } + else + sortedContacts = [NSArray array]; + + return sortedContacts; +} + + @end diff --git a/SoObjects/Mailer/SOGoDraftObject.h b/SoObjects/Mailer/SOGoDraftObject.h index 94c5d2888..4004d32a9 100644 --- a/SoObjects/Mailer/SOGoDraftObject.h +++ b/SoObjects/Mailer/SOGoDraftObject.h @@ -102,6 +102,8 @@ - (NSData *) mimeMessageAsData; /* operations */ +- (NSArray *) allRecipients; +- (NSArray *) allBareRecipients; - (NSException *) delete; - (NSException *) sendMail; diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index bd5a0d469..9c6b0a120 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -45,6 +45,7 @@ #import #import #import +#import #import #import #import @@ -63,6 +64,11 @@ #import #import +#import + +#import +#import + #import "NSData+Mail.h" #import "NSString+Mail.h" #import "SOGoMailAccount.h" @@ -1660,7 +1666,7 @@ static NSString *userAgent = nil; { recipients = [headers objectForKey: fieldNames[count]]; if ([recipients count] > 0) - [allRecipients addObjectsFromArray: recipients]; + [allRecipients addObjectsFromArray: recipients]; } return allRecipients; @@ -1689,6 +1695,71 @@ static NSString *userAgent = nil; // - (NSException *) sendMail { + SOGoUserDefaults *ud; + ud = [[context activeUser] userDefaults]; + + if ([ud mailAddOutgoingAddresses]) { + NSMutableArray *recipients; + SOGoMailAccounts *folder; + NGMailAddressParser *parser; + SOGoContactFolders *contactFolders; + NSArray *contacts; + NSString *address, *mail, *name; + int i; + id parsedAddress; + + contactFolders = [[[context activeUser] homeFolderInContext: context] + lookupName: @"Contacts" + inContext: context + acquire: NO]; + + recipients = [self allRecipients]; + + for (i = 0; i < [recipients count]; i++) + { + // The address contains a string. ex: "John Doe " + address = [recipients objectAtIndex: i]; + + parser = [NGMailAddressParser mailAddressParserWithString: address]; + parsedAddress = [parser parse]; + + mail = [parsedAddress address]; + name = [parsedAddress displayName]; + + contacts = [contactFolders allContactsFromFilter: mail + excludeGroups: YES + excludeLists: YES]; + + // If we don't get any results from the autocompletion code, we add it.. + if ([contacts count] == 0) + { + SOGoContactFolder *folder; + Class c; + SOGoContactGCSEntry *contact; + NSString *uid; + NGVCard *card; + + /* Here I want the selected address book on the preferences. */ + NSString *addressBook; + addressBook = [ud selectedAddressBook]; + + folder = [contactFolders lookupName: addressBook inContext: context acquire: NO]; + uid = [folder globallyUniqueObjectId]; + + card = [NGVCard cardWithUid: uid]; + [card addEmail: mail types: nil]; + + c = NSClassFromString(@"SOGoContactGCSEntry"); + contact = [c objectWithName: uid + inContainer: folder]; + [contact setIsNew: YES]; + + [contact saveContentString: [card versitString]]; + + } + } + } + return [self sendMailAndCopyToSent: YES]; } diff --git a/SoObjects/SOGo/SOGoDefaults.plist b/SoObjects/SOGo/SOGoDefaults.plist index f9bb2fef0..5f13a4a70 100644 --- a/SoObjects/SOGo/SOGoDefaults.plist +++ b/SoObjects/SOGo/SOGoDefaults.plist @@ -52,6 +52,7 @@ SOGoIMAPServer = "localhost"; SOGoMailDomain = "localhost"; + SOGoSelectedAddressBook = "collected"; SOGoMailMessageCheck = "manually"; SOGoMailMessageForwarding = "inline"; SOGoMailReplyPlacement = "below"; diff --git a/SoObjects/SOGo/SOGoParentFolder.m b/SoObjects/SOGo/SOGoParentFolder.m index da5a1c5b5..330a186eb 100644 --- a/SoObjects/SOGo/SOGoParentFolder.m +++ b/SoObjects/SOGo/SOGoParentFolder.m @@ -221,20 +221,17 @@ static SoSecurityManager *sm = nil; NSException *error; cm = [GCSChannelManager defaultChannelManager]; - folderLocation - = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; + folderLocation = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; fc = [cm acquireOpenChannelForURL: folderLocation]; if ([fc isOpen]) { gcsFolderType = [[self class] gcsFolderType]; - sql - = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@" - @" WHERE c_path2 = '%@'" - @" AND c_folder_type = '%@'"), - [folderLocation gcsTableName], - owner, - gcsFolderType]; + sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@" + @" WHERE c_path2 = '%@'" + @" AND c_folder_type = '%@'"), + [folderLocation gcsTableName], owner, gcsFolderType]; + error = [self _fetchPersonalFolders: sql withChannel: fc]; [cm releaseChannel: fc]; // sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'", @@ -248,6 +245,7 @@ static SoSecurityManager *sm = nil; return error; } + - (NSException *) appendSystemSources { return nil; @@ -386,14 +384,17 @@ static SoSecurityManager *sm = nil; if (!subFolders) { subFolders = [NSMutableDictionary new]; - error = [self appendPersonalSources]; + error = [self appendPersonalSources]; if (!error) - error = [self appendSystemSources]; + if ([self respondsToSelector:@selector(appendCollectedSources)]) + error = [self appendCollectedSources]; + if (!error) + error = [self appendSystemSources]; // TODO : Not really a testcase, see function if (error) - { - [subFolders release]; - subFolders = nil; - } + { + [subFolders release]; + subFolders = nil; + } } else error = nil; diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 83d6c18bb..b8df5621b 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -87,6 +87,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (NSString *) language; /* mail */ +- (void) setMailAddOutgoingAddresses: (BOOL) newValue; +- (BOOL) mailAddOutgoingAddresses; + - (void) setMailShowSubscribedFoldersOnly: (BOOL) newValue; - (BOOL) mailShowSubscribedFoldersOnly; @@ -111,6 +114,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setMailListViewColumnsOrder: (NSArray *) newValue; - (NSArray *) mailListViewColumnsOrder; +- (void) setSelectedAddressBook: (NSString *) newValue; +- (NSString *) selectedAddressBook; + - (void) setMailMessageCheck: (NSString *) newValue; - (NSString *) mailMessageCheck; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index b862c5523..d6d1c3999 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -185,8 +185,8 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; { migratedKeys = [NSDictionary dictionaryWithObjectsAndKeys: - @"SOGoLoginModule", @"SOGoUIxDefaultModule", - @"SOGoLoginModule", @"SOGoDefaultModule", + @"SOGoLoginModule", @"SOGoUIxDefaultModule", + @"SOGoLoginModule", @"SOGoDefaultModule", @"SOGoTimeFormat", @"TimeFormat", @"SOGoShortDateFormat", @"ShortDateFormat", @"SOGoLongDateFormat", @"LongDateFormat", @@ -197,6 +197,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; @"SOGoLanguage", @"SOGoDefaultLanguage", @"SOGoLanguage", @"Language", @"SOGoMailComposeMessageType", @"ComposeMessagesType", + @"SOGoSelectedAddressBook", @"SelectedAddressBook", @"SOGoMailMessageCheck", @"MessageCheck", @"SOGoMailMessageForwarding", @"MessageForwarding", @"SOGoMailSignature", @"MailSignature", @@ -384,6 +385,16 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return userLanguage; } +- (void) setMailAddOutgoingAddresses: (BOOL) newValue +{ + [self setBool: newValue forKey: @"SOGoMailAddOutgoingAddresses"]; +} + +- (BOOL) mailAddOutgoingAddresses +{ + return [self boolForKey: @"SOGoMailAddOutgoingAddresses"]; +} + - (void) setMailShowSubscribedFoldersOnly: (BOOL) newValue { [self setBool: newValue forKey: @"SOGoMailShowSubscribedFoldersOnly"]; @@ -467,6 +478,16 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return [self stringArrayForKey: @"SOGoMailListViewColumnsOrder"]; } +- (void) setSelectedAddressBook:(NSString *) newValue +{ + [self setObject: newValue forKey: @"SOGoSelectedAddressBook"]; +} + +- (NSString *) selectedAddressBook +{ + return [self stringForKey: @"SOGoSelectedAddressBook"]; +} + - (void) setMailMessageCheck: (NSString *) newValue { [self setObject: newValue forKey: @"SOGoMailMessageCheck"]; diff --git a/UI/Contacts/UIxContactFoldersView.m b/UI/Contacts/UIxContactFoldersView.m index f38a3532f..aaf35d6c2 100644 --- a/UI/Contacts/UIxContactFoldersView.m +++ b/UI/Contacts/UIxContactFoldersView.m @@ -158,88 +158,23 @@ Class SOGoContactSourceFolderK, SOGoGCSFolderK; - (id ) allContactSearchAction { id result; - SOGoFolder *folder; - NSString *searchText, *mail, *domain; + NSString *searchText; NSDictionary *data; - NSArray *folders, *contacts, *descriptors, *sortedContacts; - NSMutableArray *sortedFolders; - NSMutableDictionary *contact, *uniqueContacts; - unsigned int i, j, max; - NSSortDescriptor *commonNameDescriptor; + NSArray *sortedContacts; + BOOL excludeGroups, excludeLists; searchText = [self queryParameterForKey: @"search"]; if ([searchText length] > 0) { - // NSLog(@"Search all contacts: %@", searchText); excludeGroups = [[self queryParameterForKey: @"excludeGroups"] boolValue]; excludeLists = [[self queryParameterForKey: @"excludeLists"] boolValue]; - domain = [[context activeUser] domain]; - folders = nil; - NS_DURING - folders = [[self clientObject] subFolders]; - NS_HANDLER - /* We need to specifically test for @"SOGoDBException", which is - raised explicitly in SOGoParentFolder. Any other exception should - be re-raised. */ - if ([[localException name] isEqualToString: @"SOGoDBException"]) - folders = nil; - else - [localException raise]; - NS_ENDHANDLER; - max = [folders count]; - sortedFolders = [NSMutableArray arrayWithCapacity: max]; - uniqueContacts = [NSMutableDictionary dictionary]; - for (i = 0; i < max; i++) - { - folder = [folders objectAtIndex: i]; - /* We first search in LDAP folders (in case of duplicated entries in GCS folders) */ - if ([folder isKindOfClass: SOGoContactSourceFolderK]) - [sortedFolders insertObject: folder atIndex: 0]; - else - [sortedFolders addObject: folder]; - } - for (i = 0; i < max; i++) - { - folder = [sortedFolders objectAtIndex: i]; - //NSLog(@" Address book: %@ (%@)", [folder displayName], [folder class]); - contacts = [folder lookupContactsWithFilter: searchText - onCriteria: @"name_or_address" - sortBy: @"c_cn" - ordering: NSOrderedAscending - inDomain: domain]; - for (j = 0; j < [contacts count]; j++) - { - contact = [contacts objectAtIndex: j]; - mail = [contact objectForKey: @"c_mail"]; - //NSLog(@" found %@ (%@) ? %@", [contact objectForKey: @"c_name"], mail, - // [contact description]); - if (!excludeLists && [[contact objectForKey: @"c_component"] - isEqualToString: @"vlist"]) - { - [contact setObject: [folder nameInContainer] - forKey: @"container"]; - [uniqueContacts setObject: contact - forKey: [contact objectForKey: @"c_name"]]; - } - else if ([mail length] - && [uniqueContacts objectForKey: mail] == nil - && !(excludeGroups && [contact objectForKey: @"isGroup"])) - [uniqueContacts setObject: contact forKey: mail]; - } - } - if ([uniqueContacts count] > 0) - { - // Sort the contacts by display name - commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn" - ascending:YES]; - descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil]; - [commonNameDescriptor release]; - sortedContacts = [[uniqueContacts allValues] - sortedArrayUsingDescriptors: descriptors]; - } - else - sortedContacts = [NSArray array]; + + sortedContacts = [[self clientObject] allContactsFromFilter: searchText + excludeGroups: excludeGroups + excludeLists: excludeLists]; + + data = [NSDictionary dictionaryWithObjectsAndKeys: searchText, @"searchText", sortedContacts, @"contacts", nil]; diff --git a/UI/PreferencesUI/English.lproj/Localizable.strings b/UI/PreferencesUI/English.lproj/Localizable.strings index afa832c3e..cc5afde74 100644 --- a/UI/PreferencesUI/English.lproj/Localizable.strings +++ b/UI/PreferencesUI/English.lproj/Localizable.strings @@ -139,6 +139,8 @@ "messagecheck_every_20_minutes" = "Every 20 minutes"; "messagecheck_every_30_minutes" = "Every 30 minutes"; "messagecheck_once_per_hour" = "Once per hour"; +"PersonalAddressBook" = "Personal address book"; +"CollectedAddressBook" = "Collected addresses"; "Forward messages:" = "Forward messages:"; "messageforward_inline" = "Inline"; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 7ba612cac..92a813061 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -50,6 +50,8 @@ #import #import +#import + #import "UIxPreferences.h" #warning this class is not finished @@ -656,6 +658,16 @@ static NSArray *reminderValues = nil; } /* Mailer */ +- (void) setAddOutgoingAddresses: (BOOL) addOutgoingAddresses +{ + [userDefaults setMailAddOutgoingAddresses: addOutgoingAddresses]; +} + +- (BOOL) addOutgoingAddresses +{ + return [userDefaults mailAddOutgoingAddresses]; +} + - (void) setShowSubscribedFoldersOnly: (BOOL) showSubscribedFoldersOnly { [userDefaults setMailShowSubscribedFoldersOnly: showSubscribedFoldersOnly]; @@ -676,6 +688,58 @@ static NSArray *reminderValues = nil; return [userDefaults mailSortByThreads]; } +- (NSArray *) addressBookList +{ + /* We want all the SourceIDS */ + NSMutableArray *folders; + NSMutableArray *contactFolders; + + contactFolders = [[[context activeUser] homeFolderInContext: context] + lookupName: @"Contacts" + inContext: context + acquire: NO]; + + folders = [NSMutableArray arrayWithArray: [contactFolders subFolders]]; + + int i, count; + + count = [folders count]-1; + + // Inside this loop we remove all the public or shared addressbooks + for (count; count >= 0; count--) + { + if (![[folders objectAtIndex: count] isKindOfClass: [SOGoContactGCSFolder class]]) + [folders removeObjectAtIndex: count]; + } + + // Parse the objects in order to have only the displayName of the addressbooks to be displayed on the preferences interface + NSMutableArray *availableAddressBooks = [NSMutableArray new]; + NSMutableArray *availableAddressBooksName = [NSMutableArray new]; + + count = [folders count]-1; + for (i=0; i <= count ; i++) { + [availableAddressBooks addObject:[[folders objectAtIndex:i] realNameInContainer]]; + [availableAddressBooksName addObject:[[folders objectAtIndex:i] displayName]]; + } + + return availableAddressBooks; + +} +- (NSString *) itemAddressBookText +{ + return [self labelForKey:[NSString stringWithFormat: item]]; +} + +- (NSString *) userAddressBook +{ + return [userDefaults selectedAddressBook]; +} + +- (void) setUserAddressBook: (NSString *) newSelectedAddressBook +{ + [userDefaults setSelectedAddressBook: newSelectedAddressBook]; +} + - (NSArray *) messageCheckList { NSArray *intervalsList; diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 66f69b6a9..4c2a85f71 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -294,6 +294,16 @@ const:id="sortByThreads" var:checked="sortByThreads" /> +
+ +
+