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 "UIxMailEditorAction.h"
24 #import <SoObjects/Mailer/SOGoDraftsFolder.h>
25 #import <SoObjects/Mailer/SOGoDraftObject.h>
26 #import <SoObjects/Mailer/SOGoMailAccount.h>
27 #import <SoObjects/Mailer/SOGoMailObject.h>
30 #import <SOGo/NSString+URL.h>
32 @implementation UIxMailEditorAction
36 [self->newDraft release];
43 [self->newDraft release]; self->newDraft = nil;
48 - (SOGoDraftsFolder *)draftsFolder {
50 Note: we cannot use acquisition to find the nearest drafts folder, because
51 the IMAP4 server might contains an own Drafts folder.
53 // SOGoDraftsFolder *drafts;
54 SOGoMailAccount *accountFolder;
56 accountFolder = [[self clientObject] mailAccountFolder];
59 lookupName: [accountFolder draftsFolderNameInContext: context]
60 inContext: context acquire: NO];
65 - (id)didNotFindDraftsError {
66 // TODO: make a nice error page
67 return [@"did not find drafts folder in object: "
68 stringByAppendingString:[[self clientObject] description]];
70 - (id)couldNotCreateDraftError:(SOGoDraftsFolder *)_draftsFolder {
71 return [@"could not create a new draft in folder: "
72 stringByAppendingString:[_draftsFolder description]];
74 - (id)didNotFindMailError {
75 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
76 reason:@"Did not find mail for operation!"];
83 SOGoDraftsFolder *drafts;
85 NSString *urlBase, *url;
86 NSMutableDictionary *urlParams;
90 drafts = [self draftsFolder];
91 if ([drafts isNotNull])
93 if ([drafts isKindOfClass: [NSException class]])
97 urlBase = [drafts newObjectBaseURLInContext: context];
98 if ([urlBase isNotNull])
100 urlParams = [NSMutableDictionary new];
101 [urlParams autorelease];
103 /* attach mail-account info */
105 = [[self clientObject] valueForKey: @"mailAccountFolder"];
106 if (parameter && ![parameter isExceptionOrNull])
107 [urlParams setObject: [parameter nameInContainer]
110 parameter = [[self request] formValueForKey: @"mailto"];
112 [urlParams setObject: parameter
115 url = [urlBase composeURLWithAction: @"edit"
116 parameters: urlParams
119 /* perform redirect */
121 [self debugWithFormat:@"compose on %@: %@", drafts, url];
123 r = [context response];
124 [r setStatus: 302 /* move d */];
125 [r setHeader: url forKey: @"location"];
131 returnValue = [self couldNotCreateDraftError: drafts];
135 returnValue = [self didNotFindDraftsError];
140 /* creating new draft object */
142 - (id)newDraftObject {
143 SOGoDraftsFolder *drafts;
145 drafts = [self draftsFolder];
146 if (![drafts isNotNull])
147 return [self didNotFindDraftsError];
148 if ([drafts isKindOfClass:[NSException class]])
151 return [drafts newObjectInContext:context];
154 - (NSException *)_setupNewDraft {
155 SOGoDraftObject *tmp;
157 /* create draft object */
159 if ([(tmp = [self newDraftObject]) isKindOfClass:[NSException class]])
160 return (NSException *)tmp;
161 if (![tmp isNotNull]) { /* Note: should never happen? */
162 [self logWithFormat:@"WARNING: got no new draft object and no error!"];
163 return [self didNotFindDraftsError]; // TODO: not exact
166 ASSIGN(self->newDraft, tmp);
167 //[self debugWithFormat:@"NEW DRAFT: %@", self->newDraft];
172 - (WOResponse *)redirectToEditNewDraft {
176 if (![self->newDraft isNotNull]) {
177 [self logWithFormat:@"ERROR(%s): missing new draft (already -reset?)",
178 __PRETTY_FUNCTION__];
182 url = [self->newDraft baseURLInContext:context];
183 if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
184 url = [url stringByAppendingString:@"edit"];
187 [self logWithFormat:@"compose on %@", url];
189 r = [context response];
190 [r setStatus:302 /* moved */];
191 [r setHeader:url forKey:@"location"];
196 @end /* UIxMailEditorAction */