diff --git a/ChangeLog b/ChangeLog index 0c7a106ad..daf4ef975 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-05-25 Wolfgang Sourdeau + * UI/MailerUI/UIxMailAccountActions.m ([UIxMailAccountActions + -listMailboxesAction]): new method that returns a json-formatted + tree of all the mailboxes available to the current user. + + * UI/MailerUI/UIxMailAccountActions.[hm]: new module implementing + web actions related to the handling of mail accounts. + * SoObjects/SOGo/NSDictionary+Utilities.[hm]: new extension module. diff --git a/UI/MailerUI/UIxMailAccountActions.h b/UI/MailerUI/UIxMailAccountActions.h new file mode 100644 index 000000000..36d55657e --- /dev/null +++ b/UI/MailerUI/UIxMailAccountActions.h @@ -0,0 +1,43 @@ +/* UIxMailAccountActions.h - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef UIXMAILACCOUNTACTIONS_H +#define UIXMAILACCOUNTACTIONS_H + +#import + +@class WOResponse; + +@interface UIxMailAccountActions : WODirectAction +{ + NSString *draftFolderName; + NSString *sentFolderName; + NSString *trashFolderName; + NSString *sharedFolderName; + NSString *otherUsersFolderName; +} + +- (WOResponse *) listMailboxesAction; + +@end + +#endif /* UIXMAILACCOUNTACTIONS_H */ diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m new file mode 100644 index 000000000..b2c8dbbb6 --- /dev/null +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -0,0 +1,121 @@ +/* UIxMailAccountActions.m - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import +#import + +#import +#import +#import +#import +#import + +#import "UIxMailAccountActions.h" + +@implementation UIxMailAccountActions + +- (NSString *) _folderType: (NSString *) baseName +{ + NSString *folderType; + + if ([baseName isEqualToString: @"INBOX"]) + folderType = @"inbox"; + else if ([baseName isEqualToString: draftFolderName]) + folderType = @"draft"; + else if ([baseName isEqualToString: sentFolderName]) + folderType = @"sent"; + else if ([baseName 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; + + folders = [NSMutableArray array]; + + currentFolder = [rawFolders nextObject]; + while (currentFolder) + { + [folders addObject: [self _lineForFolder: currentFolder]]; + currentFolder = [rawFolders nextObject]; + } + + return folders; +} + +- (WOResponse *) listMailboxesAction +{ + SOGoMailAccount *clientObject; + NSArray *rawFolders, *folders, *mainFolders; + NSMutableArray *newFolders; + WOResponse *response; + + clientObject = [self clientObject]; + rawFolders = [[clientObject imap4Connection] + allFoldersForURL: [clientObject imap4URL]]; + + draftFolderName = [clientObject draftsFolderNameInContext: context]; + sentFolderName = [clientObject sentFolderNameInContext: context]; + trashFolderName = [clientObject trashFolderNameInContext: context]; + sharedFolderName = [clientObject sharedFolderName]; + otherUsersFolderName = [clientObject otherUsersFolderName]; + mainFolders = [NSArray arrayWithObjects: @"INBOX", draftFolderName, + sentFolderName, trashFolderName, nil]; + + newFolders = [NSMutableArray arrayWithArray: rawFolders]; + [newFolders removeObjectsInArray: mainFolders]; + [newFolders sortUsingSelector: @selector (caseInsensitiveCompare:)]; + [newFolders replaceObjectsInRange: NSMakeRange (0, 0) + withObjectsFromArray: mainFolders]; + + folders = [self _jsonFolders: [newFolders objectEnumerator]]; + + response = [context response]; + [response appendContentString: [folders jsonRepresentation]]; + + return response; +} + +@end