]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Mailer/UIxMailView.m
d7ffaedd3605932c8089f8fb4d903cb912c0cc1b
[scalable-opengroupware.org] / SOGo / UI / Mailer / UIxMailView.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 <SOGoUI/UIxComponent.h>
23
24 @interface UIxMailView : UIxComponent
25 {
26   id currentAddress;
27 }
28
29 - (BOOL)isDeletableClientObject;
30
31 @end
32
33 #include "UIxMailRenderingContext.h"
34 #include "WOContext+UIxMailer.h"
35 #include <SoObjects/Mailer/SOGoMailObject.h>
36 #include <NGImap4/NGImap4Envelope.h>
37 #include <NGImap4/NGImap4EnvelopeAddress.h>
38 #include "common.h"
39
40 @implementation UIxMailView
41
42 - (void)dealloc {
43   [self->currentAddress release];
44   [super dealloc];
45 }
46
47 /* notifications */
48
49 - (void)sleep {
50   [self->currentAddress release]; self->currentAddress = nil;
51   [super sleep];
52 }
53
54 /* accessors */
55
56 - (void)setCurrentAddress:(id)_addr {
57   ASSIGN(self->currentAddress, _addr);
58 }
59 - (id)currentAddress {
60   return self->currentAddress;
61 }
62
63 - (NSString *)objectTitle {
64   return [[self clientObject] subject];
65 }
66 - (NSString *)panelTitle {
67   NSString *s;
68   
69   s = [self labelForKey:@"View Mail"];
70   s = [s stringByAppendingString:@": "];
71   s = [s stringByAppendingString:[self objectTitle]];
72   return s;
73 }
74
75 /* links (DUP to UIxMailPartViewer!) */
76
77 - (NSString *)linkToEnvelopeAddress:(NGImap4EnvelopeAddress *)_address {
78   // TODO: make some web-link, eg open a new compose panel?
79   return [@"mailto:" stringByAppendingString:[_address baseEMail]];
80 }
81
82 - (NSString *)fromLink {
83   return [self linkToEnvelopeAddress:
84                  [[self clientObject] fromEnvelopeAddress]];
85 }
86 - (NSString *)currentAddressLink {
87   return [self linkToEnvelopeAddress:[self currentAddress]];
88 }
89
90 /* fetching */
91
92 - (id)message {
93   return [[self clientObject] fetchCoreInfos];
94 }
95
96 - (BOOL)hasCC {
97   return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO;
98 }
99
100 /* viewers */
101
102 - (id)contentViewerComponent {
103   // TODO: I would prefer to flatten the body structure prior rendering,
104   //       using some delegate to decide which parts to select for alternative.
105   id info;
106   
107   info = [[self clientObject] bodyStructure];
108   return [[[self context] mailRenderingContext] viewerForBodyInfo:info];
109 }
110
111 /* actions */
112
113 - (id)defaultAction {
114   if ([self message] == nil) {
115     return [NSException exceptionWithHTTPStatus:404 /* Not Found */
116                         reason:@"did not find specified message!"];
117   }
118   return self;
119 }
120
121 - (BOOL)isDeletableClientObject {
122   return [[self clientObject] respondsToSelector:@selector(delete)];
123 }
124 - (BOOL)isInlineViewer {
125   return NO;
126 }
127
128 - (id)deleteAction {
129   NSException *ex;
130   
131   if (![self isDeletableClientObject]) {
132     return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
133                         reason:@"method cannot be invoked on "
134                                @"the specified object"];
135   }
136   
137   if ((ex = [[self clientObject] delete]) != nil) {
138     // TODO: improve error handling
139     [self debugWithFormat:@"failed to delete: %@", ex];
140     return ex;
141   }
142   
143   if (![self isInlineViewer]) {
144     // if everything is ok, close the window (send a JS closing the Window)
145     id page;
146     
147     page = [self pageWithName:@"UIxMailWindowCloser"];
148     [page takeValue:@"YES" forKey:@"refreshOpener"];
149     return page;
150   }
151   else {
152     id url;
153
154     url = [[[self clientObject] container] baseURLInContext:[self context]];
155     return [self redirectToLocation:url];
156   }
157 }
158
159 - (id)getMailAction {
160   // TODO: we might want to flush the caches?
161   return [self redirectToLocation:@"view"];
162 }
163
164 /* generating response */
165
166 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
167   UIxMailRenderingContext *mctx;
168
169   mctx = [[UIxMailRenderingContext alloc] initWithViewer:self context:_ctx];
170   [_ctx pushMailRenderingContext:mctx];
171   [mctx release];
172   
173   [super appendToResponse:_response inContext:_ctx];
174   
175   [[_ctx popMailRenderingContext] reset];
176 }
177
178 @end /* UIxMailView */