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 "UIxMailRenderingContext.h"
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 /* links (DUP to UIxMailPartViewer!) */
77 - (NSString *)linkToEnvelopeAddress:(NGImap4EnvelopeAddress *)_address {
78 // TODO: make some web-link, eg open a new compose panel?
79 return [@"mailto:" stringByAppendingString:[_address baseEMail]];
82 - (NSString *)fromLink {
83 return [self linkToEnvelopeAddress:
84 [[self clientObject] fromEnvelopeAddress]];
86 - (NSString *)currentAddressLink {
87 return [self linkToEnvelopeAddress:[self currentAddress]];
93 return [[self clientObject] fetchCoreInfos];
97 return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO;
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.
107 info = [[self clientObject] bodyStructure];
108 return [[[self context] mailRenderingContext] viewerForBodyInfo:info];
113 - (id)defaultAction {
114 if ([self message] == nil) {
115 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
116 reason:@"did not find specified message!"];
121 - (BOOL)isDeletableClientObject {
122 return [[self clientObject] respondsToSelector:@selector(delete)];
124 - (BOOL)isInlineViewer {
131 if (![self isDeletableClientObject]) {
132 return [NSException exceptionWithHTTPStatus:400 /* Bad Request */
133 reason:@"method cannot be invoked on "
134 @"the specified object"];
137 if ((ex = [[self clientObject] delete]) != nil) {
138 // TODO: improve error handling
139 [self debugWithFormat:@"failed to delete: %@", ex];
143 if (![self isInlineViewer]) {
144 // if everything is ok, close the window (send a JS closing the Window)
147 page = [self pageWithName:@"UIxMailWindowCloser"];
148 [page takeValue:@"YES" forKey:@"refreshOpener"];
154 url = [[[self clientObject] container] baseURLInContext:[self context]];
155 return [self redirectToLocation:url];
159 - (id)getMailAction {
160 // TODO: we might want to flush the caches?
161 return [self redirectToLocation:@"view"];
164 /* generating response */
166 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
167 UIxMailRenderingContext *mctx;
169 mctx = [[UIxMailRenderingContext alloc] initWithViewer:self context:_ctx];
170 [_ctx pushMailRenderingContext:mctx];
173 [super appendToResponse:_response inContext:_ctx];
175 [[_ctx popMailRenderingContext] reset];
178 @end /* UIxMailView */