2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-07-27 19:34:32 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSException+misc.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-27 19:34:32 +02:00
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2006-10-03 18:14:11 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoDraftsFolder.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoDraftObject.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailAccount.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailObject.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-27 19:34:32 +02:00
|
|
|
#import "UIxMailEditorAction.h"
|
2006-07-11 19:53:09 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@implementation UIxMailEditorAction
|
|
|
|
|
2006-07-11 19:53:09 +02:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[self->newDraft release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* caches */
|
|
|
|
|
|
|
|
- (void)reset {
|
|
|
|
[self->newDraft release]; self->newDraft = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lookups */
|
|
|
|
|
|
|
|
- (SOGoDraftsFolder *)draftsFolder {
|
|
|
|
/*
|
|
|
|
Note: we cannot use acquisition to find the nearest drafts folder, because
|
|
|
|
the IMAP4 server might contains an own Drafts folder.
|
|
|
|
*/
|
2006-12-14 22:20:13 +01:00
|
|
|
// SOGoDraftsFolder *drafts;
|
|
|
|
SOGoMailAccount *accountFolder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
accountFolder = [[self clientObject] mailAccountFolder];
|
|
|
|
|
|
|
|
return [accountFolder
|
|
|
|
lookupName: [accountFolder draftsFolderNameInContext: context]
|
|
|
|
inContext: context acquire: NO];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* errors */
|
|
|
|
|
|
|
|
- (id)didNotFindDraftsError {
|
|
|
|
// TODO: make a nice error page
|
|
|
|
return [@"did not find drafts folder in object: "
|
|
|
|
stringByAppendingString:[[self clientObject] description]];
|
|
|
|
}
|
|
|
|
- (id)couldNotCreateDraftError:(SOGoDraftsFolder *)_draftsFolder {
|
|
|
|
return [@"could not create a new draft in folder: "
|
|
|
|
stringByAppendingString:[_draftsFolder description]];
|
|
|
|
}
|
|
|
|
- (id)didNotFindMailError {
|
|
|
|
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
|
|
|
|
reason:@"Did not find mail for operation!"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compose */
|
|
|
|
|
2006-07-11 19:53:09 +02:00
|
|
|
- (id) composeAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
SOGoDraftsFolder *drafts;
|
|
|
|
WOResponse *r;
|
2006-07-11 19:53:09 +02:00
|
|
|
NSString *urlBase, *url;
|
|
|
|
NSMutableDictionary *urlParams;
|
|
|
|
id parameter;
|
|
|
|
id returnValue;
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
drafts = [self draftsFolder];
|
2006-07-11 19:53:09 +02:00
|
|
|
if ([drafts isNotNull])
|
|
|
|
{
|
|
|
|
if ([drafts isKindOfClass: [NSException class]])
|
|
|
|
returnValue = drafts;
|
|
|
|
else
|
|
|
|
{
|
2006-12-14 22:20:13 +01:00
|
|
|
urlBase = [drafts newObjectBaseURLInContext: context];
|
2006-07-11 19:53:09 +02:00
|
|
|
if ([urlBase isNotNull])
|
|
|
|
{
|
|
|
|
urlParams = [NSMutableDictionary new];
|
|
|
|
[urlParams autorelease];
|
|
|
|
|
|
|
|
/* attach mail-account info */
|
|
|
|
parameter
|
|
|
|
= [[self clientObject] valueForKey: @"mailAccountFolder"];
|
|
|
|
if (parameter && ![parameter isExceptionOrNull])
|
|
|
|
[urlParams setObject: [parameter nameInContainer]
|
|
|
|
forKey: @"account"];
|
|
|
|
|
|
|
|
parameter = [[self request] formValueForKey: @"mailto"];
|
|
|
|
if (parameter)
|
|
|
|
[urlParams setObject: parameter
|
|
|
|
forKey: @"mailto"];
|
|
|
|
|
|
|
|
url = [urlBase composeURLWithAction: @"edit"
|
|
|
|
parameters: urlParams
|
|
|
|
andHash: NO];
|
|
|
|
|
|
|
|
/* perform redirect */
|
|
|
|
|
|
|
|
[self debugWithFormat:@"compose on %@: %@", drafts, url];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
r = [context response];
|
2006-07-11 19:53:09 +02:00
|
|
|
[r setStatus: 302 /* move d */];
|
|
|
|
[r setHeader: url forKey: @"location"];
|
|
|
|
[self reset];
|
|
|
|
|
|
|
|
returnValue = r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
returnValue = [self couldNotCreateDraftError: drafts];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
returnValue = [self didNotFindDraftsError];
|
|
|
|
|
|
|
|
return returnValue;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* creating new draft object */
|
|
|
|
|
|
|
|
- (id)newDraftObject {
|
|
|
|
SOGoDraftsFolder *drafts;
|
|
|
|
|
|
|
|
drafts = [self draftsFolder];
|
|
|
|
if (![drafts isNotNull])
|
|
|
|
return [self didNotFindDraftsError];
|
|
|
|
if ([drafts isKindOfClass:[NSException class]])
|
|
|
|
return drafts;
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
return [drafts newObjectInContext:context];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *)_setupNewDraft {
|
|
|
|
SOGoDraftObject *tmp;
|
|
|
|
|
|
|
|
/* create draft object */
|
|
|
|
|
|
|
|
if ([(tmp = [self newDraftObject]) isKindOfClass:[NSException class]])
|
|
|
|
return (NSException *)tmp;
|
|
|
|
if (![tmp isNotNull]) { /* Note: should never happen? */
|
|
|
|
[self logWithFormat:@"WARNING: got no new draft object and no error!"];
|
|
|
|
return [self didNotFindDraftsError]; // TODO: not exact
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSIGN(self->newDraft, tmp);
|
|
|
|
//[self debugWithFormat:@"NEW DRAFT: %@", self->newDraft];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *)redirectToEditNewDraft {
|
|
|
|
WOResponse *r;
|
|
|
|
NSString *url;
|
|
|
|
|
|
|
|
if (![self->newDraft isNotNull]) {
|
|
|
|
[self logWithFormat:@"ERROR(%s): missing new draft (already -reset?)",
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
url = [self->newDraft baseURLInContext:context];
|
2006-06-15 21:34:10 +02:00
|
|
|
if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
|
|
|
|
url = [url stringByAppendingString:@"edit"];
|
|
|
|
|
|
|
|
// TODO: debug log
|
|
|
|
[self logWithFormat:@"compose on %@", url];
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
r = [context response];
|
2006-06-15 21:34:10 +02:00
|
|
|
[r setStatus:302 /* moved */];
|
|
|
|
[r setHeader:url forKey:@"location"];
|
|
|
|
[self reset];
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxMailEditorAction */
|