1 /* UIxMailAccountActions.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSEnumerator.h>
27 #import <NGObjWeb/WOContext.h>
28 #import <NGObjWeb/WOResponse.h>
29 #import <NGImap4/NGImap4Connection.h>
30 #import <SoObjects/Mailer/SOGoMailAccount.h>
31 #import <SoObjects/SOGo/NSObject+Utilities.h>
33 #import "UIxMailAccountActions.h"
35 @implementation UIxMailAccountActions
37 - (NSString *) _folderType: (NSString *) baseName
41 if ([baseName isEqualToString: @"INBOX"])
42 folderType = @"inbox";
43 else if ([baseName isEqualToString: draftFolderName])
44 folderType = @"draft";
45 else if ([baseName isEqualToString: sentFolderName])
47 else if ([baseName isEqualToString: trashFolderName])
48 folderType = @"trash";
50 folderType = @"folder";
55 - (NSDictionary *) _lineForFolder: (NSString *) folder
58 NSMutableDictionary *folderData;
61 folderData = [NSMutableDictionary dictionary];
62 parts = [folder componentsSeparatedByString: @"/"];
63 baseName = [parts lastObject];
64 [folderData setObject: folder forKey: @"path"];
65 [folderData setObject: [self _folderType: baseName]
71 - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
73 NSMutableArray *folders;
74 NSString *currentFolder;
76 folders = [NSMutableArray array];
78 currentFolder = [rawFolders nextObject];
81 [folders addObject: [self _lineForFolder: currentFolder]];
82 currentFolder = [rawFolders nextObject];
88 - (WOResponse *) listMailboxesAction
91 NSArray *rawFolders, *folders;
94 co = [self clientObject];
95 draftFolderName = [co draftsFolderNameInContext: context];
96 sentFolderName = [co sentFolderNameInContext: context];
97 trashFolderName = [co trashFolderNameInContext: context];
99 rawFolders = [co allFolderPaths];
100 folders = [self _jsonFolders: [rawFolders objectEnumerator]];
102 response = [context response];
103 [response appendContentString: [folders jsonRepresentation]];