Added the modifications specified by extrafu

pull/29/head
Alexandre Cloutier 2014-03-25 14:53:42 -04:00
parent 76307cfaaf
commit bce701208a
8 changed files with 137 additions and 161 deletions

View File

@ -26,9 +26,7 @@
@interface SOGoContactFolders : SOGoParentFolder @interface SOGoContactFolders : SOGoParentFolder
- (NSString *) defaultFolderName; - (NSString *) defaultFolderName;
- (NSString *) collectedFolderName;
- (NSException *) appendCollectedSources;
- (NSException *) renameLDAPAddressBook: (NSString *) sourceID - (NSException *) renameLDAPAddressBook: (NSString *) sourceID
withDisplayName: (NSString *) newDisplayName; withDisplayName: (NSString *) newDisplayName;
- (NSException *) removeLDAPAddressBook: (NSString *) sourceID; - (NSException *) removeLDAPAddressBook: (NSString *) sourceID;

View File

@ -123,60 +123,6 @@ Class SOGoContactSourceFolderK;
return result; 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 - (NSException *) appendCollectedSources
{ {
GCSChannelManager *cm; GCSChannelManager *cm;
@ -195,16 +141,16 @@ Class SOGoContactSourceFolderK;
sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@" sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@"
@" WHERE c_path2 = '%@'" @" WHERE c_path2 = '%@'"
@" AND c_folder_type = '%@'"), @" AND c_folder_type = '%@'"),
[folderLocation gcsTableName], [folderLocation gcsTableName], owner, gcsFolderType];
owner,
gcsFolderType]; error = [super fetchSpecialFolders: sql withChannel: fc andFolderType: SOGoCollectedFolder];
error = [self _fetchCollectedFolders: sql withChannel: fc];
[cm releaseChannel: fc]; [cm releaseChannel: fc];
} }
else else
error = [NSException exceptionWithName: @"SOGoDBException" error = [NSException exceptionWithName: @"SOGoDBException"
reason: @"database connection could not be open" reason: @"database connection could not be open"
userInfo: nil]; userInfo: nil];
return error; return error;
} }
@ -349,11 +295,6 @@ Class SOGoContactSourceFolderK;
return [self labelForKey: @"Personal Address Book"]; return [self labelForKey: @"Personal Address Book"];
} }
- (NSString *) collectedFolderName
{
return [self labelForKey: @"Collected Address Book"];
}
- (NSArray *) toManyRelationshipKeys - (NSArray *) toManyRelationshipKeys
{ {
NSMutableArray *keys; NSMutableArray *keys;

View File

@ -1698,68 +1698,59 @@ static NSString *userAgent = nil;
SOGoUserDefaults *ud; SOGoUserDefaults *ud;
ud = [[context activeUser] userDefaults]; ud = [[context activeUser] userDefaults];
if ([ud mailAddOutgoingAddresses]) { if ([ud mailAddOutgoingAddresses])
NSMutableArray *recipients; {
SOGoMailAccounts *folder;
NGMailAddressParser *parser;
SOGoContactFolders *contactFolders; SOGoContactFolders *contactFolders;
NSArray *contacts; NGMailAddressParser *parser;
NSString *address, *mail, *name; id parsedRecipient;
SOGoContactFolder *folder;
SOGoContactGCSEntry *newContact;
NGVCard *card;
Class contactGCSEntry;
NSMutableArray *recipients;
NSString *recipient, *emailAddress, *displayName, *addressBook, *uid;
NSArray *matchingContacts;
int i; int i;
id parsedAddress;
// Get all the addressbooks
contactFolders = [[[context activeUser] homeFolderInContext: context] contactFolders = [[[context activeUser] homeFolderInContext: context]
lookupName: @"Contacts" lookupName: @"Contacts"
inContext: context inContext: context
acquire: NO]; acquire: NO];
// Get all the recipients from the current email
recipients = [self allRecipients]; recipients = [self allRecipients];
for (i = 0; i < [recipients count]; i++) for (i = 0; i < [recipients count]; i++)
{ {
// The address contains a string. ex: "John Doe <sogo1@exemple.com>" // The address contains a string. ex: "John Doe <sogo1@exemple.com>"
address = [recipients objectAtIndex: i]; recipient = [recipients objectAtIndex: i];
parser = [NGMailAddressParser mailAddressParserWithString: recipient];
parsedRecipient = [parser parse];
emailAddress = [parsedRecipient address];
displayName = [parsedRecipient displayName];
parser = [NGMailAddressParser mailAddressParserWithString: address]; matchingContacts = [contactFolders allContactsFromFilter: emailAddress
parsedAddress = [parser parse]; excludeGroups: YES
excludeLists: YES];
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 we don't get any results from the autocompletion code, we add it..
if ([contacts count] == 0) if ([matchingContacts count] == 0)
{ {
SOGoContactFolder *folder; /* Get the selected addressbook from the user preferences where the new address will be added */
Class c;
SOGoContactGCSEntry *contact;
NSString *uid;
NGVCard *card;
/* Here I want the selected address book on the preferences. */
NSString *addressBook;
addressBook = [ud selectedAddressBook]; addressBook = [ud selectedAddressBook];
folder = [contactFolders lookupName: addressBook inContext: context acquire: NO]; folder = [contactFolders lookupName: addressBook inContext: context acquire: NO];
uid = [folder globallyUniqueObjectId]; uid = [folder globallyUniqueObjectId];
card = [NGVCard cardWithUid: uid]; card = [NGVCard cardWithUid: uid];
[card addEmail: mail types: nil]; [card addEmail: emailAddress types: nil];
c = NSClassFromString(@"SOGoContactGCSEntry"); contactGCSEntry = NSClassFromString(@"SOGoContactGCSEntry");
contact = [c objectWithName: uid newContact = [contactGCSEntry objectWithName: uid
inContainer: folder]; inContainer: folder];
[contact setIsNew: YES]; [newContact setIsNew: YES];
[newContact saveContentString: [card versitString]];
[contact saveContentString: [card versitString]];
} }
} }
} }
return [self sendMailAndCopyToSent: YES]; return [self sendMailAndCopyToSent: YES];
} }

