From: helge Date: Tue, 14 Aug 2007 16:44:04 +0000 (+0000) Subject: added bodystructure fetches (v4.7.251) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e6022138e3860e167d46dd2f535bd1f1a6138a3;p=sope added bodystructure fetches (v4.7.251) git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1526 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index a7be6b5e..1e78f727 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2007-08-01 Wolfgang Sourdeau + + * NGImap4: added support for bodystructure fetches (fixes OGo bug + #1892) (v4.7.251) + 2007-08-09 Wolfgang Sourdeau * NGMail: fixed some connection states in NGSmtpClient (OGo bug #1897) diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index 68ac3230..a276a69c 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,8 @@ +2007-08-01 Wolfgang Sourdeau + + * NGImap4ResponseParser.m: added support for bodystructure fetches + (fixes OGo bug #1892) + 2007-07-15 Helge Hess * NSString+Imap4.m: changed code to use -initWithData: as suggested in diff --git a/sope-mime/NGImap4/NGImap4ResponseParser.m b/sope-mime/NGImap4/NGImap4ResponseParser.m index 024211d8..5a069449 100644 --- a/sope-mime/NGImap4/NGImap4ResponseParser.m +++ b/sope-mime/NGImap4/NGImap4ResponseParser.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG This file is part of SOPE. @@ -77,17 +77,22 @@ static __inline__ BOOL _matchesString(NGImap4ResponseParser *self, return YES; } -static NSDictionary *_parseBody(NGImap4ResponseParser *self); +static NSDictionary *_parseBody(NGImap4ResponseParser *self, + BOOL isBodyStructure); +static NSDictionary *_parseSingleBody(NGImap4ResponseParser *self, + BOOL isBodyStructure); +static NSDictionary *_parseMultipartBody(NGImap4ResponseParser *self, + BOOL isBodyStructure); + static NSString *_parseBodyString(NGImap4ResponseParser *self, BOOL _convertString); static NSString *_parseBodyDecodeString(NGImap4ResponseParser *self, BOOL _convertString, BOOL _decode); static NSDictionary *_parseBodyParameterList(NGImap4ResponseParser *self); +static NSDictionary *_parseContentDisposition(NGImap4ResponseParser *self); static NSArray *_parseAddressStructure(NGImap4ResponseParser *self); static NSArray *_parseParenthesizedAddressList(NGImap4ResponseParser *self); -static NSDictionary *_parseSingleBody(NGImap4ResponseParser *self); -static NSDictionary *_parseMultipartBody(NGImap4ResponseParser *self); static int _parseTaggedResponse(NGImap4ResponseParser *self, NGMutableHashMap *result_); static void _parseUntaggedResponse(NGImap4ResponseParser *self, @@ -1386,7 +1391,10 @@ static BOOL _parseThreadResponse(NGImap4ResponseParser *self, [self logWithFormat:@"ERROR: got no body content for key: '%@'",key]; } else if ([key isEqualToString:@"body"]) { - [fetch setObject:_parseBody(self) forKey:key]; + [fetch setObject:_parseBody(self, NO) forKey:key]; + } + else if ([key isEqualToString:@"bodystructure"]) { + [fetch setObject:_parseBody(self, YES) forKey:key]; } else if ([key isEqualToString:@"flags"]) { [fetch setObject:_parseFlagArray(self) forKey:key]; @@ -1420,15 +1428,15 @@ static BOOL _parseThreadResponse(NGImap4ResponseParser *self, else [self logWithFormat:@"ERROR: could not parse envelope!"]; } - else if ([key isEqualToString:@"bodystructure"]) { - // TODO: implement! - NSException *e; +// else if ([key isEqualToString:@"bodystructure"]) { +// // TODO: implement! +// NSException *e; - e = [[NGImap4ParserException alloc] - initWithFormat:@"bodystructure fetch result not yet supported!"]; - [self setLastException:[e autorelease]]; - return NO; - } +// e = [[NGImap4ParserException alloc] +// initWithFormat:@"bodystructure fetch result not yet supported!"]; +// [self setLastException:[e autorelease]]; +// return NO; +// } else if ([key isEqualToString:@"internaldate"]) { // TODO: implement! NSException *e; @@ -1654,6 +1662,30 @@ static NSDictionary *_parseBodyParameterList(NGImap4ResponseParser *self) return list; } +static NSDictionary *_parseContentDisposition(NGImap4ResponseParser *self) +{ + NSMutableDictionary *disposition; + NSString *type; + + disposition = [NSMutableDictionary dictionary]; + + if (_la(self, 0) == '(') { + _consume(self, 1); + type = _parseBodyString(self, YES); + [disposition setObject: type forKey: @"type"]; + if (_la(self, 0) != ')') { + _consume(self, 1); + [disposition setObject: _parseBodyParameterList(self) + forKey: @"parameterList"]; + } + _consume(self, 1); + } + else + _parseBodyString(self, YES); + + return disposition; +} + static NSArray *_parseAddressStructure(NGImap4ResponseParser *self) { NSString *personalName, *sourceRoute, *mailboxName, *hostName; @@ -1696,9 +1728,10 @@ static NSArray *_parseParenthesizedAddressList(NGImap4ResponseParser *self) { return result; } -static NSDictionary *_parseSingleBody(NGImap4ResponseParser *self) { +static NSDictionary *_parseSingleBody(NGImap4ResponseParser *self, + BOOL isBodyStructure) { NSString *type, *subtype, *bodyId, *description, - *encoding, *bodysize; + *encoding, *bodysize; NSDictionary *parameterList; NSMutableDictionary *dict; @@ -1755,41 +1788,103 @@ static NSDictionary *_parseSingleBody(NGImap4ResponseParser *self) { [dict setObject:_parseBodyString(self, YES) forKey:@"messageId"]; _consumeIfMatch(self, ')'); _consumeIfMatch(self, ' '); - [dict setObject:_parseBody(self) forKey:@"body"]; + [dict setObject:_parseBody(self, isBodyStructure) forKey:@"body"]; _consumeIfMatch(self, ' '); [dict setObject:_parseBodyString(self, YES) forKey:@"bodyLines"]; } } + + if (isBodyStructure) { + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseBodyString(self, YES) + forKey: @"md5"]; + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseContentDisposition(self) + forKey: @"disposition"]; + if (_la(self, 0) != ')') { + _consume(self,1); + if (_la(self, 0) == '(') { + [dict setObject: _parseBodyParameterList(self) + forKey: @"language"]; + } + else { + [dict setObject: _parseBodyString(self, YES) + forKey: @"language"]; + } + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseBodyString(self, YES) + forKey: @"location"]; + }; + }; + }; + }; + } + return dict; } -static NSDictionary *_parseMultipartBody(NGImap4ResponseParser *self) { +static NSDictionary *_parseMultipartBody(NGImap4ResponseParser *self, + BOOL isBodyStructure) { NSMutableArray *parts; NSString *kind; + NSMutableDictionary *dict; parts = [NSMutableArray arrayWithCapacity:4]; while (_la(self, 0) == '(') { - [parts addObject:_parseBody(self)]; + [parts addObject:_parseBody(self, isBodyStructure)]; } _consumeIfMatch(self, ' '); kind = _parseBodyString(self, YES); - return [NSDictionary dictionaryWithObjectsAndKeys: - parts, @"parts", - @"multipart", @"type", - kind , @"subtype", nil]; + dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: + parts, @"parts", + @"multipart", @"type", + kind , @"subtype", nil]; + if (isBodyStructure) { + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseBodyParameterList(self) + forKey: @"parameterList"]; + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseContentDisposition(self) + forKey: @"disposition"]; + if (_la(self, 0) != ')') { + _consume(self,1); + if (_la(self, 0) == '(') { + [dict setObject: _parseBodyParameterList(self) + forKey: @"language"]; + } + else { + [dict setObject: _parseBodyString(self, YES) + forKey: @"language"]; + } + if (_la(self, 0) != ')') { + _consume(self,1); + [dict setObject: _parseBodyString(self, YES) + forKey: @"location"]; + }; + }; + }; + }; + } + + return dict; } -static NSDictionary *_parseBody(NGImap4ResponseParser *self) { +static NSDictionary *_parseBody(NGImap4ResponseParser *self, BOOL isBodyStructure) { NSDictionary *result; _consumeIfMatch(self, '('); if (_la(self, 0) == '(') { - result = _parseMultipartBody(self); + result = _parseMultipartBody(self, isBodyStructure); } else { - result = _parseSingleBody(self); + result = _parseSingleBody(self, isBodyStructure); } if (_la(self,0) != ')') { NSString *str; diff --git a/sope-mime/Version b/sope-mime/Version index 358da7ed..15a7ba97 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=7 -SUBMINOR_VERSION:=250 +SUBMINOR_VERSION:=251 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34