From 8ebb7cfcfc69c013eca89242965df3bc622f1c23 Mon Sep 17 00:00:00 2001 From: wolfgang Date: Thu, 1 Nov 2007 13:07:22 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1210 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ChangeLog | 61 ++++++ SoObjects/Mailer/SOGoMailAccount.h | 13 +- SoObjects/Mailer/SOGoMailAccount.m | 192 ++++++++---------- SoObjects/Mailer/SOGoMailBaseObject.m | 5 +- SoObjects/Mailer/SOGoMailFolder.m | 58 ++++-- SoObjects/SOGo/AgenorUserDefaults.m | 128 +++++------- UI/MailerUI/English.lproj/Localizable.strings | 1 - UI/MailerUI/French.lproj/Localizable.strings | 1 - UI/MailerUI/German.lproj/Localizable.strings | 1 - UI/MailerUI/UIxMailAccountActions.h | 3 +- UI/MailerUI/UIxMailAccountActions.m | 93 +++++---- UI/MailerUI/UIxMailFolderActions.m | 4 +- UI/WebServerResources/MailerUI.js | 9 +- 13 files changed, 310 insertions(+), 259 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2ec7f33..14fbeaa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,64 @@ +2007-11-01 Wolfgang Sourdeau + + * UI/MailerUI/UIxMailFolderActions.m ([UIxMailFolderActions + -deleteFolderAction]): no longer prefix the target folder with + "folder". + + * UI/MailerUI/UIxMailAccountActions.m ([UIxMailAccountActions + -listMailboxesAction]): base the folder type on the folder + traversal path. + + * SoObjects/Mailer/SOGoMailFolder.m ([SOGoMailFolder + -lookupName:_keyinContext:acquire:_acquire]): compare the full + traversal to the potential looked up folder with the special + folder names and return an object with the appropriate + SOGoMailFolder subclass. + + * SoObjects/Mailer/SOGoMailBaseObject.m ([SOGoMailBaseObject + -traversalFromMailAccount]): don't prepend the whole string with + "/". + + * SoObjects/Mailer/SOGoMailAccount.m + ([-lookupSentFolder:_keyinContext:_ctx]) + ([-lookupDraftsFolder:_keyinContext:_ctx]) + ([-lookupTrashFolder:_keyinContext:_ctx]) + ([-lookupFiltersFolder:_key:_ctx]): removed methods. + ([SOGoMailAccount -inboxFolderNameInContext:]) + ([SOGoMailAccount -draftsFolderNameInContext:_ctx]) + ([SOGoMailAccount -sentFolderNameInContext:]) + ([SOGoMailAccount -trashFolderNameInContext:]): no longer prefixes + the resulting name with "prefix" since we might return a nested + foldername. + ([SOGoMailAccount -allFolderPaths]): prefixes all special folder + names with "/". Sorts the resulting folder list with + localizedCaseInsensitiveCompare: instead of + caseInsensitiveCompare:. No longer use the -[lookupXXX] methods + that were removed, instead, we choose the appropriate class + depending on the folder name. And since we are in SOGoMailAccount, + we don't have to compute a traversal path to match the key with + the foldernames. + ([SOGoMailAccount + -folderWithTraversal:traversalandClassName:className]): new method + that returns an instance of the specified SOGoMailFolder subclass, + based on the traversal path passed as parameter. + ([SOGoMailAccount -inboxFolderInContext:_ctx]) + ([SOGoMailAccount -draftsFolderInContext:_ctx]) + ([-sentFolderInContext:_ctx]) + ([SOGoMailAccount -trashFolderInContext:_ctx]): invoke the new + -folderWithTraversal:andClassName: method described above. + + * SoObjects/SOGo/AgenorUserDefaults.m ([AgenorUserDefaults + -primaryFetchProfile]): make use of -[NSPropertyListSerialization + propertyListFromData:mutabilityOption:format:errorDescription:] to + deserialize the plist. Removed variant for libFoundation since it + should support the above. + ([AgenorUserDefaults -generateSQLForInsert]) + ([AgenorUserDefaults -generateSQLForUpdate]): make use of + -[NSPropertyListSerialization + dataFromPropertyList:format:errorDescription:] to serialize the + plist. Removed variant for libFoundation since it should support + the above. Escape the backslashes from the resulting string. + 2007-10-31 Wolfgang Sourdeau * SoObjects/Mailer/SOGoMailFolder.[hm]: added a new subclass of diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index dff40537..e6e55ebb 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -35,15 +35,18 @@ @class NSArray; @class NSString; + @class SOGoDraftsFolder; @class SOGoMailFolder; +@class SOGoSentFolder; +@class SOGoTrashFolder; @interface SOGoMailAccount : SOGoMailBaseObject { SOGoMailFolder *inboxFolder; SOGoDraftsFolder *draftsFolder; - SOGoMailFolder *sentFolder; - SOGoMailFolder *trashFolder; + SOGoSentFolder *sentFolder; + SOGoTrashFolder *trashFolder; } /* folder pathes */ @@ -61,14 +64,14 @@ - (NSString *) inboxFolderNameInContext: (id)_ctx; - (NSString *) draftsFolderNameInContext: (id)_ctx; -- (NSString *) sieveFolderNameInContext: (id)_ctx; +// - (NSString *) sieveFolderNameInContext: (id)_ctx; - (NSString *) sentFolderNameInContext: (id)_ctx; - (NSString *) trashFolderNameInContext: (id)_ctx; - (SOGoMailFolder *) inboxFolderInContext: (id)_ctx; - (SOGoDraftsFolder *) draftsFolderInContext: (id)_ctx; -- (SOGoMailFolder *) sentFolderInContext: (id)_ctx; -- (SOGoMailFolder *) trashFolderInContext: (id)_ctx; +- (SOGoSentFolder *) sentFolderInContext: (id)_ctx; +- (SOGoTrashFolder *) trashFolderInContext: (id)_ctx; /* user defaults */ - (NSString *) sharedFolderName; diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 25b99b70..f702e21f 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -35,9 +35,11 @@ #import #import +#import "SOGoDraftsFolder.h" #import "SOGoMailFolder.h" #import "SOGoMailManager.h" -#import "SOGoDraftsFolder.h" +#import "SOGoSentFolder.h" +#import "SOGoTrashFolder.h" #import "SOGoMailAccount.h" @@ -177,30 +179,25 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default - (NSArray *) allFolderPaths { - NSMutableArray *newFolders; + NSMutableArray *folderPaths; NSArray *rawFolders, *mainFolders; - NSString *realDraftsFolderName, *realSentFolderName, *realTrashFolderName; rawFolders = [[self imap4Connection] allFoldersForURL: [self imap4URL]]; - realDraftsFolderName - = [[self draftsFolderInContext: context] traversalFromMailAccount]; - realSentFolderName - = [[self sentFolderInContext: context] traversalFromMailAccount]; - realTrashFolderName - = [[self trashFolderInContext: context] traversalFromMailAccount]; - - mainFolders = [NSArray arrayWithObjects: inboxFolderName, - realDraftsFolderName, - realSentFolderName, - realTrashFolderName, nil]; - newFolders = [NSMutableArray arrayWithArray: rawFolders]; - [newFolders removeObjectsInArray: mainFolders]; - [newFolders sortUsingSelector: @selector (caseInsensitiveCompare:)]; - [newFolders replaceObjectsInRange: NSMakeRange (0, 0) - withObjectsFromArray: mainFolders]; + mainFolders = [[NSArray arrayWithObjects: + [self inboxFolderNameInContext: context], + [self draftsFolderNameInContext: context], + [self sentFolderNameInContext: context], + [self trashFolderNameInContext: context], + nil] stringsWithFormat: @"/%@"]; + folderPaths = [NSMutableArray arrayWithArray: rawFolders]; + [folderPaths removeObjectsInArray: mainFolders]; + [folderPaths + sortUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + [folderPaths replaceObjectsInRange: NSMakeRange (0, 0) + withObjectsFromArray: mainFolders]; - return newFolders; + return folderPaths; } /* IMAP4 */ @@ -268,74 +265,32 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default /* name lookup */ -- (id) lookupFolder: (NSString *) _key - ofClassNamed: (NSString *) _cn - inContext: (id) _cx -{ - Class clazz; - SOGoMailFolder *folder; - - if ((clazz = NSClassFromString(_cn)) == Nil) - { - [self logWithFormat:@"ERROR: did not find class '%@' for key: '%@'", - _cn, _key]; - return [NSException exceptionWithHTTPStatus:500 /* server error */ - reason:@"did not find mail folder class!"]; - } - - folder = [clazz objectWithName: _key inContainer: self]; - - return folder; -} - -- (id) lookupSentFolder: (NSString *) _key - inContext: (id) _ctx -{ - return [self lookupFolder: _key ofClassNamed: @"SOGoSentFolder" - inContext: _ctx]; -} - -- (id) lookupDraftsFolder: (NSString *) _key - inContext: (id) _ctx -{ - return [self lookupFolder: _key ofClassNamed: @"SOGoDraftsFolder" - inContext: _ctx]; -} - -- (id) lookupTrashFolder: (NSString *) _key - inContext: (id) _ctx -{ - return [self lookupFolder: _key ofClassNamed: @"SOGoTrashFolder" - inContext: _ctx]; -} - -- (id) lookupFiltersFolder: (NSString *) _key inContext: (id) _ctx -{ - return [self lookupFolder:_key ofClassNamed:@"SOGoSieveScriptsFolder" - inContext:_ctx]; -} - - (id) lookupName: (NSString *) _key inContext: (id)_ctx acquire: (BOOL) _flag { + NSString *folderName; + Class klazz; id obj; if ([_key hasPrefix: @"folder"]) { - // TODO: those should be product.plist bindings? (can't be class bindings - // though because they are 'per-account') - if ([_key isEqualToString: [self sentFolderNameInContext: _ctx]]) - obj = [self lookupSentFolder: _key inContext: _ctx]; - else if ([_key isEqualToString: [self draftsFolderNameInContext: _ctx]]) - obj = [self lookupDraftsFolder: _key inContext: _ctx]; - else if ([_key isEqualToString: [self trashFolderNameInContext: _ctx]]) - obj = [self lookupTrashFolder: _key inContext: _ctx]; -// else if ([_key isEqualToString: [self sieveFolderNameInContext: _ctx]]) -// obj = [self lookupFiltersFolder: _key inContext: _ctx]; + folderName = [_key substringFromIndex: 6]; + if ([folderName + isEqualToString: [self sentFolderNameInContext: _ctx]]) + klazz = [SOGoSentFolder class]; + else if ([folderName + isEqualToString: [self draftsFolderNameInContext: _ctx]]) + klazz = [SOGoDraftsFolder class]; + else if ([folderName + isEqualToString: [self trashFolderNameInContext: _ctx]]) + klazz = [SOGoTrashFolder class]; +/* else if ([folderName isEqualToString: [self sieveFolderNameInContext: _ctx]]) + obj = [self lookupFiltersFolder: _key inContext: _ctx]; */ else - obj = [self lookupFolder: _key ofClassNamed: @"SOGoMailFolder" - inContext: _ctx]; + klazz = [SOGoMailFolder class]; + + obj = [klazz objectWithName: _key inContainer: self]; } else obj = [super lookupName: _key inContext: _ctx acquire: NO]; @@ -352,7 +307,7 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default - (NSString *) inboxFolderNameInContext: (id)_ctx { /* cannot be changed in Cyrus ? */ - return [NSString stringWithFormat: @"folder%@", inboxFolderName]; + return inboxFolderName; } - (NSString *) _userFolderNameWithPurpose: (NSString *) purpose @@ -380,13 +335,13 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default if (!folderName) folderName = draftsFolderName; - return [NSString stringWithFormat: @"folder%@", folderName]; + return folderName; } -- (NSString *) sieveFolderNameInContext: (id) _ctx -{ - return [NSString stringWithFormat: @"folder%@", sieveFolderName]; -} +// - (NSString *) sieveFolderNameInContext: (id) _ctx +// { +// return sieveFolderName; +// } - (NSString *) sentFolderNameInContext: (id)_ctx { @@ -396,7 +351,7 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default if (!folderName) folderName = sentFolderName; - return [NSString stringWithFormat: @"folder%@", folderName]; + return folderName; } - (NSString *) trashFolderNameInContext: (id)_ctx @@ -407,7 +362,38 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default if (!folderName) folderName = trashFolderName; - return [NSString stringWithFormat: @"folder%@", folderName]; + return folderName; +} + +- (id) folderWithTraversal: (NSString *) traversal + andClassName: (NSString *) className +{ + NSArray *paths; + NSString *currentName; + id currentContainer; + unsigned int count, max; + Class clazz; + + currentContainer = self; + paths = [traversal componentsSeparatedByString: @"/"]; + + if (!className) + clazz = [SOGoMailFolder class]; + else + clazz = NSClassFromString (className); + + max = [paths count]; + for (count = 0; count < max - 1; count++) + { + currentName = [NSString stringWithFormat: @"folder%@", + [paths objectAtIndex: count]]; + currentContainer = [SOGoMailFolder objectWithName: currentName + inContainer: currentContainer]; + } + currentName = [NSString stringWithFormat: @"folder%@", + [paths objectAtIndex: max - 1]]; + + return [clazz objectWithName: currentName inContainer: currentContainer]; } - (SOGoMailFolder *) inboxFolderInContext: (id) _ctx @@ -415,8 +401,9 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default // TODO: use some profile to determine real location, use a -traverse lookup if (!inboxFolder) { - inboxFolder = [self lookupName: [self inboxFolderNameInContext: _ctx] - inContext: _ctx acquire: NO]; + inboxFolder + = [self folderWithTraversal: [self inboxFolderNameInContext: _ctx] + andClassName: nil]; [inboxFolder retain]; } @@ -430,43 +417,36 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default if (!draftsFolder) { draftsFolder - = [self lookupName: [self draftsFolderNameInContext:_ctx] - inContext: _ctx acquire: NO]; -// if (![draftsFolder isNotNull]) -// draftsFolder = [NSException exceptionWithHTTPStatus: 404 /* not found */ -// reason: @"did not find Drafts folder!"]; + = [self folderWithTraversal: [self draftsFolderNameInContext: _ctx] + andClassName: @"SOGoDraftsFolder"]; [draftsFolder retain]; } return draftsFolder; } -- (SOGoMailFolder *) sentFolderInContext: (id) _ctx +- (SOGoSentFolder *) sentFolderInContext: (id) _ctx { // TODO: use some profile to determine real location, use a -traverse lookup if (!sentFolder) { - sentFolder = [self lookupName: [self sentFolderNameInContext:_ctx] - inContext: _ctx acquire: NO]; -// if (![sentFolder isNotNull]) -// sentFolder = [NSException exceptionWithHTTPStatus: 404 /* not found */ -// reason: @"did not find Sent folder!"]; + sentFolder + = [self folderWithTraversal: [self sentFolderNameInContext: _ctx] + andClassName: @"SOGoSentFolder"]; [sentFolder retain]; } return sentFolder; } -- (SOGoMailFolder *) trashFolderInContext: (id) _ctx +- (SOGoTrashFolder *) trashFolderInContext: (id) _ctx { if (!trashFolder) { - trashFolder = [self lookupName: [self trashFolderNameInContext: _ctx] - inContext: _ctx acquire: NO]; -// if (![trashFolder isNotNull]) -// trashFolder = [NSException exceptionWithHTTPStatus: 404 /* not found */ -// reason: @"did not find Trash folder!"]; + trashFolder + = [self folderWithTraversal: [self trashFolderNameInContext: _ctx] + andClassName: @"SOGoTrashFolder"]; [trashFolder retain]; } diff --git a/SoObjects/Mailer/SOGoMailBaseObject.m b/SoObjects/Mailer/SOGoMailBaseObject.m index 60d6c22a..6feb888a 100644 --- a/SoObjects/Mailer/SOGoMailBaseObject.m +++ b/SoObjects/Mailer/SOGoMailBaseObject.m @@ -191,7 +191,10 @@ static BOOL debugOn = YES; NSMutableString *currentTraversal; currentTraversal = [container traversalFromMailAccount]; - [currentTraversal appendFormat: @"/%@", [self relativeImap4Name]]; + if ([container isKindOfClass: [SOGoMailAccount class]]) + [currentTraversal appendString: [self relativeImap4Name]]; + else + [currentTraversal appendFormat: @"/%@", [self relativeImap4Name]]; return currentTraversal; } diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 15f5b660..96be3161 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -299,10 +299,34 @@ static NSString *defaultUserID = @"anyone"; inContext: (id)_ctx acquire: (BOOL) _acquire { + NSString *folderName, *className; + SOGoMailAccount *mailAccount; id obj; if ([_key hasPrefix: @"folder"]) - obj = [SOGoMailFolder objectWithName: _key inContainer: self]; + { + mailAccount = [self mailAccountFolder]; + folderName = [NSString stringWithFormat: @"%@/%@", + [self traversalFromMailAccount], + [_key substringFromIndex: 6]]; + if ([folderName + isEqualToString: [mailAccount sentFolderNameInContext: _ctx]]) + className = @"SOGoSentFolder"; + else if ([folderName isEqualToString: + [mailAccount draftsFolderNameInContext: _ctx]]) + className = @"SOGoDraftsFolder"; + else if ([folderName isEqualToString: + [mailAccount trashFolderNameInContext: _ctx]]) + className = @"SOGoTrashFolder"; +/* else if ([folderName isEqualToString: + [mailAccount sieveFolderNameInContext: _ctx]]) + obj = [self lookupFiltersFolder: _key inContext: _ctx]; */ + else + className = @"SOGoMailFolder"; + + obj = [NSClassFromString (className) + objectWithName: _key inContainer: self]; + } else { if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]]) @@ -394,22 +418,24 @@ static NSString *defaultUserID = @"anyone"; { // TODO: detect Trash/Sent/Drafts folders SOGoMailAccount *account; - NSString *n; + NSString *name; - if (folderType != nil) - return folderType; - - account = [self mailAccountFolder]; - n = nameInContainer; - - if ([n isEqualToString:[account trashFolderNameInContext:nil]]) - folderType = @"IPF.Trash"; - else if ([n isEqualToString:[account inboxFolderNameInContext:nil]]) - folderType = @"IPF.Inbox"; - else if ([n isEqualToString:[account sentFolderNameInContext:nil]]) - folderType = @"IPF.Sent"; - else - folderType = @"IPF.Folder"; + if (!folderType) + { + account = [self mailAccountFolder]; + name = [self traversalFromMailAccount]; + + if ([name isEqualToString: [account trashFolderNameInContext: nil]]) + folderType = @"IPF.Trash"; + else if ([name + isEqualToString: [account inboxFolderNameInContext: nil]]) + folderType = @"IPF.Inbox"; + else if ([name + isEqualToString: [account sentFolderNameInContext: nil]]) + folderType = @"IPF.Sent"; + else + folderType = @"IPF.Folder"; + } return folderType; } diff --git a/SoObjects/SOGo/AgenorUserDefaults.m b/SoObjects/SOGo/AgenorUserDefaults.m index 15743275..39778f76 100644 --- a/SoObjects/SOGo/AgenorUserDefaults.m +++ b/SoObjects/SOGo/AgenorUserDefaults.m @@ -113,12 +113,10 @@ static NSString *uidColumnName = @"c_uid"; EOAdaptorChannel *channel; NSDictionary *row; NSException *ex; - NSString *sql, *value; + NSString *sql, *value, *error; NSArray *attrs; BOOL rc; -#if LIB_FOUNDATION_LIBRARY NSData *plistData; -#endif rc = NO; @@ -134,7 +132,6 @@ static NSString *uidColumnName = @"c_uid"; uidColumnName, [self uid]]; [values release]; - values = [NSMutableDictionary new]; /* run SQL */ @@ -155,15 +152,13 @@ static NSString *uidColumnName = @"c_uid"; value = [row objectForKey: fieldName]; if ([value isNotNull]) { -#if LIB_FOUNDATION_LIBRARY plistData = [value dataUsingEncoding: NSUTF8StringEncoding]; - [values setDictionary: [NSDeserializer - deserializePropertyListFromData: plistData - mutableContainers: YES]]; - -#else - [values setDictionary: [value propertyList]]; -#endif + values + = [NSPropertyListSerialization propertyListFromData: plistData + mutabilityOption: NSPropertyListMutableContainers + format: NULL + errorDescription: &error]; + [values retain]; } ASSIGN (lastFetch, [NSCalendarDate date]); @@ -180,22 +175,9 @@ static NSString *uidColumnName = @"c_uid"; return rc; } -- (NSString *) generateSQLForInsert +- (NSString *) _serializedDefaults { - NSMutableString *sql; - NSString *serializedDefaults; - -#if LIB_FOUNDATION_LIBRARY - serializedDefaults = [values stringRepresentation]; - - sql = [NSString stringWithFormat: (@"INSERT INTO %@" - @" (%@, %@)" - @" VALUES ('%@', '%@')"), - [[self tableURL] gcsTableName], uidColumnName, fieldName, - [self uid], - [serializedDefaults stringByReplacingString: @"'" - withString:@"''"]]; -#else + NSMutableString *serializedDefaults; NSData *serializedDefaultsData; NSString *error; @@ -204,75 +186,57 @@ static NSString *uidColumnName = @"c_uid"; = [NSPropertyListSerialization dataFromPropertyList: values format: NSPropertyListOpenStepFormat errorDescription: &error]; - if (error) { - sql = nil; + [self errorWithFormat: @"serializing the defaults: %@", error]; + serializedDefaults = nil; [error release]; } else { - serializedDefaults = [[NSString alloc] initWithData: serializedDefaultsData - encoding: NSUTF8StringEncoding]; - - sql = [NSString stringWithFormat: (@"INSERT INTO %@" - @" (%@, %@)" - @" VALUES ('%@', '%@')"), - [[self tableURL] gcsTableName], uidColumnName, fieldName, - [self uid], - [serializedDefaults stringByReplacingString:@"'" withString:@"''"]]; - [serializedDefaults release]; + serializedDefaults + = [[NSMutableString alloc] initWithData: serializedDefaultsData + encoding: NSUTF8StringEncoding]; + [serializedDefaults autorelease]; + [serializedDefaults replaceString: @"\\" withString: @"\\\\"]; + [serializedDefaults replaceString: @"'" withString: @"''"]; } -#endif + + return serializedDefaults; +} + +- (NSString *) generateSQLForInsert +{ + NSString *sql, *serializedDefaults; + + serializedDefaults = [self _serializedDefaults]; + if (serializedDefaults) + sql = [NSString stringWithFormat: (@"INSERT INTO %@" + @" (%@, %@)" + @" VALUES ('%@', '%@')"), + [[self tableURL] gcsTableName], uidColumnName, fieldName, + [self uid], serializedDefaults]; + else + sql = nil; return sql; } - (NSString *) generateSQLForUpdate { - NSMutableString *sql; - NSString *serializedDefaults; - -#if LIB_FOUNDATION_LIBRARY - serializedDefaults = [values stringRepresentation]; - - sql = [NSString stringWithFormat: (@"UPDATE %@" - @" SET %@ = '%@'" - @" WHERE %@ = '%@'"), - [[self tableURL] gcsTableName], - fieldName, - [serializedDefaults stringByReplacingString:@"'" withString:@"''"], - uidColumnName, [self uid]]; -#else - NSData *serializedDefaultsData; - NSString *error; - - error = nil; - serializedDefaultsData - = [NSPropertyListSerialization dataFromPropertyList: values - format: NSPropertyListOpenStepFormat - errorDescription: &error]; - if (error) - { - sql = nil; - [error release]; - } + NSString *sql, *serializedDefaults; + + serializedDefaults = [self _serializedDefaults]; + if (serializedDefaults) + sql = [NSString stringWithFormat: (@"UPDATE %@" + @" SET %@ = '%@'" + @" WHERE %@ = '%@'"), + [[self tableURL] gcsTableName], + fieldName, + serializedDefaults, + uidColumnName, [self uid]]; else - { - serializedDefaults = [[NSString alloc] initWithData: serializedDefaultsData - encoding: NSUTF8StringEncoding]; - - sql = [NSString stringWithFormat: (@"UPDATE %@" - @" SET %@ = '%@'" - @" WHERE %@ = '%@'"), - [[self tableURL] gcsTableName], - fieldName, - [serializedDefaults stringByReplacingString: @"'" - withString: @"''"], - uidColumnName, [self uid]]; - [serializedDefaults release]; - } -#endif + sql = nil; return sql; } diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index 5bf7abab..d3d7eb06 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -216,7 +216,6 @@ "Please select only one message to print." = "Please select only one message to print."; "You need to choose a non-virtual folder!" = "You need to choose a non-virtual folder!"; -"You need to choose a root subfolder!" = "You need to choose a root subfolder!"; "Moving a message into its own folder is impossible!" = "Moving a message into its own folder is impossible!"; diff --git a/UI/MailerUI/French.lproj/Localizable.strings b/UI/MailerUI/French.lproj/Localizable.strings index 6f9acb86..a818ceb0 100644 --- a/UI/MailerUI/French.lproj/Localizable.strings +++ b/UI/MailerUI/French.lproj/Localizable.strings @@ -217,7 +217,6 @@ "Please select only one message to print." = "Veuillez ne sélectionner qu'un seul message à imprimer."; "You need to choose a non-virtual folder!" = "Vous devez choisir un dossier non-virtuel."; -"You need to choose a root subfolder!" = "Vous devez choisir un sous-dossier de la racine."; "Moving a message into its own folder is impossible!" = "Le déplacement d'un message dans son propre dossier est impossible."; diff --git a/UI/MailerUI/German.lproj/Localizable.strings b/UI/MailerUI/German.lproj/Localizable.strings index 4f5f9890..4dd0652b 100644 --- a/UI/MailerUI/German.lproj/Localizable.strings +++ b/UI/MailerUI/German.lproj/Localizable.strings @@ -200,7 +200,6 @@ "Please select only one message to print." = "Bitte wählen Sie nur eine Nachricht zum Drucken aus."; "You need to choose a non-virtual folder!" = "You need to choose a non-virtual folder!"; -"You need to choose a root subfolder!" = "You need to choose a root subfolder!"; "Moving a message into its own folder is impossible!" = "Moving a message into its own folder is impossible!"; diff --git a/UI/MailerUI/UIxMailAccountActions.h b/UI/MailerUI/UIxMailAccountActions.h index e6c84f7d..f06d7fd1 100644 --- a/UI/MailerUI/UIxMailAccountActions.h +++ b/UI/MailerUI/UIxMailAccountActions.h @@ -29,7 +29,8 @@ @interface UIxMailAccountActions : WODirectAction { - NSString *draftFolderName; + NSString *inboxFolderName; + NSString *draftsFolderName; NSString *sentFolderName; NSString *trashFolderName; } diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index 7f3a66cb..f9d4d2b8 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -31,6 +31,7 @@ #import #import #import +#import #import #import @@ -40,17 +41,56 @@ @implementation UIxMailAccountActions -- (NSString *) _folderType: (NSString *) baseName +- (id) init +{ + if ((self = [super init])) + { + inboxFolderName = nil; + draftsFolderName = nil; + sentFolderName = nil; + trashFolderName = nil; + } + + return self; +} + +- (void) dealloc +{ + [inboxFolderName release]; + [draftsFolderName release]; + [sentFolderName release]; + [trashFolderName release]; + [super dealloc]; +} + +- (NSString *) _folderType: (NSString *) folderName { NSString *folderType; + SOGoMailAccount *co; + NSArray *specialFolders; - if ([baseName isEqualToString: @"INBOX"]) + if (!inboxFolderName) + { + co = [self clientObject]; + specialFolders = [[NSArray arrayWithObjects: + [co inboxFolderNameInContext: context], + [co draftsFolderNameInContext: context], + [co sentFolderNameInContext: context], + [co trashFolderNameInContext: context], + nil] stringsWithFormat: @"/%@"]; + ASSIGN (inboxFolderName, [specialFolders objectAtIndex: 0]); + ASSIGN (draftsFolderName, [specialFolders objectAtIndex: 1]); + ASSIGN (sentFolderName, [specialFolders objectAtIndex: 2]); + ASSIGN (trashFolderName, [specialFolders objectAtIndex: 3]); + } + + if ([folderName isEqualToString: inboxFolderName]) folderType = @"inbox"; - else if ([baseName isEqualToString: draftFolderName]) + else if ([folderName isEqualToString: draftsFolderName]) folderType = @"draft"; - else if ([baseName isEqualToString: sentFolderName]) + else if ([folderName isEqualToString: sentFolderName]) folderType = @"sent"; - else if ([baseName isEqualToString: trashFolderName]) + else if ([folderName isEqualToString: trashFolderName]) folderType = @"trash"; else folderType = @"folder"; @@ -58,34 +98,20 @@ return folderType; } -- (NSDictionary *) _lineForFolder: (NSString *) folder -{ - NSArray *parts; - NSMutableDictionary *folderData; - NSString *baseName; - - folderData = [NSMutableDictionary dictionary]; - parts = [folder componentsSeparatedByString: @"/"]; - baseName = [parts lastObject]; - [folderData setObject: folder forKey: @"path"]; - [folderData setObject: [self _folderType: baseName] - forKey: @"type"]; - - return folderData; -} - - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders { NSMutableArray *folders; NSString *currentFolder; + NSDictionary *folderData; folders = [NSMutableArray array]; - - currentFolder = [rawFolders nextObject]; - while (currentFolder) + while ((currentFolder = [rawFolders nextObject])) { - [folders addObject: [self _lineForFolder: currentFolder]]; - currentFolder = [rawFolders nextObject]; + folderData = [NSDictionary dictionaryWithObjectsAndKeys: + currentFolder, @"path", + [self _folderType: currentFolder], @"type", + nil]; + [folders addObject: folderData]; } return folders; @@ -94,19 +120,14 @@ - (WOResponse *) listMailboxesAction { SOGoMailAccount *co; - NSArray *rawFolders, *folders; + NSEnumerator *rawFolders; + NSArray *folders; WOResponse *response; co = [self clientObject]; - draftFolderName = [[co draftsFolderNameInContext: context] - substringFromIndex: 6]; - sentFolderName = [[co sentFolderNameInContext: context] - substringFromIndex: 6]; - trashFolderName = [[co trashFolderNameInContext: context] - substringFromIndex: 6]; - - rawFolders = [co allFolderPaths]; - folders = [self _jsonFolders: [rawFolders objectEnumerator]]; + + rawFolders = [[co allFolderPaths] objectEnumerator]; + folders = [self _jsonFolders: rawFolders]; response = [self responseWithStatus: 200]; [response setHeader: @"text/plain; charset=utf-8" diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index c78fade8..c80cc99b 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -140,7 +140,7 @@ trashFolderName = [[co mailAccountFolder] trashFolderNameInContext: context]; path = [NSString stringWithFormat: @"/%@/%@", - [trashFolderName substringFromIndex: 6], folderName]; + trashFolderName, folderName]; destURL = [[NSURL alloc] initWithScheme: [srcURL scheme] host: [srcURL host] path: path]; [destURL autorelease]; @@ -193,7 +193,7 @@ [mailSettings autorelease]; } [ud setObject: mailSettings forKey: @"Mail"]; - [mailSettings setObject: [co relativeImap4Name] + [mailSettings setObject: [co traversalFromMailAccount] forKey: [NSString stringWithFormat: @"%@Folder", purpose]]; [ud synchronize]; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 9c4ba4bd..adbf3bbd 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -1393,13 +1393,8 @@ function _onMenuChangeToXXXFolder(event, folder) { window.alert(labels["You need to choose a non-virtual folder!"]); else { var folderID = document.menuTarget.getAttribute("dataname"); - var number = folderID.split("/").length; - if (number > 3) - window.alert(labels["You need to choose a root subfolder!"]); - else { - var urlstr = URLForFolderID(folderID) + "/setAs" + folder + "Folder"; - triggerAjaxRequest(urlstr, folderOperationCallback); - } + var urlstr = URLForFolderID(folderID) + "/setAs" + folder + "Folder"; + triggerAjaxRequest(urlstr, folderOperationCallback); } } -- 2.39.5