View File

@ -51,4 +51,10 @@ typedef enum
EventUpdated = 2, EventUpdated = 2,
} SOGoEventOperation; } SOGoEventOperation;
typedef enum
{
SOGoPersonalFolder = 0,
SOGoCollectedFolder = 1,
} SOGoFolderType;
#endif /* _SOGOCONSTANTS_H_ */ #endif /* _SOGOCONSTANTS_H_ */

View File

@ -22,6 +22,7 @@
#define SOGOPARENTFOLDERS_H #define SOGOPARENTFOLDERS_H
#import "SOGoFolder.h" #import "SOGoFolder.h"
#import "SOGoConstants.h"
@class NSMutableDictionary; @class NSMutableDictionary;
@class NSString; @class NSString;

View File

@ -153,9 +153,15 @@ static SoSecurityManager *sm = nil;
return @"Personal"; return @"Personal";
} }
- (void) _createPersonalFolder - (NSString *) collectedFolderName
{
return @"Collected";
}
- (void) createSpecialFolder: (SOGoFolderType) folderType
{ {
NSArray *roles; NSArray *roles;
NSString *folderName;
SOGoGCSFolder *folder; SOGoGCSFolder *folder;
SOGoUser *folderOwner; SOGoUser *folderOwner;
@ -165,20 +171,32 @@ static SoSecurityManager *sm = nil;
// We autocreate the calendars if the user is the owner, a superuser or // We autocreate the calendars if the user is the owner, a superuser or
// if it's a resource as we won't necessarily want to login as a resource // if it's a resource as we won't necessarily want to login as a resource
// in order to create its database tables. // in order to create its database tables.
// FolderType is an Enum where 0 = Personal and 1 = collected
if ([roles containsObject: SoRole_Owner] || if ([roles containsObject: SoRole_Owner] ||
(folderOwner && [folderOwner isResource])) (folderOwner && [folderOwner isResource]))
{ {
folder = [subFolderClass objectWithName: @"personal" inContainer: self]; folder = [subFolderClass objectWithName: folderName inContainer: self];
[folder setDisplayName: [self defaultFolderName]]; if (folderType == 0)
[folder {
setOCSPath: [NSString stringWithFormat: @"%@/personal", OCSPath]]; folderName = @"personal";
[folder setDisplayName: [self defaultFolderName]];
}
else if (folderType == 1)
{
folderName = @"Collected Address Book";
[folder setDisplayName: [self collectedFolderName]];
}
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, folderName]];
if ([folder create]) if ([folder create])
[subFolders setObject: folder forKey: @"personal"]; [subFolders setObject: folder forKey: folderName];
} }
} }
- (NSException *) _fetchPersonalFolders: (NSString *) sql - (NSException *) fetchSpecialFolders: (NSString *) sql
withChannel: (EOAdaptorChannel *) fc withChannel: (EOAdaptorChannel *) fc
andFolderType: (SOGoFolderType) folderType
{ {
NSArray *attrs; NSArray *attrs;
NSDictionary *row; NSDictionary *row;
@ -191,24 +209,29 @@ static SoSecurityManager *sm = nil;
error = [fc evaluateExpressionX: sql]; error = [fc evaluateExpressionX: sql];
if (!error) if (!error)
{
attrs = [fc describeResults: NO];
while ((row = [fc fetchAttributes: attrs withZone: NULL]))
{ {
attrs = [fc describeResults: NO]; key = [row objectForKey: @"c_path4"];
while ((row = [fc fetchAttributes: attrs withZone: NULL])) if ([key isKindOfClass: [NSString class]])
{ {
key = [row objectForKey: @"c_path4"]; folder = [subFolderClass objectWithName: key inContainer: self];
if ([key isKindOfClass: [NSString class]]) [folder setOCSPath: [NSString stringWithFormat: @"%@/%@", OCSPath, key]];
{ [subFolders setObject: folder forKey: key];
folder = [subFolderClass objectWithName: key inContainer: self]; }
[folder setOCSPath: [NSString stringWithFormat: @"%@/%@",
OCSPath, key]];
[subFolders setObject: folder forKey: key];
}
}
if (![subFolders objectForKey: @"personal"])
[self _createPersonalFolder];
} }
if (folderType == 0)
{
if (![subFolders objectForKey: @"personal"])
[self createSpecialFolder: SOGoPersonalFolder];
}
else if (folderType == 1)
{
if (![subFolders objectForKey: @"collected"])
[self createSpecialFolder: SOGoCollectedFolder];
}
}
return error; return error;
} }
@ -224,19 +247,18 @@ static SoSecurityManager *sm = nil;
folderLocation = [[GCSFolderManager defaultFolderManager] folderInfoLocation]; folderLocation = [[GCSFolderManager defaultFolderManager] folderInfoLocation];
fc = [cm acquireOpenChannelForURL: folderLocation]; fc = [cm acquireOpenChannelForURL: folderLocation];
if ([fc isOpen]) if ([fc isOpen])
{ {
gcsFolderType = [[self class] gcsFolderType]; gcsFolderType = [[self class] gcsFolderType];
sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@" sql = [NSString stringWithFormat: (@"SELECT c_path4 FROM %@"
@" WHERE c_path2 = '%@'" @" WHERE c_path2 = '%@'"
@" AND c_folder_type = '%@'"), @" AND c_folder_type = '%@'"),
[folderLocation gcsTableName], owner, gcsFolderType]; [folderLocation gcsTableName], owner, gcsFolderType];
error = [self _fetchPersonalFolders: sql withChannel: fc]; error = [self fetchSpecialFolders: sql withChannel: fc andFolderType: SOGoPersonalFolder];
[cm releaseChannel: fc];
// sql = [sql stringByAppendingFormat:@" WHERE %@ = '%@'", [cm releaseChannel: fc];
// uidColumnName, [self uid]]; }
}
else else
error = [NSException exceptionWithName: @"SOGoDBException" error = [NSException exceptionWithName: @"SOGoDBException"
reason: @"database connection could not be open" reason: @"database connection could not be open"
@ -384,7 +406,7 @@ static SoSecurityManager *sm = nil;
if (!subFolders) if (!subFolders)
{ {
subFolders = [NSMutableDictionary new]; subFolders = [NSMutableDictionary new];
error = [self appendPersonalSources]; error = [self appendPersonalSources];
if (!error) if (!error)
if ([self respondsToSelector:@selector(appendCollectedSources)]) if ([self respondsToSelector:@selector(appendCollectedSources)])
error = [self appendCollectedSources]; error = [self appendCollectedSources];

View File

@ -139,8 +139,8 @@
"messagecheck_every_20_minutes" = "Every 20 minutes"; "messagecheck_every_20_minutes" = "Every 20 minutes";
"messagecheck_every_30_minutes" = "Every 30 minutes"; "messagecheck_every_30_minutes" = "Every 30 minutes";
"messagecheck_once_per_hour" = "Once per hour"; "messagecheck_once_per_hour" = "Once per hour";
"PersonalAddressBook" = "Personal address book"; "personal" = "Personal addressbook";
"CollectedAddressBook" = "Collected addresses"; "collected" = "Collected addresses";
"Forward messages:" = "Forward messages:"; "Forward messages:" = "Forward messages:";
"messageforward_inline" = "Inline"; "messageforward_inline" = "Inline";

View File

@ -691,18 +691,14 @@ static NSArray *reminderValues = nil;
- (NSArray *) addressBookList - (NSArray *) addressBookList
{ {
/* We want all the SourceIDS */ /* We want all the SourceIDS */
NSMutableArray *folders; NSMutableArray *folders, *contactFolders, *availableAddressBooks;
NSMutableArray *contactFolders; int i, count;
contactFolders = [[[context activeUser] homeFolderInContext: context] contactFolders = [[[context activeUser] homeFolderInContext: context]
lookupName: @"Contacts" lookupName: @"Contacts"
inContext: context inContext: context
acquire: NO]; acquire: NO];
folders = [NSMutableArray arrayWithArray: [contactFolders subFolders]]; folders = [NSMutableArray arrayWithArray: [contactFolders subFolders]];
int i, count;
count = [folders count]-1; count = [folders count]-1;
// Inside this loop we remove all the public or shared addressbooks // Inside this loop we remove all the public or shared addressbooks
@ -713,21 +709,42 @@ static NSArray *reminderValues = nil;
} }
// Parse the objects in order to have only the displayName of the addressbooks to be displayed on the preferences interface // Parse the objects in order to have only the displayName of the addressbooks to be displayed on the preferences interface
NSMutableArray *availableAddressBooks = [NSMutableArray new]; availableAddressBooks = [[NSMutableArray alloc] initWithCapacity: [folders count]];
NSMutableArray *availableAddressBooksName = [NSMutableArray new];
count = [folders count]-1; count = [folders count]-1;
for (i=0; i <= count ; i++) { for (i=0; i <= count ; i++) {
[availableAddressBooks addObject:[[folders objectAtIndex:i] realNameInContainer]]; [availableAddressBooks addObject:[[folders objectAtIndex:i] realNameInContainer]];
[availableAddressBooksName addObject:[[folders objectAtIndex:i] displayName]];
} }
return availableAddressBooks; return availableAddressBooks;
} }
- (NSString *) itemAddressBookText - (NSString *) itemAddressBookText
{ {
return [self labelForKey:[NSString stringWithFormat: item]]; NSString *displayNameAddressBookItem, *test;
NSMutableArray *folders, *contactFolders;
int count, i;
if ([item isEqualToString: @"personal"] || [item isEqualToString: @"collected"])
displayNameAddressBookItem = [self labelForKey:[NSString stringWithFormat: item]];
else
{
contactFolders = [[[context activeUser] homeFolderInContext: context]
lookupName: @"Contacts"
inContext: context
acquire: NO];
folders = [NSMutableArray arrayWithArray: [contactFolders subFolders]];
count = [folders count]-1;
for (i=0; i <= count ; i++)
{
if ([item isEqualToString:[[folders objectAtIndex:i] realNameInContainer]])
{
displayNameAddressBookItem = [[folders objectAtIndex:i] displayName];
break;
};
}
}
return displayNameAddressBookItem;
} }
- (NSString *) userAddressBook - (NSString *) userAddressBook