1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
Copyright (C) 2007-2015 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
SOGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OGo; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#import <NGImap4/NGImap4Envelope.h>
#import <NGImap4/NGImap4EnvelopeAddress.h>
#import <NGExtensions/NSString+Encoding.h>
#import <NGObjWeb/WOResponse.h>
#import <SoObjects/Mailer/NSData+Mail.h>
#import <SoObjects/Mailer/NSString+Mail.h>
#import <UI/MailerUI/WOContext+UIxMailer.h>
#import "UIxMailRenderingContext.h"
#import <Foundation/NSDictionary.h>
#import "UIxMailPartViewer.h"
/*
UIxMailPartMessageViewer
Show message/rfc822 mail parts. Note that the IMAP4 server already returns a
proper body structure of the message.
Relevant body-info keys:
to/sender/from/cc/bcc/in-reply-to/reply-to - array of addr-dicts
type/subtype - message/RFC822
size
subject
parameterList - dict (eg 'name')
messageId
date
encoding - 7BIT
bodyLines - 83
bodyId - (empty string?)
description - (empty string?, content-description?)
body - a body structure?
Addr-Dict:
hostName / mailboxName / personalName / sourceRoute
*/
@class NGImap4Envelope;
@interface UIxMailPartMessageViewer : UIxMailPartViewer
{
NGImap4Envelope *envelope;
}
@end
@implementation UIxMailPartMessageViewer
- (void) dealloc
{
[envelope release];
[super dealloc];
}
/* cache maintenance */
- (void) resetBodyInfoCaches
{
[super resetBodyInfoCaches];
[envelope release]; envelope = nil;
}
/* nested body structure */
- (id) contentInfo
{
return [[self bodyInfo] valueForKey:@"body"];
}
- (id) contentPartPath
{
/*
Path processing is a bit weird in the context of message/rfc822. If we have
a multipart, the multipart itself has no own identifier! Instead the
children of the multipart are directly mapped into the message namespace.
If the message has just a plain content, ids seems to be as expected (that
is, its just a "1").
*/
NSArray *pp;
NSString *mt;
mt = [[[self contentInfo] valueForKey:@"type"] lowercaseString];
if ([mt isEqualToString:@"multipart"])
return [self partPath];
pp = [self partPath];
return (([pp count] > 0)
? (id)[pp arrayByAddingObject: @"1"]
: (id)[NSArray arrayWithObject: @"1"]);
}
- (id) contentViewerComponent
{
UIxMailRenderingContext *mailContext;
mailContext = [[self context] mailRenderingContext];
return [mailContext viewerForBodyInfo: [self contentInfo]];
}
/* generating envelope */
- (NGImap4Envelope *) envelope
{
if (!envelope)
envelope = [[NGImap4Envelope alloc] initWithBodyStructureInfo:
[self bodyInfo]];
return envelope;
}
- (NSString *) formattedComponents: (NSArray *) components
{
NSMutableArray *formattedComponents;
unsigned int count, max;
NSString *component;
max = [components count];
formattedComponents = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
component = [[components objectAtIndex: count] email];
if (component)
[formattedComponents addObject: [component decodedHeader]];
}
return [formattedComponents componentsJoinedByString: @", "];
}
- (NSString *) messageSubject
{
id baseSubject;
NSString *subject;
baseSubject = [[self envelope] subject];
// We avoid uber-lamenesses in SOPE - see sope-core/NGExtensions/NGQuotedPrintableCoding.m
// -stringByDecodingQuotedPrintable for all details
if ([baseSubject isKindOfClass: [NSString class]])
baseSubject = [baseSubject dataUsingEncoding: NSASCIIStringEncoding];
subject = [baseSubject decodedHeader];
if (![subject length])
subject = @"";
return subject;
}
- (NSString *) fromAddresses
{
NSArray *from;
from = [[self envelope] from];
return [self formattedComponents: from];
}
- (NSString *) toAddresses
{
NSArray *to;
to = [[self envelope] to];
return [self formattedComponents: to];
}
- (NSString *) ccAddresses
{
NSArray *cc;
cc = [[self envelope] cc];
return [self formattedComponents: cc];
}
/* links to recipients */
- (NSString *) linkToEnvelopeAddress: (NGImap4EnvelopeAddress *) _address
{
// TODO: make some web-link, eg open a new compose panel?
return [@"mailto:" stringByAppendingString:[_address baseEMail]];
}
- (id) renderedPart
{
id info, viewer;
NSArray *parts;
NSMutableArray *renderedParts;
NSUInteger i, max;
parts = [[self contentInfo] objectForKey: @"parts"];
renderedParts = [NSMutableArray array];
max = [parts count];
// Might get a multipart/*
if (max)
{
for (i = 0; i < max; i++)
{
info = [parts objectAtIndex: i];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setPartPath: [[self contentPartPath] arrayByAddingObject: [NSString stringWithFormat: @"%d", (int)i+1]]];
[renderedParts addObject: [viewer renderedPart]];
}
}
else
{
info = [self contentInfo];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setPartPath: [self contentPartPath]];
[renderedParts addObject: [viewer renderedPart]];
}
// We inject the output of our UIxMailPartMessageViewer template
// in order to pretty-format the parts following it.
info = [NSDictionary dictionaryWithObjectsAndKeys: @"text/plain", @"contentType", @"UIxMailPartTextViewer", @"type",
[[self generateResponse] contentAsString], @"content", nil];
[renderedParts insertObject: info atIndex: 0];
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
renderedParts, @"content",
nil];
}
@end /* UIxMailPartMessageViewer */
|