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 <NGImap4/NGImap4Envelope.h>
23 #import <NGImap4/NGImap4EnvelopeAddress.h>
25 #import <SoObjects/Mailer/NSData+Mail.h>
26 #import <SoObjects/Mailer/NSString+Mail.h>
28 #import <UI/MailerUI/WOContext+UIxMailer.h>
29 #import "UIxMailRenderingContext.h"
31 #import "UIxMailPartViewer.h"
34 UIxMailPartMessageViewer
36 Show message/rfc822 mail parts. Note that the IMAP4 server already returns a
37 proper body structure of the message.
39 Relevant body-info keys:
40 to/sender/from/cc/bcc/in-reply-to/reply-to - array of addr-dicts
41 type/subtype - message/RFC822
44 parameterList - dict (eg 'name')
49 bodyId - (empty string?)
50 description - (empty string?, content-description?)
52 body - a body structure?
55 hostName / mailboxName / personalName / sourceRoute
58 @class NGImap4Envelope;
60 @interface UIxMailPartMessageViewer : UIxMailPartViewer
62 NGImap4Envelope *envelope;
67 @implementation UIxMailPartMessageViewer
75 /* cache maintenance */
77 - (void) resetBodyInfoCaches
79 [super resetBodyInfoCaches];
80 [envelope release]; envelope = nil;
83 /* nested body structure */
87 return [[self bodyInfo] valueForKey:@"body"];
90 - (id) contentPartPath
93 Path processing is a bit weird in the context of message/rfc822. If we have
94 a multipart, the multipart itself has no own identifier! Instead the
95 children of the multipart are directly mapped into the message namespace.
97 If the message has just a plain content, ids seems to be as expected (that
103 mt = [[[self contentInfo] valueForKey:@"type"] lowercaseString];
104 if ([mt isEqualToString:@"multipart"])
105 return [self partPath];
107 pp = [self partPath];
108 return (([pp count] > 0)
109 ? [pp arrayByAddingObject: @"1"]
110 : [NSArray arrayWithObject: @"1"]);
113 - (id) contentViewerComponent
115 UIxMailRenderingContext *mailContext;
117 mailContext = [[self context] mailRenderingContext];
119 return [mailContext viewerForBodyInfo: [self contentInfo]];
122 /* generating envelope */
124 - (NGImap4Envelope *) envelope
127 envelope = [[NGImap4Envelope alloc] initWithBodyStructureInfo:
133 - (NSString *) formattedComponents: (NSArray *) components
135 NSMutableArray *formattedComponents;
136 unsigned int count, max;
139 max = [components count];
140 formattedComponents = [NSMutableArray arrayWithCapacity: max];
141 for (count = 0; count < max; count++)
143 component = [[components objectAtIndex: count] email];
144 [formattedComponents addObject: component];
147 return [formattedComponents componentsJoinedByString: @", "];
150 - (NSString *) messageSubject
155 baseSubject = [[self envelope] subject];
156 subject = [baseSubject decodedSubject];
157 if (![subject length])
158 subject = [self labelForKey: @"Untitled"];
163 - (NSString *) fromAddresses
167 from = [[self envelope] from];
169 return [self formattedComponents: from];
172 - (NSString *) toAddresses
176 to = [[self envelope] to];
178 return [self formattedComponents: to];
181 - (NSString *) ccAddresses
185 cc = [[self envelope] cc];
187 return [self formattedComponents: cc];
190 /* links to recipients */
192 - (NSString *) linkToEnvelopeAddress: (NGImap4EnvelopeAddress *) _address
194 // TODO: make some web-link, eg open a new compose panel?
195 return [@"mailto:" stringByAppendingString:[_address baseEMail]];
198 @end /* UIxMailPartMessageViewer */