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/NSString.h>
25 #import <NGObjWeb/WOContext.h>
26 #import <NGObjWeb/WORequest.h>
27 #import <NGObjWeb/WOResponse.h>
28 #import <NGObjWeb/NSException+HTTP.h>
30 #import <SoObjects/Mailer/SOGoDraftObject.h>
31 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
32 #import <SoObjects/Mailer/SOGoMailAccount.h>
33 #import <SoObjects/Mailer/SOGoMailObject.h>
35 #import "../Common/WODirectAction+SOGo.h"
37 #import "UIxMailActions.h"
39 @implementation UIxMailActions
41 - (WOResponse *) replyToAll: (BOOL) toAll
43 SOGoMailAccount *account;
45 SOGoDraftsFolder *folder;
46 SOGoDraftObject *newMail;
47 NSString *newLocation;
49 co = [self clientObject];
50 account = [co mailAccountFolder];
51 folder = [account draftsFolderInContext: context];
52 newMail = [folder newDraft];
53 [newMail fetchMailForReplying: co toAll: toAll];
55 newLocation = [NSString stringWithFormat: @"%@/edit",
56 [newMail baseURLInContext: context]];
58 return [self redirectToLocation: newLocation];
61 - (WOResponse *) replyAction
63 return [self replyToAll: NO];
66 - (WOResponse *) replyToAllAction
68 return [self replyToAll: NO];
71 - (WOResponse *) forwardAction
73 SOGoMailAccount *account;
75 SOGoDraftsFolder *folder;
76 SOGoDraftObject *newMail;
77 NSString *newLocation;
79 co = [self clientObject];
80 account = [co mailAccountFolder];
81 folder = [account draftsFolderInContext: context];
82 newMail = [folder newDraft];
83 [newMail fetchMailForForwarding: co];
85 newLocation = [NSString stringWithFormat: @"%@/edit",
86 [newMail baseURLInContext: context]];
88 return [self redirectToLocation: newLocation];
95 response = [[self clientObject] trashInContext: context];
97 response = [self responseWith204];
104 NSString *destinationFolder;
107 destinationFolder = [[context request] formValueForKey: @"tofolder"];
108 if ([destinationFolder length] > 0)
110 response = [[self clientObject] moveToFolderNamed: destinationFolder
113 response = [self responseWith204];
116 response = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
117 reason: @"No destination folder given"];
124 - (id) markMessageUnreadAction
128 response = [[self clientObject] removeFlags: @"seen"];
130 response = [self responseWith204];
135 - (id) markMessageReadAction
139 response = [[self clientObject] addFlags: @"seen"];
141 response = [self responseWith204];
146 /* SOGoDraftObject */
147 - (WOResponse *) editAction
149 SOGoMailAccount *account;
151 SOGoDraftsFolder *folder;
152 SOGoDraftObject *newMail;
153 NSString *newLocation;
155 co = [self clientObject];
156 account = [co mailAccountFolder];
157 folder = [account draftsFolderInContext: context];
158 newMail = [folder newDraft];
159 [newMail fetchMailForEditing: co];
162 newLocation = [NSString stringWithFormat: @"%@/edit",
163 [newMail baseURLInContext: context]];
165 return [self redirectToLocation: newLocation];
170 SOGoDraftObject *draft;
174 draft = [self clientObject];
175 error = [draft delete];
179 response = [self responseWith204];
184 - (WOResponse *) deleteAttachmentAction
186 WOResponse *response;
189 filename = [[context request] formValueForKey: @"filename"];
190 if ([filename length] > 0)
192 response = [self responseWith204];
193 [[self clientObject] deleteAttachmentWithName: filename];
197 response = [self responseWithStatus: 500];
198 [response appendContentString: @"How did you end up here?"];