]> err.no Git - scalable-opengroupware.org/blob - UI/MailerUI/UIxMailForwardAction.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1089 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailerUI / UIxMailForwardAction.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "UIxMailEditorAction.h"
23
24 @interface UIxMailForwardAction : UIxMailEditorAction
25 @end
26
27 #include <SoObjects/Mailer/SOGoMailObject.h>
28 #include <SoObjects/Mailer/SOGoDraftObject.h>
29 #include "common.h"
30
31 @implementation UIxMailForwardAction
32
33 - (NSString *)getAttachmentNameForSubject:(NSString *)_subject {
34   /* SOGoDraftObject disallows some strings - anything else required? */
35   static NSString *sescape[] = { 
36     @"/", @"..", @"~", @"\"", @"'", @" ", @".", nil 
37   };
38   static int maxFilenameLength = 64;
39   NSString *s;
40   unsigned i;
41   
42   if (![_subject isNotNull] || [_subject length] == 0)
43     return _subject;
44   s = _subject;
45   
46   if ([s length] > maxFilenameLength)
47     s = [s substringToIndex:maxFilenameLength];
48   
49   for (i = 0; sescape[i] != nil; i++)
50     s = [s stringByReplacingString:sescape[i] withString:@"_"];
51   
52   return [s stringByAppendingString:@".mail"];
53 }
54
55 - (NSString *)forwardSubject:(NSString *)_subject {
56   if (![_subject isNotNull] || [_subject length] == 0)
57     return _subject;
58   
59   /* Note: this is how Thunderbird 1.0 creates the subject */
60   _subject = [@"[Fwd: " stringByAppendingString:_subject];
61   _subject = [_subject stringByAppendingString:@"]"];
62   return _subject;
63 }
64
65 - (id)forwardAction {
66   NSException  *error;
67   NSData       *content;
68   NSDictionary *info;
69   id result;
70
71   /* fetch message */
72   
73   if ((content = [[self clientObject] content]) == nil)
74     return [self didNotFindMailError];
75   if ([content isKindOfClass:[NSException class]])
76     return content;
77   
78   /* setup draft */
79   
80   if ((error = [self _setupNewDraft]) != nil)
81     return error;
82   
83   /* set subject (do we need to set anything else?) */
84   
85   info = [NSDictionary dictionaryWithObjectsAndKeys:
86                          [self forwardSubject:[[self clientObject] subject]],
87                          @"subject",
88                        nil];
89   if ((error = [self->newDraft storeInfo:info]) != nil)
90     return error;
91   
92   /* attach message */
93   
94   // TODO: use subject for filename?
95   error = [self->newDraft saveAttachment:content withName:@"forward.mail"];
96   if (error != nil)
97     return error;
98   
99   // TODO: we might want to pass the original URL to the editor for a final
100   //       redirect back to the message?
101   result = [self redirectToEditNewDraft];
102   [self reset];
103   return result;
104 }
105
106 @end /* UIxMailForwardAction */