2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/NSDictionary.h>
24 #import <NGObjWeb/WOContext.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <NGObjWeb/WOResponse.h>
27 #import <NGObjWeb/NSException+HTTP.h>
28 #import <NGExtensions/NSNull+misc.h>
29 #import <NGExtensions/NSException+misc.h>
31 #import <SoObjects/SOGo/NSString+Utilities.h>
32 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
33 #import <SoObjects/Mailer/SOGoDraftObject.h>
34 #import <SoObjects/Mailer/SOGoMailAccount.h>
35 #import <SoObjects/Mailer/SOGoMailObject.h>
37 #import "UIxMailEditorAction.h"
39 @implementation UIxMailEditorAction
43 [self->newDraft release];
50 [self->newDraft release]; self->newDraft = nil;
55 - (SOGoDraftsFolder *)draftsFolder {
57 Note: we cannot use acquisition to find the nearest drafts folder, because
58 the IMAP4 server might contains an own Drafts folder.
60 // SOGoDraftsFolder *drafts;
61 SOGoMailAccount *accountFolder;
63 accountFolder = [[self clientObject] mailAccountFolder];
66 lookupName: [accountFolder draftsFolderNameInContext: context]
67 inContext: context acquire: NO];
72 - (id)didNotFindDraftsError {
73 // TODO: make a nice error page
74 return [@"did not find drafts folder in object: "
75 stringByAppendingString:[[self clientObject] description]];
77 - (id)couldNotCreateDraftError:(SOGoDraftsFolder *)_draftsFolder {
78 return [@"could not create a new draft in folder: "
79 stringByAppendingString:[_draftsFolder description]];
81 - (id)didNotFindMailError {
82 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
83 reason:@"Did not find mail for operation!"];
90 SOGoDraftsFolder *drafts;
92 NSString *urlBase, *url;
93 NSMutableDictionary *urlParams;
97 drafts = [self draftsFolder];
98 if ([drafts isNotNull])
100 if ([drafts isKindOfClass: [NSException class]])
101 returnValue = drafts;
104 urlBase = [drafts newObjectBaseURLInContext: context];
105 if ([urlBase isNotNull])
107 urlParams = [NSMutableDictionary new];
108 [urlParams autorelease];
110 /* attach mail-account info */
112 = [[self clientObject] valueForKey: @"mailAccountFolder"];
113 if (parameter && ![parameter isExceptionOrNull])
114 [urlParams setObject: [parameter nameInContainer]
117 parameter = [[self request] formValueForKey: @"mailto"];
119 [urlParams setObject: parameter
122 url = [urlBase composeURLWithAction: @"edit"
123 parameters: urlParams
126 /* perform redirect */
128 [self debugWithFormat:@"compose on %@: %@", drafts, url];
130 r = [context response];
131 [r setStatus: 302 /* move d */];
132 [r setHeader: url forKey: @"location"];
138 returnValue = [self couldNotCreateDraftError: drafts];
142 returnValue = [self didNotFindDraftsError];
147 /* creating new draft object */
149 - (id)newDraftObject {
150 SOGoDraftsFolder *drafts;
152 drafts = [self draftsFolder];
153 if (![drafts isNotNull])
154 return [self didNotFindDraftsError];
155 if ([drafts isKindOfClass:[NSException class]])
158 return [drafts newObjectInContext:context];
161 - (NSException *)_setupNewDraft {
162 SOGoDraftObject *tmp;
164 /* create draft object */
166 if ([(tmp = [self newDraftObject]) isKindOfClass:[NSException class]])
167 return (NSException *)tmp;
168 if (![tmp isNotNull]) { /* Note: should never happen? */
169 [self logWithFormat:@"WARNING: got no new draft object and no error!"];
170 return [self didNotFindDraftsError]; // TODO: not exact
173 ASSIGN(self->newDraft, tmp);
174 //[self debugWithFormat:@"NEW DRAFT: %@", self->newDraft];
179 - (WOResponse *)redirectToEditNewDraft {
183 if (![self->newDraft isNotNull]) {
184 [self logWithFormat:@"ERROR(%s): missing new draft (already -reset?)",
185 __PRETTY_FUNCTION__];
189 url = [self->newDraft baseURLInContext:context];
190 if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
191 url = [url stringByAppendingString:@"edit"];
194 [self logWithFormat:@"compose on %@", url];
196 r = [context response];
197 [r setStatus:302 /* moved */];
198 [r setHeader:url forKey:@"location"];
203 @end /* UIxMailEditorAction */