From 695afc670fc207a84d68f1d8d5910ae191a56c45 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sat, 23 Dec 2017 08:56:29 -0500 Subject: [PATCH] (feat) new encrypted viewer + cosmetics in text one --- UI/MailPartViewers/GNUmakefile | 1 + .../UIxMailPartEncryptedViewer.h | 35 ++++++++ .../UIxMailPartEncryptedViewer.m | 82 +++++++++++++++++++ UI/MailPartViewers/UIxMailPartTextViewer.h | 4 +- UI/MailPartViewers/UIxMailPartTextViewer.m | 4 +- 5 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 UI/MailPartViewers/UIxMailPartEncryptedViewer.h create mode 100644 UI/MailPartViewers/UIxMailPartEncryptedViewer.m diff --git a/UI/MailPartViewers/GNUmakefile b/UI/MailPartViewers/GNUmakefile index e1e4bc767..6834d0f68 100644 --- a/UI/MailPartViewers/GNUmakefile +++ b/UI/MailPartViewers/GNUmakefile @@ -20,6 +20,7 @@ MailPartViewers_OBJC_FILES += \ UIxMailPartImageViewer.m \ UIxMailPartLinkViewer.m \ UIxMailPartMixedViewer.m \ + UIxMailPartEncryptedViewer.m \ UIxMailPartSignedViewer.m \ UIxMailPartAlternativeViewer.m \ UIxMailPartMessageViewer.m \ diff --git a/UI/MailPartViewers/UIxMailPartEncryptedViewer.h b/UI/MailPartViewers/UIxMailPartEncryptedViewer.h new file mode 100644 index 000000000..6c950e078 --- /dev/null +++ b/UI/MailPartViewers/UIxMailPartEncryptedViewer.h @@ -0,0 +1,35 @@ +/* UIxMailPartEncryptedViewer.h - this file is part of SOGo + * + * Copyright (C) 2017 Inverse inc. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef UIXMAILPARTENCRYPTEDVIEWER_H +#define UIXMAILPARTENCRYPTEDVIEWER_H + +#import "UIxMailPartViewer.h" + +@class NSMutableString; +@class NGPart; + +@interface UIxMailPartEncryptedViewer : UIxMailPartViewer +{ +} + +@end + +#endif /* UIXMAILPARTENCRYPTEDVIEWER_H */ diff --git a/UI/MailPartViewers/UIxMailPartEncryptedViewer.m b/UI/MailPartViewers/UIxMailPartEncryptedViewer.m new file mode 100644 index 000000000..78fa9b24e --- /dev/null +++ b/UI/MailPartViewers/UIxMailPartEncryptedViewer.m @@ -0,0 +1,82 @@ +/* + Copyright (C) 2017 Inverse inc. + + 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 SOGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#import +#import + +#import +#import + +#import +#import + +#import "UIxMailRenderingContext.h" +#import "UIxMailPartEncryptedViewer.h" + +@implementation UIxMailPartEncryptedViewer + +/* nested viewers */ + +- (id) contentViewerComponent +{ + id info; + + info = [self childInfo]; + return [[[self context] mailRenderingContext] viewerForBodyInfo: info]; +} + +- (id) renderedPart +{ + id info, viewer; + + NSData *encryptedData; + +#if 1 + NSData *pkcs12Data = [NSData dataWithContentsOfFile: @"/home/sogo/dropbucket/lmarcotte@inverse.ca.p12"]; + [pkcs12Data convertPKCS12ToPEMUsingPassword: @"831af13d97576d74d574628c1d0e5abe"]; +#endif + + + encryptedData = [[self clientObject] content]; + [encryptedData writeToFile: @"/tmp/received.encrypted" atomically: 1]; + + //NSData *pem = [NSData dataWithContentsOfFile: @"/home/sogo/dropbucket/lmarcotte@inverse.ca.pem"]; + NSData *pem = [NSData dataWithContentsOfFile: @"/tmp/foofoo.newpem"]; + NSData *decryptedData = [encryptedData decryptUsingCertificate: pem]; + + NGMimeMessageParser *parser = [[NGMimeMessageParser alloc] init]; + id 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: + [self className], @"type", + [NSArray arrayWithObject: [viewer renderedPart]], @"content", + nil]; + //return [viewer renderedPart]; +} + +@end /* UIxMailPartAlternativeViewer */ diff --git a/UI/MailPartViewers/UIxMailPartTextViewer.h b/UI/MailPartViewers/UIxMailPartTextViewer.h index 8a99ed462..68d73c3ff 100644 --- a/UI/MailPartViewers/UIxMailPartTextViewer.h +++ b/UI/MailPartViewers/UIxMailPartTextViewer.h @@ -1,6 +1,6 @@ -/* UIxMailPartTextViewer.h - this file is part of $PROJECT_NAME_HERE$ +/* UIxMailPartTextViewer.h - this file is part of SOGo. * - * Copyright (C) 2006-2015 Inverse inc. + * Copyright (C) 2006-2017 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/UI/MailPartViewers/UIxMailPartTextViewer.m b/UI/MailPartViewers/UIxMailPartTextViewer.m index 227b8e8bb..8ca148008 100644 --- a/UI/MailPartViewers/UIxMailPartTextViewer.m +++ b/UI/MailPartViewers/UIxMailPartTextViewer.m @@ -1,6 +1,6 @@ -/* UIxMailPartTextViewer.m - this file is part of $PROJECT_NAME_HERE$ +/* UIxMailPartTextViewer.m - this file is part of SOGo. * - * Copyright (C) 2006-2015 Inverse inc. + * Copyright (C) 2006-2017 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by