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 <SOGoUI/UIxComponent.h>
24 @interface UIxMailView : UIxComponent
29 - (BOOL)isDeletableClientObject;
33 #include <UI/MailPartViewers/UIxMailRenderingContext.h> // cyclic
34 #include "WOContext+UIxMailer.h"
35 #include <SoObjects/Mailer/SOGoMailObject.h>
36 #include <NGImap4/NGImap4Envelope.h>
37 #include <NGImap4/NGImap4EnvelopeAddress.h>
40 @implementation UIxMailView
43 [self->currentAddress release];
50 [self->currentAddress release]; self->currentAddress = nil;
56 - (void)setCurrentAddress:(id)_addr {
57 ASSIGN(self->currentAddress, _addr);
59 - (id)currentAddress {
60 return self->currentAddress;
63 - (NSString *)objectTitle {
64 return [[self clientObject] subject];
66 - (NSString *)panelTitle {
69 s = [self labelForKey:@"View Mail"];
70 s = [s stringByAppendingString:@": "];
71 s = [s stringByAppendingString:[self objectTitle]];
75 /* expunge / delete setup and permissions */
77 - (BOOL)showMarkDeletedButton {
78 if (![[self clientObject] isDeletionAllowed])
81 return NO; // TODO: make configurable in profile
84 - (BOOL)showTrashButton {
85 if (![[self clientObject] isDeletionAllowed])
87 // TODO: should also check for Trash write access (or add -isTrashingAllowed)
89 return YES; // TODO: make configurable in profile
92 /* links (DUP to UIxMailPartViewer!) */
94 - (NSString *)linkToEnvelopeAddress:(NGImap4EnvelopeAddress *)_address {
95 // TODO: make some web-link, eg open a new compose panel?
96 return [@"mailto:" stringByAppendingString:[_address baseEMail]];
99 - (NSString *)currentAddressLink {
100 return [self linkToEnvelopeAddress:[self currentAddress]];
106 return [[self clientObject] fetchCoreInfos];
110 return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO;
115 - (id)contentViewerComponent {
116 // TODO: I would prefer to flatten the body structure prior rendering,
117 // using some delegate to decide which parts to select for alternative.
120 info = [[self clientObject] bodyStructure];
121 return [[[self context] mailRenderingContext] viewerForBodyInfo:info];
126 - (id)defaultAction {
127 if ([self message] == nil) {
128 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
129 reason:@"did not find specified message!"];
134 - (BOOL)isDeletableClientObject {
135 return [[self clientObject] respondsToSelector:@selector(delete)];
137 - (BOOL)isInlineViewer {
141 - (id)redirectToParentFolder {
144 url = [[[self clientObject] container] baseURLInContext:[self context]];
145 return [self redirectToLocation:url];
151 if (![self isDeletableClientObject]) {
152 return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
153 reason:@"method cannot be invoked on "
154 @"the specified object"];
157 if ([self isInvokedBySafeMethod]) {
158 // TODO: fix UI to use POST for unsafe actions
159 [self logWithFormat:@"WARNING: method is invoked using safe HTTP method!"];
162 if ((ex = [[self clientObject] delete]) != nil) {
165 url = [[ex reason] stringByEscapingURL];
166 url = [@"view?error=" stringByAppendingString:url];
167 return [self redirectToLocation:url];
171 if (![self isInlineViewer]) {
172 // if everything is ok, close the window (send a JS closing the Window)
175 page = [self pageWithName:@"UIxMailWindowCloser"];
176 [page takeValue:@"YES" forKey:@"refreshOpener"];
180 return [self redirectToParentFolder];
186 if ([self isInvokedBySafeMethod]) {
187 // TODO: fix UI to use POST for unsafe actions
188 [self logWithFormat:@"WARNING: method is invoked using safe HTTP method!"];
191 if ((ex = [[self clientObject] trashInContext:[self context]]) != nil) {
194 url = [[ex reason] stringByEscapingURL];
195 url = [@"view?error=" stringByAppendingString:url];
196 return [self redirectToLocation:url];
199 if (![self isInlineViewer]) {
200 // if everything is ok, close the window (send a JS closing the Window)
203 page = [self pageWithName:@"UIxMailWindowCloser"];
204 [page takeValue:@"YES" forKey:@"refreshOpener"];
208 return [self redirectToParentFolder];
211 - (id)getMailAction {
212 // TODO: we might want to flush the caches?
213 return [self redirectToLocation:@"view"];
216 /* generating response */
218 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
219 UIxMailRenderingContext *mctx;
221 mctx = [[NSClassFromString(@"UIxMailRenderingContext")
222 alloc] initWithViewer:self context:_ctx];
223 [_ctx pushMailRenderingContext:mctx];
226 [super appendToResponse:_response inContext:_ctx];
228 [[_ctx popMailRenderingContext] reset];
231 @end /* UIxMailView */