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 #include "UIxMailEditorAction.h"
24 #include <SoObjects/Mailer/SOGoDraftsFolder.h>
25 #include <SoObjects/Mailer/SOGoDraftObject.h>
26 #include <SoObjects/Mailer/SOGoMailAccount.h>
27 #include <SoObjects/Mailer/SOGoMailObject.h>
30 @implementation UIxMailEditorAction
33 [self->newDraft release];
40 [self->newDraft release]; self->newDraft = nil;
45 - (SOGoDraftsFolder *)draftsFolder {
47 Note: we cannot use acquisition to find the nearest drafts folder, because
48 the IMAP4 server might contains an own Drafts folder.
50 SOGoDraftsFolder *drafts;
53 client = [self clientObject];
54 drafts = [[client mailAccountFolder]
55 lookupName:@"Drafts" inContext:[self context] acquire:NO];
61 - (id)didNotFindDraftsError {
62 // TODO: make a nice error page
63 return [@"did not find drafts folder in object: "
64 stringByAppendingString:[[self clientObject] description]];
66 - (id)couldNotCreateDraftError:(SOGoDraftsFolder *)_draftsFolder {
67 return [@"could not create a new draft in folder: "
68 stringByAppendingString:[_draftsFolder description]];
70 - (id)didNotFindMailError {
71 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
72 reason:@"Did not find mail for operation!"];
78 SOGoDraftsFolder *drafts;
83 drafts = [self draftsFolder];
84 if (![drafts isNotNull])
85 return [self didNotFindDraftsError];
86 if ([drafts isKindOfClass:[NSException class]])
89 url = [drafts newObjectBaseURLInContext:[self context]];
91 return [self couldNotCreateDraftError:drafts];
93 if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
94 url = [url stringByAppendingString:@"edit"];
96 /* attach mail-account info */
98 accountFolder = [[self clientObject] valueForKey:@"mailAccountFolder"];
99 if (![accountFolder isExceptionOrNull]) {
100 url = [url stringByAppendingString:@"?account="];
101 url = [url stringByAppendingString:[accountFolder nameInContainer]];
104 /* perform redirect */
106 [self debugWithFormat:@"compose on %@: %@", drafts, url];
108 r = [[self context] response];
109 [r setStatus:302 /* moved */];
110 [r setHeader:url forKey:@"location"];
115 /* creating new draft object */
117 - (id)newDraftObject {
118 SOGoDraftsFolder *drafts;
120 drafts = [self draftsFolder];
121 if (![drafts isNotNull])
122 return [self didNotFindDraftsError];
123 if ([drafts isKindOfClass:[NSException class]])
126 return [drafts newObjectInContext:[self context]];
129 - (NSException *)_setupNewDraft {
130 SOGoDraftObject *tmp;
132 /* create draft object */
134 if ([(tmp = [self newDraftObject]) isKindOfClass:[NSException class]])
135 return (NSException *)tmp;
136 if (![tmp isNotNull]) { /* Note: should never happen? */
137 [self logWithFormat:@"WARNING: got no new draft object and no error!"];
138 return [self didNotFindDraftsError]; // TODO: not exact
141 ASSIGN(self->newDraft, tmp);
142 //[self debugWithFormat:@"NEW DRAFT: %@", self->newDraft];
147 - (WOResponse *)redirectToEditNewDraft {
151 if (![self->newDraft isNotNull]) {
152 [self logWithFormat:@"ERROR(%s): missing new draft (already -reset?)",
153 __PRETTY_FUNCTION__];
157 url = [self->newDraft baseURLInContext:[self context]];
158 if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
159 url = [url stringByAppendingString:@"edit"];
162 [self logWithFormat:@"compose on %@", url];
164 r = [[self context] response];
165 [r setStatus:302 /* moved */];
166 [r setHeader:url forKey:@"location"];
171 @end /* UIxMailEditorAction */