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