]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailActions.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1173 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailActions.m
1 /* UIxMailActions.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/NSString.h>
24
25 #import <NGObjWeb/WOContext.h>
26 #import <NGObjWeb/WORequest.h>
27 #import <NGObjWeb/WOResponse.h>
28 #import <NGObjWeb/NSException+HTTP.h>
29
30 #import <SoObjects/Mailer/SOGoDraftObject.h>
31 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
32 #import <SoObjects/Mailer/SOGoMailAccount.h>
33 #import <SoObjects/Mailer/SOGoMailObject.h>
34
35 #import "../Common/WODirectAction+SOGo.h"
36
37 #import "UIxMailActions.h"
38
39 @implementation UIxMailActions
40
41 - (WOResponse *) replyToAll: (BOOL) toAll
42 {
43   SOGoMailAccount *account;
44   SOGoMailObject *co;
45   SOGoDraftsFolder *folder;
46   SOGoDraftObject *newMail;
47   NSString *newLocation;
48
49   co = [self clientObject];
50   account = [co mailAccountFolder];
51   folder = [account draftsFolderInContext: context];
52   newMail = [folder newDraft];
53   [newMail fetchMailForReplying: co toAll: toAll];
54
55   newLocation = [NSString stringWithFormat: @"%@/edit",
56                           [newMail baseURLInContext: context]];
57
58   return [self redirectToLocation: newLocation];
59 }
60
61 - (WOResponse *) replyAction
62 {
63   return [self replyToAll: NO];
64 }
65
66 - (WOResponse *) replyToAllAction
67 {
68   return [self replyToAll: NO];
69 }
70
71 - (WOResponse *) forwardAction
72 {
73   SOGoMailAccount *account;
74   SOGoMailObject *co;
75   SOGoDraftsFolder *folder;
76   SOGoDraftObject *newMail;
77   NSString *newLocation;
78
79   co = [self clientObject];
80   account = [co mailAccountFolder];
81   folder = [account draftsFolderInContext: context];
82   newMail = [folder newDraft];
83   [newMail fetchMailForForwarding: co];
84
85   newLocation = [NSString stringWithFormat: @"%@/edit",
86                           [newMail baseURLInContext: context]];
87
88   return [self redirectToLocation: newLocation];
89 }
90
91 - (id) trashAction
92 {
93   id response;
94
95   response = [[self clientObject] trashInContext: context];
96   if (!response)
97     response = [self responseWith204];
98
99   return response;
100 }
101
102 - (id) moveAction
103 {
104   NSString *destinationFolder;
105   id response;
106
107   destinationFolder = [[context request] formValueForKey: @"tofolder"];
108   if ([destinationFolder length] > 0)
109     {
110       response = [[self clientObject] moveToFolderNamed: destinationFolder
111                                       inContext: context];
112       if (!response)
113         response = [self responseWith204];
114     }
115   else
116     response = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
117                             reason: @"No destination folder given"];
118
119   return response;
120 }
121
122 /* active message */
123
124 - (id) markMessageUnreadAction 
125 {
126   id response;
127
128   response = [[self clientObject] removeFlags: @"seen"];
129   if (!response)
130     response = [self responseWith204];
131
132   return response;
133 }
134
135 - (id) markMessageReadAction 
136 {
137   id response;
138
139   response = [[self clientObject] addFlags: @"seen"];
140   if (!response)
141     response = [self responseWith204];
142
143   return response;
144 }
145
146 /* SOGoDraftObject */
147 - (WOResponse *) editAction
148 {
149   SOGoMailAccount *account;
150   SOGoMailObject *co;
151   SOGoDraftsFolder *folder;
152   SOGoDraftObject *newMail;
153   NSString *newLocation;
154
155   co = [self clientObject];
156   account = [co mailAccountFolder];
157   folder = [account draftsFolderInContext: context];
158   newMail = [folder newDraft];
159   [newMail fetchMailForEditing: co];
160   [newMail storeInfo];
161
162   newLocation = [NSString stringWithFormat: @"%@/edit",
163                           [newMail baseURLInContext: context]];
164
165   return [self redirectToLocation: newLocation];
166 }
167
168 - (id) deleteAction
169 {
170   SOGoDraftObject *draft;
171   NSException *error;
172   id response;
173
174   draft = [self clientObject];
175   error = [draft delete];
176   if (error)
177     response = error;
178   else
179     response = [self responseWith204];
180
181   return response;
182 }
183
184 - (WOResponse *) deleteAttachmentAction
185 {
186   WOResponse *response;
187   NSString *filename;
188
189   filename = [[context request] formValueForKey: @"filename"];
190   if ([filename length] > 0)
191     {
192       response = [self responseWith204];
193       [[self clientObject] deleteAttachmentWithName: filename];
194     }
195   else
196     {
197       response = [self responseWithStatus: 500];
198       [response appendContentString: @"How did you end up here?"];
199     }
200
201   return response;
202 }
203
204 @end