From 2a93ea4e6dfecbd1f37e8c56715a30a5b8d1a64b Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 31 Oct 2011 19:28:22 +0000 Subject: [PATCH] Monotone-Parent: a0e83a1784478d41763fc4ebb3eb9ee8a5142b5a Monotone-Revision: 55595f6ee3aaa33db773a4eb60c184519b6f18fd Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-10-31T19:28:22 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 11 +++++++++++ SoObjects/Mailer/SOGoMailBodyPart.h | 1 + SoObjects/Mailer/SOGoMailBodyPart.m | 10 ++++++++-- SoObjects/Mailer/SOGoMailObject+Draft.m | 3 ++- SoObjects/Mailer/SOGoMailObject.h | 3 ++- SoObjects/Mailer/SOGoMailObject.m | 18 ++++++++++++------ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 793378e10..afff8fd85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-10-31 Wolfgang Sourdeau + + * SoObjects/Mailer/SOGoMailBodyPart.m (-fetchBLOBWithPeek:): new + method that enables the fetching of body parts either via "BODY" + or "BODY.PEEK". + + * SoObjects/Mailer/SOGoMailObject.m + (-addRequiredKeysOfStructure:path:toArray:acceptedTypes:withPeek:): + added a "withPeek" parameter that enables the fetching of body + parts either via "BODY" or "BODY.PEEK". + 2011-10-28 Wolfgang Sourdeau * OpenChange/MAPIStoreMailVolatileMessage.m (_generateMailData): diff --git a/SoObjects/Mailer/SOGoMailBodyPart.h b/SoObjects/Mailer/SOGoMailBodyPart.h index 76cc84dba..ed814e4c0 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.h +++ b/SoObjects/Mailer/SOGoMailBodyPart.h @@ -59,6 +59,7 @@ - (id) partInfo; - (NSData *) fetchBLOB; +- (NSData *) fetchBLOBWithPeek: (BOOL) withPeek; - (void) setAsAttachment; /* factory */ diff --git a/SoObjects/Mailer/SOGoMailBodyPart.m b/SoObjects/Mailer/SOGoMailBodyPart.m index cf58c1023..9728eadce 100644 --- a/SoObjects/Mailer/SOGoMailBodyPart.m +++ b/SoObjects/Mailer/SOGoMailBodyPart.m @@ -258,7 +258,7 @@ static BOOL debugOn = NO; /* fetch */ -- (NSData *) fetchBLOB +- (NSData *) fetchBLOBWithPeek: (BOOL) withPeek { // HEADER, HEADER.FIELDS, HEADER.FIELDS.NOT, MIME, TEXT NSString *enc; @@ -266,7 +266,8 @@ static BOOL debugOn = NO; data = [[self imap4Connection] fetchContentOfBodyPart: [self bodyPartIdentifier] - atURL:[self imap4URL]]; + atURL:[self imap4URL] + withPeek: withPeek]; if (data == nil) return nil; /* check for content encodings */ @@ -299,6 +300,11 @@ static BOOL debugOn = NO; return data; } +- (NSData *) fetchBLOB +{ + return [self fetchBLOBWithPeek: NO]; +} + /* WebDAV */ - (NSString *)contentTypeForBodyPartInfo:(id)_info { diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index 7ac01e373..e27cac368 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -141,7 +141,8 @@ = [NSArray arrayWithObjects: @"text/plain", @"text/html", nil]; keys = [NSMutableArray array]; [self addRequiredKeysOfStructure: [self bodyStructure] - path: @"" toArray: keys acceptedTypes: acceptedTypes]; + path: @"" toArray: keys acceptedTypes: acceptedTypes + withPeek: NO]; return [self _contentForEditingFromKeys: keys]; } diff --git a/SoObjects/Mailer/SOGoMailObject.h b/SoObjects/Mailer/SOGoMailObject.h index 34ed172de..cc56324d7 100644 --- a/SoObjects/Mailer/SOGoMailObject.h +++ b/SoObjects/Mailer/SOGoMailObject.h @@ -126,7 +126,8 @@ NSArray *SOGoMailCoreInfoKeys; - (void) addRequiredKeysOfStructure: (NSDictionary *) info path: (NSString *) p toArray: (NSMutableArray *) keys - acceptedTypes: (NSArray *) types; + acceptedTypes: (NSArray *) types + withPeek: (BOOL) withPeek; @end diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index 15ca436e5..b6dd7054d 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -527,6 +527,7 @@ static BOOL debugSoParts = NO; path: (NSString *) p toArray: (NSMutableArray *) keys acceptedTypes: (NSArray *) types + withPeek: (BOOL) withPeek { /* This is used to collect the set of IMAP4 fetch-keys required to fetch @@ -539,9 +540,11 @@ static BOOL debugSoParts = NO; unsigned i, count; NSString *k; id body; - NSString *sp, *mimeType; + NSString *bodyToken, *sp, *mimeType; id childInfo; + bodyToken = (withPeek ? @"body.peek" : @"body"); + mimeType = [[NSString stringWithFormat: @"%@/%@", [info valueForKey: @"type"], [info valueForKey: @"subtype"]] @@ -549,7 +552,7 @@ static BOOL debugSoParts = NO; if ([types containsObject: mimeType]) { if ([p length] > 0) - k = [NSString stringWithFormat: @"body[%@]", p]; + k = [NSString stringWithFormat: @"%@[%@]", bodyToken, p]; else { /* @@ -557,7 +560,7 @@ static BOOL debugSoParts = NO; entities? TODO: check with HTML */ - k = @"body[text]"; + k = [NSString stringWithFormat: @"%@[text]", bodyToken]; } [keys addObject: [NSDictionary dictionaryWithObjectsAndKeys: k, @"key", mimeType, @"mimeType", nil]]; @@ -575,7 +578,8 @@ static BOOL debugSoParts = NO; [self addRequiredKeysOfStructure: childInfo path: sp toArray: keys - acceptedTypes: types]; + acceptedTypes: types + withPeek: withPeek]; } /* check body */ @@ -600,7 +604,8 @@ static BOOL debugSoParts = NO; sp = [p length] > 0 ? (id)[p stringByAppendingString: @".1"] : (id)@"1"; [self addRequiredKeysOfStructure: body path: sp toArray: keys - acceptedTypes: types]; + acceptedTypes: types + withPeek: withPeek]; } } @@ -618,7 +623,8 @@ static BOOL debugSoParts = NO; @"application/pgp-signature", nil]; ma = [NSMutableArray arrayWithCapacity: 4]; [self addRequiredKeysOfStructure: [self bodyStructure] - path: @"" toArray: ma acceptedTypes: types]; + path: @"" toArray: ma acceptedTypes: types + withPeek: NO]; return ma; }