]> err.no Git - scalable-opengroupware.org/blob - UI/MailPartViewers/UIxMailPartMessageViewer.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1294 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / MailPartViewers / UIxMailPartMessageViewer.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <NGImap4/NGImap4Envelope.h>
23 #import <NGImap4/NGImap4EnvelopeAddress.h>
24
25 #import <SoObjects/Mailer/NSData+Mail.h>
26 #import <SoObjects/Mailer/NSString+Mail.h>
27
28 #import <UI/MailerUI/WOContext+UIxMailer.h>
29 #import "UIxMailRenderingContext.h"
30
31 #import "UIxMailPartViewer.h"
32
33 /*
34   UIxMailPartMessageViewer
35
36  Show message/rfc822 mail parts. Note that the IMAP4 server already returns a
37  proper body structure of the message.
38
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
42  size
43  subject
44  parameterList - dict (eg 'name')
45  messageId 
46  date
47  encoding - 7BIT
48  bodyLines - 83
49  bodyId - (empty string?)
50  description - (empty string?, content-description?)
51  
52  body - a body structure?
53  
54  Addr-Dict:
55  hostName / mailboxName / personalName / sourceRoute
56 */
57
58 @class NGImap4Envelope;
59
60 @interface UIxMailPartMessageViewer : UIxMailPartViewer
61 {
62   NGImap4Envelope *envelope;
63 }
64
65 @end
66
67 @implementation UIxMailPartMessageViewer
68
69 - (void) dealloc
70 {
71   [envelope release];
72   [super dealloc];
73 }
74
75 /* cache maintenance */
76
77 - (void) resetBodyInfoCaches
78 {
79   [super resetBodyInfoCaches];
80   [envelope release]; envelope = nil;
81 }
82
83 /* nested body structure */
84
85 - (id) contentInfo
86 {
87   return [[self bodyInfo] valueForKey:@"body"];
88 }
89
90 - (id) contentPartPath
91 {
92   /*
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.
96  
97     If the message has just a plain content, ids seems to be as expected (that
98     is, its just a "1").
99   */
100   NSArray *pp;
101   NSString *mt;
102  
103   mt = [[[self contentInfo] valueForKey:@"type"] lowercaseString];
104   if ([mt isEqualToString:@"multipart"])
105     return [self partPath];
106  
107   pp = [self partPath];
108   return (([pp count] > 0)
109           ? [pp arrayByAddingObject: @"1"]
110           : [NSArray arrayWithObject: @"1"]);
111 }
112
113 - (id) contentViewerComponent
114 {
115   UIxMailRenderingContext *mailContext;
116
117   mailContext = [[self context] mailRenderingContext];
118
119   return [mailContext viewerForBodyInfo: [self contentInfo]];
120 }
121
122 /* generating envelope */
123
124 - (NGImap4Envelope *) envelope
125 {
126   if (!envelope)
127     envelope = [[NGImap4Envelope alloc] initWithBodyStructureInfo:
128                                           [self bodyInfo]];
129
130   return envelope;
131 }
132
133 - (NSString *) formattedComponents: (NSArray *) components
134 {
135   NSMutableArray *formattedComponents;
136   unsigned int count, max;
137   NSString *component;
138
139   max = [components count];
140   formattedComponents = [NSMutableArray arrayWithCapacity: max];
141   for (count = 0; count < max; count++)
142     {
143       component = [[components objectAtIndex: count] email];
144       [formattedComponents addObject: component];
145     }
146
147   return [formattedComponents componentsJoinedByString: @", "];
148 }
149
150 - (NSString *) messageSubject
151 {
152   id baseSubject;
153   NSString *subject;
154
155   baseSubject = [[self envelope] subject];
156   subject = [baseSubject decodedSubject];
157   if (![subject length])
158     subject = [self labelForKey: @"Untitled"];
159
160   return subject;
161 }
162
163 - (NSString *) fromAddresses
164 {
165   NSArray *from;
166
167   from = [[self envelope] from];
168
169   return [self formattedComponents: from];
170 }
171
172 - (NSString *) toAddresses
173 {
174   NSArray *to;
175
176   to = [[self envelope] to];
177
178   return [self formattedComponents: to];
179 }
180
181 - (NSString *) ccAddresses
182 {
183   NSArray *cc;
184
185   cc = [[self envelope] cc];
186
187   return [self formattedComponents: cc];
188 }
189
190 /* links to recipients */
191
192 - (NSString *) linkToEnvelopeAddress: (NGImap4EnvelopeAddress *) _address
193 {
194   // TODO: make some web-link, eg open a new compose panel?
195   return [@"mailto:" stringByAppendingString:[_address baseEMail]];
196 }
197
198 @end /* UIxMailPartMessageViewer */