(fix) cleanups and proper handling when trying to decrypt email with no cert

This commit is contained in:
Ludovic Marcotte
2017-12-23 09:34:26 -05:00
parent 35c7f483d9
commit 643c6b7ebf
2 changed files with 33 additions and 34 deletions

View File

@@ -24,8 +24,11 @@
#import <NGExtensions/NSObject+Logs.h>
#import <NGMail/NGMimeMessageParser.h>
#import <NGMime/NGMimeType.h>
#import <SoObjects/Mailer/NSData+SMIME.h>
#import <SoObjects/Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoMailObject.h>
#import <UI/MailerUI/WOContext+UIxMailer.h>
#import "UIxMailRenderingContext.h"
@@ -45,49 +48,39 @@
- (id) renderedPart
{
NSData *certificate;
NSData *certificate, *decryptedData, *encryptedData;
id info, viewer;
certificate = [[[self clientObject] mailAccountFolder] certificate];
encryptedData = [[self clientObject] content];
decryptedData = [encryptedData decryptUsingCertificate: certificate];
if (certificate)
if (decryptedData)
{
NSData *decryptedData, *encryptedData;
NGMimeMessageParser *parser;
id part;
encryptedData = [[self clientObject] content];
decryptedData = [encryptedData decryptUsingCertificate: certificate];
parser = [[NGMimeMessageParser alloc] init];
part = [[parser parsePartFromData: decryptedData] retain];
if (decryptedData)
{
NGMimeMessageParser *parser;
id part;
info = [NSDictionary dictionaryWithObjectsAndKeys: [[part contentType] type], @"type",
[[part contentType] subType], @"subtype", nil];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setFlatContent: decryptedData];
[viewer setDecodedContent: [part body]];
parser = [[NGMimeMessageParser alloc] init];
part = [[parser parsePartFromData: decryptedData] retain];
info = [NSDictionary dictionaryWithObjectsAndKeys: [[part contentType] type], @"type",
[[part contentType] subType], @"subtype", nil];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setFlatContent: decryptedData];
[viewer setDecodedContent: [part body]];
return [NSDictionary dictionaryWithObjectsAndKeys:
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
[NSArray arrayWithObject: [viewer renderedPart]], @"content",
nil];
}
[NSArray arrayWithObject: [viewer renderedPart]], @"content",
nil];
}
// Decryption failed, let's return the master viewer
// FIXME - does not work for now.
info = [NSDictionary dictionaryWithObjectsAndKeys: @"multipart", @"type",
@"mixed", @"subtype", nil];
[self setFlatContent: nil];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
return [viewer renderedPart];
// Decryption failed, let's return something else...
// FIXME - does not work for now.
return nil;
}
@end /* UIxMailPartAlternativeViewer */

View File

@@ -26,6 +26,7 @@
#import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSNull+misc.h>
#import <SoObjects/Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoMailObject.h>
#import "UIxMailRenderingContext.h"
@@ -195,7 +196,7 @@ static BOOL showNamedTextAttachmentsInline = NO;
else if ([st isEqualToString: @"alternative"])
return [self alternativeViewer];
if ([st isEqualToString:@"report"])
if ([st isEqualToString: @"report"])
/* this is used by mail-delivery reports */
return [self mixedViewer];
}
@@ -249,12 +250,17 @@ static BOOL showNamedTextAttachmentsInline = NO;
if ([mt isEqualToString: @"application"])
{
// octet-stream (generate download link?, autodetect type?)
if ([st isEqualToString:@"ics"]) /* Cooqle K4lendahr - Google Calendar */
if ([st isEqualToString: @"ics"]) /* Cooqle K4lendahr - Google Calendar */
return [self iCalViewer];
if ([st isEqualToString: @"x-pkcs7-mime"] ||
[st isEqualToString: @"pkcs7-mime"])
return [self encryptedViewer];
{
// If the mail account has a valid certificate, we try to decode
// the encrypted email. Otherwise, we fallback to a link viewer
if ([[[viewer clientObject] mailAccountFolder] certificate])
return [self encryptedViewer];
}
#if 0 /* the link viewer looks better than plain text ;-) */
if ([st isEqualToString: @"pgp-signature"]) // TODO: real PGP viewer