+2007-11-01 Wolfgang Sourdeau <wsourdeau@inverse.ca>
+
+ * 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 <wsourdeau@inverse.ca>
* SoObjects/Mailer/SOGoMailFolder.[hm]: added a new subclass of
@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 */
- (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;
#import <SoObjects/SOGo/NSArray+Utilities.h>
#import <SoObjects/SOGo/SOGoUser.h>
+#import "SOGoDraftsFolder.h"
#import "SOGoMailFolder.h"
#import "SOGoMailManager.h"
-#import "SOGoDraftsFolder.h"
+#import "SOGoSentFolder.h"
+#import "SOGoTrashFolder.h"
#import "SOGoMailAccount.h"
- (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 */
/* 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];
- (NSString *) inboxFolderNameInContext: (id)_ctx
{
/* cannot be changed in Cyrus ? */
- return [NSString stringWithFormat: @"folder%@", inboxFolderName];
+ return inboxFolderName;
}
- (NSString *) _userFolderNameWithPurpose: (NSString *) purpose
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
{
if (!folderName)
folderName = sentFolderName;
- return [NSString stringWithFormat: @"folder%@", folderName];
+ return folderName;
}
- (NSString *) trashFolderNameInContext: (id)_ctx
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
// 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];
}
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];
}
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;
}
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]])
{
// 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;
}
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;
uidColumnName, [self uid]];
[values release];
- values = [NSMutableDictionary new];
/* run SQL */
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]);
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;
= [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;
}
"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!";
"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.";
"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!";
@interface UIxMailAccountActions : WODirectAction
{
- NSString *draftFolderName;
+ NSString *inboxFolderName;
+ NSString *draftsFolderName;
NSString *sentFolderName;
NSString *trashFolderName;
}
#import <SoObjects/Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoDraftObject.h>
#import <SoObjects/Mailer/SOGoDraftsFolder.h>
+#import <SoObjects/SOGo/NSArray+Utilities.h>
#import <SoObjects/SOGo/NSObject+Utilities.h>
#import <SoObjects/SOGo/NSString+Utilities.h>
@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";
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;
- (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"
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];
[mailSettings autorelease];
}
[ud setObject: mailSettings forKey: @"Mail"];
- [mailSettings setObject: [co relativeImap4Name]
+ [mailSettings setObject: [co traversalFromMailAccount]
forKey: [NSString stringWithFormat: @"%@Folder",
purpose]];
[ud synchronize];
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);
}
}