JSONify mail parts

This commit is contained in:
Francis Lachapelle
2015-05-12 22:37:58 -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 */