From 6294d91180b0a258ee3f48a370540ec1d344fe92 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sat, 23 Dec 2017 06:06:23 -0500 Subject: [PATCH] (feat) added S/MIME file download support --- SoObjects/Mailer/SOGoMailBodyPart.m | 39 +++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailBodyPart.m b/SoObjects/Mailer/SOGoMailBodyPart.m index b0ac78d22..5cb01b106 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SoObjects/Mailer/SOGoMailBodyPart.m @@ -1,14 +1,15 @@ /* + Copyright (C) 2005-2017 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG - This file is part of OpenGroupware.org. + This file is part of SOGo. - OGo is free software; you can redistribute it and/or modify it under + 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. - OGo is distributed in the hope that it will be useful, but WITHOUT ANY + 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. @@ -32,12 +33,15 @@ #import #import #import +#import +#import #import +#import "NSData+SMIME.h" #import "NSDictionary+Mail.h" #import "SOGoMailObject.h" - +#import "SOGoMailAccount.h" #import "SOGoMailBodyPart.h" @implementation SOGoMailBodyPart @@ -250,10 +254,9 @@ static BOOL debugOn = NO; NSString *enc; NSData *data; - data = [[self imap4Connection] fetchContentOfBodyPart: - [self bodyPartIdentifier] - atURL:[self imap4URL] - withPeek: withPeek]; + data = [[self imap4Connection] fetchContentOfBodyPart: [self bodyPartIdentifier] + atURL: [self imap4URL] + withPeek: withPeek]; if (data == nil) return nil; /* check for content encodings */ @@ -289,6 +292,26 @@ static BOOL debugOn = NO; - (NSData *) fetchBLOB { + if ([[self container] isEncrypted]) + { + NSData *certificate; + + certificate = [[self mailAccountFolder] certificate]; + + // If we got a user certificate, let's use it. Otherwise we fallback + // to the current BLOB fetching code. + if (certificate) + { + NGMimeMessage *m; + id part; + + m = [[container content] messageFromEncryptedDataAndCertificate: certificate]; + part = [[[m body] parts] objectAtIndex: ([[self nameInContainer] intValue]-1)]; + + return [part body]; + } + } + return [self fetchBLOBWithPeek: NO]; }