From 96d62c432b230e15e166e9749f953a9529e144d8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sat, 23 Dec 2017 06:10:11 -0500 Subject: [PATCH] (fix) made the code a bit more robust --- SoObjects/Mailer/SOGoMailObject.m | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index d7f2e2f40..ba39480d0 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -1196,17 +1196,24 @@ static BOOL debugSoParts = NO; if ([self isEncrypted]) { NSData *certificate; - NGMimeMessage *m; - id part; certificate = [[self mailAccountFolder] certificate]; - m = [[self content] messageFromEncryptedDataAndCertificate: certificate]; - part = [[[m body] parts] objectAtIndex: ([_key intValue]-1)]; - mimeType = [[part contentType] stringValue]; - clazz = [SOGoMailBodyPart bodyPartClassForMimeType: mimeType - inContext: _ctx]; - return [clazz objectWithName:_key inContainer: self]; + // If we got a user certificate, let's use it. Otherwise we fallback + // to the current parts fetching code. + if (certificate) + { + NGMimeMessage *m; + id part; + + m = [[self content] messageFromEncryptedDataAndCertificate: certificate]; + + part = [[[m body] parts] objectAtIndex: ([_key intValue]-1)]; + mimeType = [[part contentType] stringValue]; + clazz = [SOGoMailBodyPart bodyPartClassForMimeType: mimeType + inContext: _ctx]; + return [clazz objectWithName:_key inContainer: self]; + } } parts = [[self bodyStructure] objectForKey: @"parts"];