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
- (NSString *) defaultFolderName;
- (NSString *) collectedFolderName;
- (NSException *) appendCollectedSources;
- (NSException *) renameLDAPAddressBook: (NSString *) sourceID
withDisplayName: (NSString *) newDisplayName;
- (NSException *) removeLDAPAddressBook: (NSString *) sourceID;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -139,8 +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";
"personal" = "Personal addressbook";
"collected" = "Collected addresses";
"Forward messages:" = "Forward messages:";
"messageforward_inline" = "Inline";

View File

@ -691,18 +691,14 @@ static NSArray *reminderValues = nil;
- (NSArray *) addressBookList
{
/* We want all the SourceIDS */
NSMutableArray *folders;
NSMutableArray *contactFolders;
NSMutableArray *folders, *contactFolders, *availableAddressBooks;
int i, count;
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
@ -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
NSMutableArray *availableAddressBooks = [NSMutableArray new];
NSMutableArray *availableAddressBooksName = [NSMutableArray new];
availableAddressBooks = [[NSMutableArray alloc] initWithCapacity: [folders count]];
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 *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