]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailAccountActions.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1123 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailAccountActions.m
1 /* UIxMailAccountActions.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSEnumerator.h>
26
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>
32
33 #import "UIxMailAccountActions.h"
34
35 @implementation UIxMailAccountActions
36
37 - (NSString *) _folderType: (NSString *) baseName
38 {
39   NSString *folderType;
40
41   if ([baseName isEqualToString: @"INBOX"])
42     folderType = @"inbox";
43   else if ([baseName isEqualToString: draftFolderName])
44     folderType = @"draft";
45   else if ([baseName isEqualToString: sentFolderName])
46     folderType = @"sent";
47   else if ([baseName isEqualToString: trashFolderName])
48     folderType = @"trash";
49   else
50     folderType = @"folder";
51
52   return folderType;
53 }
54
55 - (NSDictionary *) _lineForFolder: (NSString *) folder
56 {
57   NSArray *parts;
58   NSMutableDictionary *folderData;
59   NSString *baseName;
60
61   folderData = [NSMutableDictionary dictionary];
62   parts = [folder componentsSeparatedByString: @"/"];
63   baseName = [parts lastObject];
64   [folderData setObject: folder forKey: @"path"];
65   [folderData setObject: [self _folderType: baseName]
66               forKey: @"type"];
67
68   return folderData;
69 }
70
71 - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
72 {
73   NSMutableArray *folders;
74   NSString *currentFolder;
75
76   folders = [NSMutableArray array];
77
78   currentFolder = [rawFolders nextObject];
79   while (currentFolder)
80     {
81       [folders addObject: [self _lineForFolder: currentFolder]];
82       currentFolder = [rawFolders nextObject];
83     }
84
85   return folders;
86 }
87
88 - (WOResponse *) listMailboxesAction
89 {
90   SOGoMailAccount *co;
91   NSArray *rawFolders, *folders;
92   WOResponse *response;
93
94   co = [self clientObject];
95   draftFolderName = [co draftsFolderNameInContext: context];
96   sentFolderName = [co sentFolderNameInContext: context];
97   trashFolderName = [co trashFolderNameInContext: context];
98
99   rawFolders = [co allFolderPaths];
100   folders = [self _jsonFolders: [rawFolders objectEnumerator]];
101
102   response = [context response];
103   [response appendContentString: [folders jsonRepresentation]];
104
105   return response;
106 }
107
108 @end