Skip to content

Commit

Permalink
Merge to 2.2.16
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Feb 12, 2015
2 parents 3ca94c6 + b26ea30 commit d16eeb1
Show file tree
Hide file tree
Showing 35 changed files with 1,623 additions and 87 deletions.
123 changes: 117 additions & 6 deletions ActiveSync/SOGoMailObject+ActiveSync.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#import <NGExtensions/NSString+Encoding.h>
#import <NGImap4/NGImap4Envelope.h>
#import <NGImap4/NGImap4EnvelopeAddress.h>
#import <NGImap4/NSString+Imap4.h>
#import <NGObjWeb/WOContext+SoObjects.h>

#import <NGMime/NGMimeBodyPart.h>
Expand All @@ -57,6 +58,10 @@
#import <NGMail/NGMimeMessage.h>
#import <NGMail/NGMimeMessageGenerator.h>

#import <Mailer/SOGoMailLabel.h>

#import <SOGo/SOGoUserDefaults.h>

#include "iCalTimeZone+ActiveSync.h"
#include "NSData+ActiveSync.h"
#include "NSDate+ActiveSync.h"
Expand Down Expand Up @@ -204,6 +209,7 @@ - (NSString *) _emailAddressesFrom: (NSArray *) enveloppeAddresses
//
//
- (NSData *) _preferredBodyDataInMultipartUsingType: (int) theType
nativeTypeFound: (int *) theNativeTypeFound
{
NSString *encoding, *key, *plainKey, *htmlKey, *type, *subtype;
NSDictionary *textParts, *part;
Expand All @@ -222,18 +228,33 @@ - (NSData *) _preferredBodyDataInMultipartUsingType: (int) theType
type = [part valueForKey: @"type"];
subtype = [part valueForKey: @"subtype"];

// Don't select an attachment as body
if ([[[part valueForKey: @"disposition"] valueForKey: @"type"] isEqualToString: @"attachment"])
continue;

if ([type isEqualToString: @"text"] && [subtype isEqualToString: @"html"])
htmlKey = key;
else if ([type isEqualToString: @"text"] && [subtype isEqualToString: @"plain"])
plainKey = key;
}

key = nil;
*theNativeTypeFound = 1;

if (theType == 2)
key = htmlKey;
else if (theType == 1)
if (theType == 2 && htmlKey)
{
key = htmlKey;
*theNativeTypeFound = 2;
}
else if (theType == 1 && plainKey)
key = plainKey;
else if (theType == 2 && plainKey)
key = plainKey;
else if (theType == 1 && htmlKey)
{
key = htmlKey;
*theNativeTypeFound = 2;
}

if (key)
{
Expand All @@ -254,6 +275,10 @@ - (NSData *) _preferredBodyDataInMultipartUsingType: (int) theType
charset = @"us-ascii";

s = [NSString stringWithData: d usingEncodingNamed: charset];

if (theType == 1 && *theNativeTypeFound == 2)
s = [s htmlToText];

d = [s dataUsingEncoding: NSUTF8StringEncoding];
}

Expand Down Expand Up @@ -434,12 +459,12 @@ - (NSData *) _preferredBodyDataUsingType: (int) theType
{
s = [s htmlToText];
}

d = [s dataUsingEncoding: NSUTF8StringEncoding];
}
else if ([type isEqualToString: @"multipart"])
{
d = [self _preferredBodyDataInMultipartUsingType: theType];
d = [self _preferredBodyDataInMultipartUsingType: theType nativeTypeFound: theNativeType];
}
}
else if (theType == 4)
Expand Down Expand Up @@ -729,7 +754,13 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) _context
len = [content length];

[s appendString: @"<Body xmlns=\"AirSyncBase:\">"];
[s appendFormat: @"<Type>%d</Type>", preferredBodyType];

// Set the correct type if client requested text/html but we got text/plain
if (preferredBodyType == 2 && nativeBodyType == 1)
[s appendString: @"<Type>1</Type>"];
else
[s appendFormat: @"<Type>%d</Type>", preferredBodyType];

[s appendFormat: @"<Truncated>%d</Truncated>", truncated];
[s appendFormat: @"<Preview></Preview>"];

Expand Down Expand Up @@ -774,6 +805,27 @@ - (NSString *) activeSyncRepresentationInContext: (WOContext *) _context
[s appendString: @"<Flag xmlns=\"Email:\">"];
[s appendFormat: @"<FlagStatus>%d</FlagStatus>", ([self flagged] ? 2 : 0)];
[s appendString: @"</Flag>"];


// Categroies/Labels
NSEnumerator *categories;
categories = [[[self fetchCoreInfos] objectForKey: @"flags"] objectEnumerator];

if (categories)
{
NSString *currentFlag;
NSDictionary *v;

v = [[[context activeUser] userDefaults] mailLabelsColors];

[s appendFormat: @"<Categories xmlns=\"Email:\">"];
while ((currentFlag = [categories nextObject]))
{
if ([[v objectForKey: currentFlag] objectAtIndex:0])
[s appendFormat: @"<Category>%@</Category>", [[[v objectForKey: currentFlag] objectAtIndex:0] activeSyncRepresentationInContext: context]];
}
[s appendFormat: @"</Categories>"];
}

// FIXME - support these in the future
//[s appendString: @"<ConversationId xmlns=\"Email2:\">foobar</ConversationId>"];
Expand Down Expand Up @@ -836,6 +888,65 @@ - (void) takeActiveSyncValues: (NSDictionary *) theValues
else
[self removeFlags: @"seen"];;
}

if ((o = [theValues objectForKey: @"Categories"]))
{
NSEnumerator *categories;
NSString *currentFlag;
NSDictionary *v;

v = [[[context activeUser] userDefaults] mailLabelsColors];

// add categories/labels sent from client
if ([o isKindOfClass: [NSArray class]])
{
NSEnumerator *enumerator;
NSMutableArray *labels;
NSEnumerator *flags;
id key;

labels = [NSMutableArray array];

enumerator = [v keyEnumerator];
flags = [o objectEnumerator];

while ((currentFlag = [flags nextObject]))
{
while ((key = [enumerator nextObject]))
{
if (([currentFlag isEqualToString:[[v objectForKey:key] objectAtIndex:0]]))
{
[labels addObject: key];
break;
}
}
}

[self addFlags: [labels componentsJoinedByString: @" "]];
}

categories = [[[self fetchCoreInfos] objectForKey: @"flags"] objectEnumerator];

// remove all categories/labels from server which were not it the list sent from client
if (categories)
{
while ((currentFlag = [categories nextObject]))
{
// only deal with lables and don't touch flags like seen and flagged
if (([v objectForKey: currentFlag]))
{
if (![o isKindOfClass: [NSArray class]])
{
[self removeFlags: currentFlag];
}
else if (([o indexOfObject: [[v objectForKey:currentFlag] objectAtIndex:0]] == NSNotFound))
{
[self removeFlags: currentFlag];
}
}
}
}
}
}

@end
Loading

0 comments on commit d16eeb1

Please sign in to comment.