1 /* UIxMailFolderActions.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>
26 #import <Foundation/NSURL.h>
28 #import <NGObjWeb/WOContext.h>
29 #import <NGObjWeb/WOResponse.h>
30 #import <NGObjWeb/WORequest.h>
31 #import <NGImap4/NGImap4Connection.h>
33 #import <SoObjects/Mailer/SOGoMailFolder.h>
34 #import <SoObjects/Mailer/SOGoTrashFolder.h>
35 #import <SoObjects/Mailer/SOGoMailAccount.h>
37 #import "UIxMailFolderActions.h"
39 @implementation UIxMailFolderActions
41 - (WOResponse *) createFolderAction
45 NGImap4Connection *connection;
49 co = [self clientObject];
50 response = [context response];
52 folderName = [[context request] formValueForKey: @"name"];
53 if ([folderName length] > 0)
55 connection = [co imap4Connection];
56 error = [connection createMailbox: folderName atURL: [co imap4URL]];
59 [response setStatus: 403];
60 [response appendContentString: @"Unable to create folder."];
63 [response setStatus: 204];
67 [response setStatus: 403];
68 [response appendContentString: @"Missing 'name' parameter."];
74 - (NSURL *) _urlOfFolder: (NSURL *) srcURL
75 renamedTo: (NSString *) folderName
80 path = [[srcURL path] stringByDeletingLastPathComponent];
82 destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
84 path: [NSString stringWithFormat: @"%@%@",
86 [destURL autorelease];
91 - (WOResponse *) renameFolderAction
95 NGImap4Connection *connection;
98 NSURL *srcURL, *destURL;
100 co = [self clientObject];
101 response = [context response];
103 folderName = [[context request] formValueForKey: @"name"];
104 if ([folderName length] > 0)
106 srcURL = [co imap4URL];
107 destURL = [self _urlOfFolder: srcURL renamedTo: folderName];
108 connection = [co imap4Connection];
109 error = [connection moveMailboxAtURL: srcURL
113 [response setStatus: 403];
114 [response appendContentString: @"Unable to rename folder."];
117 [response setStatus: 204];
121 [response setStatus: 403];
122 [response appendContentString: @"Missing 'name' parameter."];
128 - (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL
129 withCO: (SOGoMailFolder *) co
132 NSString *trashFolderName, *folderName;
134 folderName = [[srcURL path] lastPathComponent];
136 = [[co mailAccountFolder] trashFolderNameInContext: context];
138 destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
140 path: [NSString stringWithFormat: @"/%@/%@",
141 trashFolderName, folderName]];
142 [destURL autorelease];
147 - (WOResponse *) deleteFolderAction
150 WOResponse *response;
151 NGImap4Connection *connection;
153 NSURL *srcURL, *destURL;
155 co = [self clientObject];
156 response = [context response];
157 connection = [co imap4Connection];
158 srcURL = [co imap4URL];
159 destURL = [self _trashedURLOfFolder: srcURL
161 connection = [co imap4Connection];
162 error = [connection moveMailboxAtURL: srcURL
166 [response setStatus: 403];
167 [response appendContentString: @"Unable to move folder."];
170 [response setStatus: 204];
175 - (WOResponse *) emptyTrashAction
179 NSEnumerator *subfolders;
180 WOResponse *response;
181 NGImap4Connection *connection;
184 co = [self clientObject];
185 response = [context response];
187 error = [co addFlagsToAllMessages: @"deleted"];
189 error = [co expunge];
192 [co flushMailCaches];
193 connection = [co imap4Connection];
194 subfolders = [[co subfoldersURL] objectEnumerator];
195 currentURL = [subfolders nextObject];
198 [connection deleteMailboxAtURL: currentURL];
199 currentURL = [subfolders nextObject];
204 [response setStatus: 403];
205 [response appendContentString: @"Unable to empty the trash folder."];
208 [response setStatus: 204];
213 #warning here should be done what should be done: IMAP subscription
214 - (WOResponse *) _subscriptionStubAction
216 NSString *mailInvitationParam, *mailInvitationURL;
217 WOResponse *response;
218 SOGoMailFolder *clientObject;
220 response = [context response];
222 = [[context request] formValueForKey: @"mail-invitation"];
223 if ([mailInvitationParam boolValue])
225 clientObject = [self clientObject];
227 = [[clientObject soURLToBaseContainerForCurrentUser]
229 [response setStatus: 302];
230 [response setHeader: mailInvitationURL
231 forKey: @"location"];
235 [response setStatus: 403];
236 [response appendContentString: @"How did you end up here?"];
242 - (WOResponse *) subscribeAction
244 return [self _subscriptionStubAction];
247 - (WOResponse *) unsubscribeAction
249 return [self _subscriptionStubAction];