]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailActions.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1158 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 <SoObjects/Mailer/SOGoDraftObject.h>
29 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
30 #import <SoObjects/Mailer/SOGoMailAccount.h>
31 #import <SoObjects/Mailer/SOGoMailObject.h>
32
33 #import "../Common/WODirectAction+SOGo.h"
34
35 #import "UIxMailActions.h"
36
37 @implementation UIxMailActions
38
39 - (WOResponse *) editAction
40 {
41   SOGoMailAccount *account;
42   SOGoMailObject *co;
43   SOGoDraftsFolder *folder;
44   SOGoDraftObject *newMail;
45   NSString *newLocation;
46
47   co = [self clientObject];
48   account = [co mailAccountFolder];
49   folder = [account draftsFolderInContext: context];
50   newMail = [folder newDraft];
51   [newMail fetchMailForEditing: co];
52   [newMail storeInfo];
53
54   newLocation = [NSString stringWithFormat: @"%@/edit",
55                           [newMail baseURLInContext: context]];
56
57   return [self redirectToLocation: newLocation];
58 }
59
60 - (WOResponse *) replyToAll: (BOOL) toAll
61 {
62   SOGoMailAccount *account;
63   SOGoMailObject *co;
64   SOGoDraftsFolder *folder;
65   SOGoDraftObject *newMail;
66   NSString *newLocation;
67
68   co = [self clientObject];
69   account = [co mailAccountFolder];
70   folder = [account draftsFolderInContext: context];
71   newMail = [folder newDraft];
72   [newMail fetchMailForReplying: co toAll: toAll];
73
74   newLocation = [NSString stringWithFormat: @"%@/edit",
75                           [newMail baseURLInContext: context]];
76
77   return [self redirectToLocation: newLocation];
78 }
79
80 - (WOResponse *) replyAction
81 {
82   return [self replyToAll: NO];
83 }
84
85 - (WOResponse *) replyToAllAction
86 {
87   return [self replyToAll: NO];
88 }
89
90 - (WOResponse *) forwardAction
91 {
92   SOGoMailAccount *account;
93   SOGoMailObject *co;
94   SOGoDraftsFolder *folder;
95   SOGoDraftObject *newMail;
96   NSString *newLocation;
97
98   co = [self clientObject];
99   account = [co mailAccountFolder];
100   folder = [account draftsFolderInContext: context];
101   newMail = [folder newDraft];
102   [newMail fetchMailForForwarding: co];
103
104   newLocation = [NSString stringWithFormat: @"%@/edit",
105                           [newMail baseURLInContext: context]];
106
107   return [self redirectToLocation: newLocation];
108 }
109
110 /* SOGoDraftObject */
111 - (id) deleteAction
112 {
113   SOGoDraftObject *draft;
114   NSException *error;
115   id response;
116
117   draft = [self clientObject];
118   error = [draft delete];
119   if (error)
120     response = error;
121   else
122     {
123       response = [context response];
124       [response setStatus: 204];
125     }
126
127   return response;
128 }
129
130 - (WOResponse *) deleteAttachmentAction
131 {
132   WOResponse *response;
133   NSString *filename;
134
135   response = [context response];
136
137   filename = [[context request] formValueForKey: @"filename"];
138   if ([filename length] > 0)
139     {
140       [[self clientObject] deleteAttachmentWithName: filename];
141       [response setStatus: 204];
142     }
143   else
144     {
145       [response setStatus: 500];
146       [response appendContentString: @"How did you end up here?"];
147     }
148
149   return response;
150 }
151
152 @end