]> err.no Git - scalable-opengroupware.org/blob - UI/MailPartViewers/UIxMailPartMessageViewer.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1146 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 <UI/MailerUI/WOContext+UIxMailer.h>
26 #import "UIxMailRenderingContext.h"
27
28 #import "UIxMailPartViewer.h"
29
30 /*
31   UIxMailPartMessageViewer
32
33  Show message/rfc822 mail parts. Note that the IMAP4 server already returns a
34  proper body structure of the message.
35
36  Relevant body-info keys:
37  to/sender/from/cc/bcc/in-reply-to/reply-to - array of addr-dicts
38  type/subtype - message/RFC822
39  size
40  subject
41  parameterList - dict (eg 'name')
42  messageId 
43  date
44  encoding - 7BIT
45  bodyLines - 83
46  bodyId - (empty string?)
47  description - (empty string?, content-description?)
48  
49  body - a body structure?
50  
51  Addr-Dict:
52  hostName / mailboxName / personalName / sourceRoute
53 */
54
55 @class NGImap4Envelope;
56
57 @interface UIxMailPartMessageViewer : UIxMailPartViewer
58 {
59   NGImap4Envelope *envelope;
60 }
61
62 @end
63
64 @implementation UIxMailPartMessageViewer
65
66 - (void) dealloc
67 {
68   [envelope release];
69   [super dealloc];
70 }
71
72 /* cache maintenance */
73
74 - (void) resetBodyInfoCaches
75 {
76   [super resetBodyInfoCaches];
77   [envelope release]; envelope = nil;
78 }
79
80 /* nested body structure */
81
82 - (id) contentInfo
83 {
84   return [[self bodyInfo] valueForKey:@"body"];
85 }
86
87 - (id) contentPartPath
88 {
89   /*
90     Path processing is a bit weird in the context of message/rfc822. If we have
91     a multipart, the multipart itself has no own identifier! Instead the
92     children of the multipart are directly mapped into the message namespace.
93  
94     If the message has just a plain content, ids seems to be as expected (that
95     is, its just a "1").
96   */
97   NSArray *pp;
98   NSString *mt;
99  
100   mt = [[[self contentInfo] valueForKey:@"type"] lowercaseString];
101   if ([mt isEqualToString:@"multipart"])
102     return [self partPath];
103  
104   pp = [self partPath];
105   return (([pp count] > 0)
106           ? [pp arrayByAddingObject: @"1"]
107           : [NSArray arrayWithObject: @"1"]);
108 }
109
110 - (id) contentViewerComponent
111 {
112   UIxMailRenderingContext *mailContext;
113
114   mailContext = [[self context] mailRenderingContext];
115
116   return [mailContext viewerForBodyInfo: [self contentInfo]];
117 }
118
119 /* generating envelope */
120
121 - (NGImap4Envelope *) envelope
122 {
123   if (!envelope)
124     envelope = [[NGImap4Envelope alloc] initWithBodyStructureInfo:
125                                           [self bodyInfo]];
126
127   return envelope;
128 }
129
130 - (NSString *) formattedComponents: (NSArray *) components
131 {
132   NSMutableArray *formattedComponents;
133   unsigned int count, max;
134   NSString *component;
135
136   max = [components count];
137   formattedComponents = [NSMutableArray arrayWithCapacity: max];
138   for (count = 0; count < max; count++)
139     {
140       component = [[components objectAtIndex: count] email];
141       [formattedComponents addObject: component];
142     }
143
144   return [formattedComponents componentsJoinedByString: @", "];
145 }
146
147 - (NSString *) fromAddresses
148 {
149   NSArray *from;
150
151   from = [[self envelope] from];
152
153   return [self formattedComponents: from];
154 }
155
156 - (NSString *) toAddresses
157 {
158   NSArray *to;
159
160   to = [[self envelope] to];
161
162   return [self formattedComponents: to];
163 }
164
165 - (NSString *) ccAddresses
166 {
167   NSArray *cc;
168
169   cc = [[self envelope] cc];
170
171   return [self formattedComponents: cc];
172 }
173
174 /* links to recipients */
175
176 - (NSString *) linkToEnvelopeAddress: (NGImap4EnvelopeAddress *) _address
177 {
178   // TODO: make some web-link, eg open a new compose panel?
179   return [@"mailto:" stringByAppendingString:[_address baseEMail]];
180 }
181
182 @end /* UIxMailPartMessageViewer */