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/NSException.h>
23 #import <Foundation/NSUserDefaults.h>
24 #import <NGObjWeb/NSException+HTTP.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <NGObjWeb/WOResponse.h>
27 #import <NGExtensions/NSException+misc.h>
28 #import <NGExtensions/NSString+misc.h>
29 #import <NGImap4/NGImap4Envelope.h>
30 #import <NGImap4/NGImap4EnvelopeAddress.h>
31 #import <SoObjects/Mailer/SOGoMailObject.h>
32 #import <SoObjects/Mailer/SOGoMailAccount.h>
33 #import <SoObjects/Mailer/SOGoMailFolder.h>
34 #import <SOGoUI/UIxComponent.h>
35 #import <MailPartViewers/UIxMailRenderingContext.h> // cyclic
37 #import "WOContext+UIxMailer.h"
39 @interface UIxMailView : UIxComponent
44 - (BOOL)isDeletableClientObject;
48 @implementation UIxMailView
50 static NSString *mailETag = nil;
53 return [super version] + 0 /* v2 */;
57 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
59 NSAssert2([super version] == 2,
60 @"invalid superclass (%@) version %i !",
61 NSStringFromClass([self superclass]), [super version]);
63 if ([ud boolForKey:@"SOGoDontUseETagsForMailViewer"]) {
64 NSLog(@"Note: usage of constant etag for mailer viewer is disabled.");
67 mailETag = [[NSString alloc] initWithFormat:@"\"imap4url_%d_%d_%03d\"",
68 UIX_MAILER_MAJOR_VERSION,
69 UIX_MAILER_MINOR_VERSION,
70 UIX_MAILER_SUBMINOR_VERSION];
71 NSLog(@"Note: using constant etag for mail viewer: '%@'", mailETag);
81 - (void) setCurrentAddress: (id) _addr
83 currentAddress = _addr;
88 return currentAddress;
91 - (NSString *) messageSubject
95 subject = [[self clientObject] decodedSubject];
96 if (![subject length])
97 subject = [self labelForKey: @"Untitled"];
102 - (NSString *) panelTitle
104 return [NSString stringWithFormat: @"%@: %@",
105 [self labelForKey: @"View Mail"],
106 [self messageSubject]];
109 /* links (DUP to UIxMailPartViewer!) */
111 - (NSString *) linkToEnvelopeAddress: (NGImap4EnvelopeAddress *) _address
113 // TODO: make some web-link, eg open a new compose panel?
114 return [NSString stringWithFormat: @"mailto: %@", [_address baseEMail]];
117 - (NSString *) currentAddressLink
119 return [self linkToEnvelopeAddress:[self currentAddress]];
126 return [[self clientObject] fetchCoreInfos];
131 return [[[self clientObject] ccEnvelopeAddresses] count] > 0 ? YES : NO;
136 return [[[self clientObject] replyToEnvelopeAddresses] count] > 0 ? YES : NO;
141 - (id) contentViewerComponent
143 // TODO: I would prefer to flatten the body structure prior rendering,
144 // using some delegate to decide which parts to select for alternative.
147 info = [[self clientObject] bodyStructure];
149 return [[context mailRenderingContext] viewerForBodyInfo:info];
156 WOResponse *response;
159 /* check etag to see whether we really must rerender */
163 Note: There is one thing which *can* change for an existing message,
164 those are the IMAP4 flags (and annotations, which we do not use).
165 Since we don't render the flags, it should be OK, if this changes
166 we must embed the flagging into the etag.
168 s = [[context request] headerForKey: @"if-none-match"];
171 if ([s rangeOfString:mailETag].length > 0) /* not perfectly correct */
173 /* client already has the proper entity */
174 // [self logWithFormat:@"MATCH: %@ (tag %@)", s, mailETag];
176 if (![[self clientObject] doesMailExist]) {
177 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
178 reason:@"message got deleted"];
181 response = [context response];
182 [response setStatus: 304 /* Not Modified */];
189 if (![self message]) // TODO: redirect to proper error
190 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
191 reason:@"did not find specified message!"];
196 - (BOOL) isDeletableClientObject
198 return [[self clientObject] respondsToSelector: @selector (delete)];
201 - (BOOL) isInlineViewer
208 return [[self clientObject] isInDraftsFolder];
211 - (id) redirectToParentFolder
215 url = [[[self clientObject] container] baseURLInContext: context];
217 return [self redirectToLocation: url];
220 /* generating response */
222 - (void) appendToResponse: (WOResponse *) _response
223 inContext: (WOContext *) _ctx
225 UIxMailRenderingContext *mctx;
228 [[_ctx response] setHeader:mailETag forKey:@"etag"];
230 mctx = [[UIxMailRenderingContext alloc] initWithViewer: self
233 [_ctx pushMailRenderingContext: mctx];
236 [super appendToResponse: _response inContext: _ctx];
238 [[_ctx popMailRenderingContext] reset];
241 @end /* UIxMailView */