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/WORequest.h>
29 #import <NGObjWeb/WOResponse.h>
30 #import <NGImap4/NGImap4Connection.h>
31 #import <SoObjects/Mailer/SOGoMailAccount.h>
32 #import <SoObjects/Mailer/SOGoDraftObject.h>
33 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
34 #import <SoObjects/SOGo/NSObject+Utilities.h>
35 #import <SoObjects/SOGo/NSString+Utilities.h>
37 #import "../Common/WODirectAction+SOGo.h"
39 #import "UIxMailAccountActions.h"
41 @implementation UIxMailAccountActions
43 - (NSString *) _folderType: (NSString *) baseName
47 if ([baseName isEqualToString: @"INBOX"])
48 folderType = @"inbox";
49 else if ([baseName isEqualToString: draftFolderName])
50 folderType = @"draft";
51 else if ([baseName isEqualToString: sentFolderName])
53 else if ([baseName isEqualToString: trashFolderName])
54 folderType = @"trash";
56 folderType = @"folder";
61 - (NSDictionary *) _lineForFolder: (NSString *) folder
64 NSMutableDictionary *folderData;
67 folderData = [NSMutableDictionary dictionary];
68 parts = [folder componentsSeparatedByString: @"/"];
69 baseName = [parts lastObject];
70 [folderData setObject: folder forKey: @"path"];
71 [folderData setObject: [self _folderType: baseName]
77 - (NSArray *) _jsonFolders: (NSEnumerator *) rawFolders
79 NSMutableArray *folders;
80 NSString *currentFolder;
82 folders = [NSMutableArray array];
84 currentFolder = [rawFolders nextObject];
87 [folders addObject: [self _lineForFolder: currentFolder]];
88 currentFolder = [rawFolders nextObject];
94 - (WOResponse *) listMailboxesAction
97 NSArray *rawFolders, *folders;
100 co = [self clientObject];
101 draftFolderName = [[co draftsFolderNameInContext: context]
102 substringFromIndex: 6];
103 sentFolderName = [[co sentFolderNameInContext: context]
104 substringFromIndex: 6];
105 trashFolderName = [[co trashFolderNameInContext: context]
106 substringFromIndex: 6];
108 rawFolders = [co allFolderPaths];
109 folders = [self _jsonFolders: [rawFolders objectEnumerator]];
111 response = [self responseWithStatus: 200];
112 [response setHeader: @"text/plain; charset=utf-8"
113 forKey: @"content-type"];
114 [response appendContentString: [folders jsonRepresentation]];
121 - (WOResponse *) composeAction
123 SOGoDraftsFolder *drafts;
124 SOGoDraftObject *newDraftMessage;
125 NSString *urlBase, *url, *value;
129 drafts = [[self clientObject] draftsFolderInContext: context];
130 newDraftMessage = [drafts newDraft];
132 value = [[self request] formValueForKey: @"mailto"];
133 if ([value length] > 0)
135 mailTo = [NSArray arrayWithObject: value];
136 [newDraftMessage setHeaders: [NSDictionary dictionaryWithObject: mailTo
138 [newDraftMessage storeInfo];
141 urlBase = [newDraftMessage baseURLInContext: context];
142 url = [urlBase composeURLWithAction: @"edit"
146 return [self redirectToLocation: url];