1 /* UIxMailActions.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/NSString.h>
26 #import <NGObjWeb/WOContext.h>
27 #import <NGObjWeb/WORequest.h>
28 #import <NGObjWeb/WOResponse.h>
29 #import <NGObjWeb/NSException+HTTP.h>
31 #import <SoObjects/Mailer/SOGoDraftObject.h>
32 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
33 #import <SoObjects/Mailer/SOGoMailAccount.h>
34 #import <SoObjects/Mailer/SOGoMailObject.h>
36 #import "../Common/WODirectAction+SOGo.h"
38 #import "UIxMailActions.h"
40 @implementation UIxMailActions
42 - (WOResponse *) replyToAll: (BOOL) toAll
44 SOGoMailAccount *account;
46 SOGoDraftsFolder *folder;
47 SOGoDraftObject *newMail;
48 NSString *newLocation;
50 co = [self clientObject];
51 account = [co mailAccountFolder];
52 folder = [account draftsFolderInContext: context];
53 newMail = [folder newDraft];
54 [newMail fetchMailForReplying: co toAll: toAll];
56 newLocation = [NSString stringWithFormat: @"%@/edit",
57 [newMail baseURLInContext: context]];
59 return [self redirectToLocation: newLocation];
62 - (WOResponse *) replyAction
64 return [self replyToAll: NO];
67 - (WOResponse *) replyToAllAction
69 return [self replyToAll: YES];
72 - (WOResponse *) forwardAction
74 SOGoMailAccount *account;
76 SOGoDraftsFolder *folder;
77 SOGoDraftObject *newMail;
78 NSString *newLocation;
80 co = [self clientObject];
81 account = [co mailAccountFolder];
82 folder = [account draftsFolderInContext: context];
83 newMail = [folder newDraft];
84 [newMail fetchMailForForwarding: co];
86 newLocation = [NSString stringWithFormat: @"%@/edit",
87 [newMail baseURLInContext: context]];
89 return [self redirectToLocation: newLocation];
96 response = [[self clientObject] trashInContext: context];
98 response = [self responseWith204];
105 NSString *destinationFolder;
108 destinationFolder = [[context request] formValueForKey: @"folder"];
109 if ([destinationFolder length] > 0)
111 response = [[self clientObject] moveToFolderNamed: destinationFolder
114 response = [self responseWith204];
117 response = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
118 reason: @"No destination folder given"];
125 NSString *destinationFolder;
128 destinationFolder = [[context request] formValueForKey: @"folder"];
129 if ([destinationFolder length] > 0)
131 response = [[self clientObject] copyToFolderNamed: destinationFolder
134 response = [self responseWith204];
137 response = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
138 reason: @"No destination folder given"];
145 - (id) markMessageUnreadAction
149 response = [[self clientObject] removeFlags: @"seen"];
151 response = [self responseWith204];
156 - (id) markMessageReadAction
160 response = [[self clientObject] addFlags: @"seen"];
162 response = [self responseWith204];
167 /* SOGoDraftObject */
168 - (WOResponse *) editAction
170 SOGoMailAccount *account;
172 SOGoDraftsFolder *folder;
173 SOGoDraftObject *newMail;
174 NSString *newLocation;
176 co = [self clientObject];
177 account = [co mailAccountFolder];
178 folder = [account draftsFolderInContext: context];
179 newMail = [folder newDraft];
180 [newMail fetchMailForEditing: co];
183 newLocation = [NSString stringWithFormat: @"%@/edit",
184 [newMail baseURLInContext: context]];
186 return [self redirectToLocation: newLocation];
191 SOGoDraftObject *draft;
195 draft = [self clientObject];
196 error = [draft delete];
200 response = [self responseWith204];
205 - (WOResponse *) deleteAttachmentAction
207 WOResponse *response;
210 filename = [[context request] formValueForKey: @"filename"];
211 if ([filename length] > 0)
213 response = [self responseWith204];
214 [[self clientObject] deleteAttachmentWithName: filename];
218 response = [self responseWithStatus: 500];
219 [response appendContentString: @"How did you end up here?"];
225 - (WOResponse *) _addLabel: (unsigned int) number
227 WOResponse *response;
232 co = [self clientObject];
233 flags = [NSArray arrayWithObject:
234 [NSString stringWithFormat: @"$Label%u", number]];
235 error = [co addFlags: flags];
237 response = (WOResponse *) error;
239 response = [self responseWith204];
244 - (WOResponse *) _removeLabel: (unsigned int) number
246 WOResponse *response;
251 co = [self clientObject];
252 flags = [NSArray arrayWithObject:
253 [NSString stringWithFormat: @"$Label%u", number]];
254 error = [co removeFlags: flags];
256 response = (WOResponse *) error;
258 response = [self responseWith204];
263 - (WOResponse *) addLabel1Action
265 return [self _addLabel: 1];
268 - (WOResponse *) addLabel2Action
270 return [self _addLabel: 2];
273 - (WOResponse *) addLabel3Action
275 return [self _addLabel: 3];
278 - (WOResponse *) addLabel4Action
280 return [self _addLabel: 4];
283 - (WOResponse *) addLabel5Action
285 return [self _addLabel: 5];
288 - (WOResponse *) removeLabel1Action
290 return [self _removeLabel: 1];
293 - (WOResponse *) removeLabel2Action
295 return [self _removeLabel: 2];
298 - (WOResponse *) removeLabel3Action
300 return [self _removeLabel: 3];
303 - (WOResponse *) removeLabel4Action
305 return [self _removeLabel: 4];
308 - (WOResponse *) removeLabel5Action
310 return [self _removeLabel: 5];
313 - (WOResponse *) removeAllLabelsAction
315 WOResponse *response;
320 co = [self clientObject];
321 flags = [NSArray arrayWithObjects: @"$Label1", @"$Label2", @"$Label3",
322 @"$Label4", @"$Label5", nil];
323 error = [co removeFlags: flags];
325 response = (WOResponse *) error;
327 response = [self responseWith204];