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 - (id) contentViewerComponent
138 // TODO: I would prefer to flatten the body structure prior rendering,
139 // using some delegate to decide which parts to select for alternative.
142 info = [[self clientObject] bodyStructure];
144 return [[context mailRenderingContext] viewerForBodyInfo:info];
151 WOResponse *response;
154 /* check etag to see whether we really must rerender */
158 Note: There is one thing which *can* change for an existing message,
159 those are the IMAP4 flags (and annotations, which we do not use).
160 Since we don't render the flags, it should be OK, if this changes
161 we must embed the flagging into the etag.
163 s = [[context request] headerForKey: @"if-none-match"];
166 if ([s rangeOfString:mailETag].length > 0) /* not perfectly correct */
168 /* client already has the proper entity */
169 // [self logWithFormat:@"MATCH: %@ (tag %@)", s, mailETag];
171 if (![[self clientObject] doesMailExist]) {
172 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
173 reason:@"message got deleted"];
176 response = [context response];
177 [response setStatus: 304 /* Not Modified */];
184 if (![self message]) // TODO: redirect to proper error
185 return [NSException exceptionWithHTTPStatus:404 /* Not Found */
186 reason:@"did not find specified message!"];
191 - (BOOL) isDeletableClientObject
193 return [[self clientObject] respondsToSelector: @selector (delete)];
196 - (BOOL) isInlineViewer
203 return [[self clientObject] isInDraftsFolder];
206 - (id) redirectToParentFolder
210 url = [[[self clientObject] container] baseURLInContext: context];
212 return [self redirectToLocation: url];
215 /* generating response */
217 - (void) appendToResponse: (WOResponse *) _response
218 inContext: (WOContext *) _ctx
220 UIxMailRenderingContext *mctx;
223 [[_ctx response] setHeader:mailETag forKey:@"etag"];
225 mctx = [[UIxMailRenderingContext alloc] initWithViewer: self
228 [_ctx pushMailRenderingContext: mctx];
231 [super appendToResponse: _response inContext: _ctx];
233 [[_ctx popMailRenderingContext] reset];
236 @end /* UIxMailView */