JSONify mail parts

This commit is contained in:
Francis Lachapelle
2015-06-12 12:02:18 -04:00
parent 6cd02043af
commit 9ed65e34ad
9 changed files with 215 additions and 103 deletions
@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2009 Inverse inc.
Copyright (C) 2007-2015 Inverse inc.
Copyright (C) 2004 SKYRIX Software AG
This file is part of SOGo.
@@ -15,11 +15,12 @@
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
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 <Foundation/NSDictionary.h>
#import <Foundation/NSNull.h>
#import <NGExtensions/NSObject+Logs.h>
@@ -27,24 +28,21 @@
#import <UI/MailerUI/WOContext+UIxMailer.h>
#import "UIxMailPartViewer.h"
#import "UIxMailPartMixedViewer.h"
#import "UIxMailRenderingContext.h"
/*
UIxMailPartAlternativeViewer
Display multipart/alternative parts. Most common application is for messages
which contain text/html and text/plain, but it is also used in other
contexts, eg in OGo appointment mails.
TODO: We might want to give the user the possibility to access all parts
of the alternative set.
*/
@interface UIxMailPartAlternativeViewer : UIxMailPartViewer
{
id childInfo;
NSUInteger childIndex;
}
@interface UIxMailPartAlternativeViewer : UIxMailPartMixedViewer
@end
@@ -52,19 +50,9 @@
- (void) dealloc
{
[childInfo release];
[super dealloc];
}
/* caches */
- (void) resetBodyInfoCaches
{
[childInfo release]; childInfo = nil;
childIndex = 0;
[super resetBodyInfoCaches];
}
/* part selection */
- (NSArray *) childPartTypes
@@ -76,7 +64,7 @@
childParts = [[self bodyInfo] valueForKey:@"parts"];
count = [childParts count];
types = [NSMutableArray arrayWithCapacity:count];
for (i = 0; i < count; i++) {
NSString *mt, *st;
@@ -140,7 +128,7 @@
[childInfo release]; childInfo = nil;
childIndex = 0;
idx = [self _selectPartIndexFromTypes: [self childPartTypes]];
if (idx == NSNotFound)
{
@@ -150,42 +138,7 @@
}
childIndex = idx + 1;
childInfo =
[[[[self bodyInfo] valueForKey:@"parts"] objectAtIndex:idx] retain];
}
/* accessors */
- (id) childInfo
{
if (!childInfo)
[self selectChildInfo];
return childInfo;
}
- (NSUInteger) childIndex
{
if (!childIndex)
[self selectChildInfo];
return childIndex - 1;
}
- (NSString *) childPartName
{
return [NSString stringWithFormat: @"%u",
(unsigned int) ([self childIndex] + 1)];
}
- (id) childPartPath
{
NSArray *pp;
pp = [self partPath];
return [pp count] > 0
? (id)[pp arrayByAddingObject:[self childPartName]]
: (id)[NSArray arrayWithObject:[self childPartName]];
childInfo = [[[[self bodyInfo] valueForKey:@"parts"] objectAtIndex:idx] retain];
}
/* nested viewers */
@@ -193,9 +146,43 @@
- (id) contentViewerComponent
{
id info;
info = [self childInfo];
return [[[self context] mailRenderingContext] viewerForBodyInfo:info];
}
- (id) renderedPart {
id info, viewer;
NSArray *parts;
NSMutableArray *renderedParts;
NSString *preferredType;
NSUInteger i, max;
parts = [[self bodyInfo] objectForKey: @"parts"];
max = [parts count];
renderedParts = [NSMutableArray arrayWithCapacity: max];
for (i = 0; i < max; i++)
{
[self setChildIndex: i];
[self setChildInfo: [parts objectAtIndex: i]];
info = [self childInfo];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setPartPath: [self childPartPath]];
[renderedParts addObject: [viewer renderedPart]];
}
// Identity a preferred type
[self selectChildInfo];
preferredType = [NSString stringWithFormat: @"%@/%@",
[[self childInfo] objectForKey: @"type"],
[[self childInfo] objectForKey: @"subtype"]];
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
preferredType, @"preferredPart",
renderedParts, @"content",
nil];
}
@end /* UIxMailPartAlternativeViewer */
+10 -4
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2009 Inverse inc.
Copyright (C) 2007-2015 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
@@ -15,7 +15,7 @@
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
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.
*/
@@ -27,10 +27,16 @@
@interface UIxMailPartMixedViewer : UIxMailPartViewer
{
id childInfo;
unsigned int childIndex;
id childInfo;
NSUInteger childIndex;
}
- (void) setChildInfo: (id) _info;
- (id) childInfo;
- (void) setChildIndex: (unsigned int) _index;
- (id) childPartPath;
@end
#endif /* UIXMAILPARTMIXEDVIEWER_H */
+33 -3
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2009 Inverse inc.
Copyright (C) 2007-2015 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
@@ -20,6 +20,8 @@
02111-1307, USA.
*/
#import <Foundation/NSDictionary.h>
#import <UI/MailerUI/WOContext+UIxMailer.h>
#import "UIxMailRenderingContext.h"
@@ -48,14 +50,16 @@
return self->childInfo;
}
- (void)setChildIndex:(unsigned int)_index {
- (void) setChildIndex: (NSUInteger) _index {
self->childIndex = _index;
}
- (unsigned int)childIndex {
- (NSUInteger) childIndex {
return self->childIndex;
}
- (NSString *)childPartName {
return [NSString stringWithFormat: @"%u",
(unsigned int) ([self childIndex] + 1)];
char buf[8];
sprintf(buf, "%d", [self childIndex] + 1);
return [NSString stringWithCString:buf];
@@ -79,4 +83,30 @@
return [[[self context] mailRenderingContext] viewerForBodyInfo:info];
}
- (id) renderedPart {
id info, viewer;
NSArray *parts;
NSMutableArray *renderedParts;
NSUInteger i, max;
parts = [[self bodyInfo] objectForKey: @"parts"];
max = [parts count];
renderedParts = [NSMutableArray arrayWithCapacity: max];
for (i = 0; i < max; i++)
{
[self setChildIndex: i];
[self setChildInfo: [parts objectAtIndex: i]];
info = [self childInfo];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo: info];
[viewer setBodyInfo: info];
[viewer setPartPath: [self childPartPath]];
[renderedParts addObject: [viewer renderedPart]];
}
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
renderedParts, @"content",
nil];
}
@end /* UIxMailPartMixedViewer */
+33 -4
View File
@@ -1,9 +1,6 @@
/* UIxMailPartSignedViewer.m - this file is part of SOGo
*
* Copyright (C) 2009 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Ludovic Marcotte <lmarcotte@inverse.ca>
* Copyright (C) 2009-2015 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
@@ -30,9 +27,12 @@
#endif
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSValue.h>
#import <NGMime/NGPart.h>
#import <Mailer/SOGoMailObject.h>
#import "UIxMailRenderingContext.h"
#import "UIxMailPartSignedViewer.h"
@implementation UIxMailPartSignedViewer : UIxMailPartMixedViewer
@@ -211,4 +211,33 @@
}
#endif
- (id) renderedPart {
id info, viewer;
NSArray *parts;
NSMutableArray *renderedParts;
NSUInteger i, max;
parts = [[self bodyInfo] objectForKey: @"parts"];
max = [parts count];
renderedParts = [NSMutableArray arrayWithCapacity: max];
for (i = 0; i < max; i++)
{
[self setChildIndex: i];
[self setChildInfo: [parts objectAtIndex: i]];
info = [self childInfo];
viewer = [[[self context] mailRenderingContext] viewerForBodyInfo:info];
[viewer setBodyInfo: info];
[viewer setPartPath: [self childPartPath]];
[renderedParts addObject: [viewer renderedPart]];
}
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
@"supports-smime", [NSNumber numberWithBool: [self supportsSMIME]],
@"valid", [NSNumber numberWithBool: [self validSignature]],
@"error", [self validationMessage],
renderedParts, @"content",
nil];
}
@end
+3 -1
View File
@@ -1,4 +1,5 @@
/*
Copyright (C) 2015 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of OpenGroupware.org.
@@ -14,7 +15,7 @@
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
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.
*/
@@ -63,6 +64,7 @@
- (id)bodyInfo;
- (SOGoMailBodyPart *) clientPart;
- (id) renderedPart;
- (NSData *)flatContent;
- (NSData *)decodedFlatContent;
+19 -2
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2007-2013 Inverse inc.
Copyright (C) 2007-2015 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
@@ -15,7 +15,7 @@
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
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.
*/
@@ -31,6 +31,8 @@
#import <NGExtensions/NSString+Encoding.h>
#import <NGExtensions/NSString+misc.h>
#import <NGObjWeb/WOResponse.h>
#import <SOGo/NSString+Utilities.h>
#import <Mailer/NSData+Mail.h>
#import <Mailer/NSDictionary+Mail.h>
@@ -141,6 +143,21 @@
return currentObject;
}
- (id) renderedPart
{
NSString *type;
type = [NSString stringWithFormat: @"%@/%@",
[bodyInfo objectForKey: @"type"],
[bodyInfo objectForKey: @"subtype"]];
return [NSDictionary dictionaryWithObjectsAndKeys:
[self className], @"type",
type, @"contentType",
[[self generateResponse] contentAsString], @"content",
nil];
}
- (NSData *) content
{
return [[self clientObject] fetchBLOB];