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>
23 #import <Foundation/NSString.h>
25 #import <NGExtensions/NSNull+misc.h>
27 #import <SoObjects/Mailer/SOGoMailObject.h>
28 #import <SoObjects/Mailer/SOGoDraftObject.h>
30 #import "UIxMailEditorAction.h"
32 @interface UIxMailForwardAction : UIxMailEditorAction
36 @implementation UIxMailForwardAction
38 - (NSString *)getAttachmentNameForSubject:(NSString *)_subject {
39 /* SOGoDraftObject disallows some strings - anything else required? */
40 static NSString *sescape[] = {
41 @"/", @"..", @"~", @"\"", @"'", @" ", @".", nil
43 static int maxFilenameLength = 64;
47 if (![_subject isNotNull] || [_subject length] == 0)
51 if ([s length] > maxFilenameLength)
52 s = [s substringToIndex:maxFilenameLength];
54 for (i = 0; sescape[i] != nil; i++)
55 s = [s stringByReplacingString:sescape[i] withString:@"_"];
57 return [s stringByAppendingString:@".mail"];
60 - (NSString *)forwardSubject:(NSString *)_subject {
61 if (![_subject isNotNull] || [_subject length] == 0)
64 /* Note: this is how Thunderbird 1.0 creates the subject */
65 _subject = [@"[Fwd: " stringByAppendingString:_subject];
66 _subject = [_subject stringByAppendingString:@"]"];
73 NSDictionary *info, *attachment;
78 if ((content = [[self clientObject] content]) == nil)
79 return [self didNotFindMailError];
80 if ([content isKindOfClass:[NSException class]])
85 if ((error = [self _setupNewDraft]) != nil)
88 /* set subject (do we need to set anything else?) */
90 info = [NSDictionary dictionaryWithObjectsAndKeys:
91 [self forwardSubject:[[self clientObject] subject]],
94 if ((error = [newDraft storeInfo:info]) != nil)
99 // TODO: use subject for filename?
100 error = [newDraft saveAttachment:content withName:@"forward.mail"];
104 // TODO: we might want to pass the original URL to the editor for a final
105 // redirect back to the message?
106 result = [self redirectToEditNewDraft];
111 @end /* UIxMailForwardAction */