}
- (BOOL)_parseNumberUntaggedResponse:(NGMutableHashMap *)result_ {
+ NSMutableDictionary *fetch;
NSNumber *number;
NSString *key = nil;
return NO;
_consumeIfMatch(self, ' ');
+
+ if (!_matchesString(self, "FETCH ")) {
+ /* got a number request from select like exists or recent */
+ key = _parseUntil(self, '\n');
+ [result_ addObject:number forKey:[key lowercaseString]];
+ return YES;
+ }
- if (_matchesString(self, "FETCH ")) {
- /* eg: "FETCH (FLAGS (\Seen) UID 5 RFC822.HEADER {2903}" */
- NSMutableDictionary *fetch;
-
- fetch = [[NSMutableDictionary alloc] initWithCapacity:10];
+ /* eg: "FETCH (FLAGS (\Seen) UID 5 RFC822.HEADER {2903}" */
+ fetch = [[NSMutableDictionary alloc] initWithCapacity:10];
- _consume(self, 6); /* "FETCH " */
- _consumeIfMatch(self, '(');
- while (_la(self, 0) != ')') { /* until closing parent */
- NSString *key;
+ _consume(self, 6); /* "FETCH " */
+ _consumeIfMatch(self, '(');
+ while (_la(self, 0) != ')') { /* until closing parent */
+ NSString *key;
- key = [_parseUntil(self, ' ') lowercaseString];
+ key = [_parseUntil(self, ' ') lowercaseString];
#if 0
- [self logWithFormat:@"PARSE KEY: %@", key];
+ [self logWithFormat:@"PARSE KEY: %@", key];
#endif
- if ([key hasPrefix:@"body["]) {
- NSDictionary *content;
+ if ([key hasPrefix:@"body["]) {
+ NSDictionary *content;
- if ((content = [self _parseBodyContent]) != nil)
- [fetch setObject:content forKey:key];
- else
- [self logWithFormat:@"ERROR: got no body content for key: '%@'",key];
- }
- else if ([key isEqualToString:@"body"]) {
- [fetch setObject:_parseBody(self) forKey:key];
- }
- else if ([key isEqualToString:@"flags"]) {
- [fetch setObject:_parseFlagArray(self) forKey:key];
- }
- else if ([key isEqualToString:@"uid"]) {
- [fetch setObject:_parseUnsigned(self) forKey:key];
- }
- else if ([key isEqualToString:@"rfc822.size"]) {
- [fetch setObject:_parseUnsigned(self) forKey:key];
- }
- else if ([key hasPrefix:@"rfc822"]) {
- NSData *data;
-
- if (_la(self, 0) == '"') {
- NSString *str;
- _consume(self,1);
-
- str = _parseUntil(self, '"');
- data = [str dataUsingEncoding:defCStringEncoding];
- }
- else
- data = [self _parseData];
+ if ((content = [self _parseBodyContent]) != nil)
+ [fetch setObject:content forKey:key];
+ else
+ [self logWithFormat:@"ERROR: got no body content for key: '%@'",key];
+ }
+ else if ([key isEqualToString:@"body"]) {
+ [fetch setObject:_parseBody(self) forKey:key];
+ }
+ else if ([key isEqualToString:@"flags"]) {
+ [fetch setObject:_parseFlagArray(self) forKey:key];
+ }
+ else if ([key isEqualToString:@"uid"]) {
+ [fetch setObject:_parseUnsigned(self) forKey:key];
+ }
+ else if ([key isEqualToString:@"rfc822.size"]) {
+ [fetch setObject:_parseUnsigned(self) forKey:key];
+ }
+ else if ([key hasPrefix:@"rfc822"]) {
+ NSData *data;
+
+ if (_la(self, 0) == '"') {
+ NSString *str;
+ _consume(self,1);
- if (data != nil) [fetch setObject:data forKey:key];
+ str = _parseUntil(self, '"');
+ data = [str dataUsingEncoding:defCStringEncoding];
}
- else if ([key isEqualToString:@"envelope"]) {
- id envelope;
+ else
+ data = [self _parseData];
- if ((envelope = [self _parseEnvelope]) != nil)
- [fetch setObject:envelope forKey:key];
- else
- [self logWithFormat:@"ERROR: could not parse envelope!"];
- }
- else {
- NSException *e;
-
- e = [[NGImap4ParserException alloc] initWithFormat:
- @"unsupported fetch key: %@",
- key];
- [self setLastException:[e autorelease]];
- return NO;
- }
- if (_la(self, 0) == ' ')
- _consume(self, 1);
+ if (data != nil) [fetch setObject:data forKey:key];
}
- if (fetch != nil) {
- [fetch setObject:number forKey:@"msn"];
- [result_ addObject:fetch forKey:@"fetch"];
- _consume(self, 1); /* consume ')' */
- _consumeIfMatch(self, '\n');
+ else if ([key isEqualToString:@"envelope"]) {
+ id envelope;
+
+ if ((envelope = [self _parseEnvelope]) != nil)
+ [fetch setObject:envelope forKey:key];
+ else
+ [self logWithFormat:@"ERROR: could not parse envelope!"];
}
- else { /* no correct fetch line */
- _parseUntil(self, '\n');
+ else if ([key isEqualToString:@"bodystructure"]) {
+ // TODO: implement!
+ NSException *e;
+
+ e = [[NGImap4ParserException alloc]
+ initWithFormat:@"bodystructure not yet supported!"];
+ [self setLastException:[e autorelease]];
+ return NO;
+ }
+ else {
+ NSException *e;
+
+ e = [[NGImap4ParserException alloc] initWithFormat:
+ @"unsupported fetch key: %@",
+ key];
+ [self setLastException:[e autorelease]];
+ return NO;
}
- [fetch release]; fetch = nil;
- return YES;
+ if (_la(self, 0) == ' ')
+ _consume(self, 1);
}
-
- { /* got a number request from select like exists or recent */
- key = _parseUntil(self, '\n');
- [result_ addObject:number forKey:[key lowercaseString]];
+ if (fetch != nil) {
+ [fetch setObject:number forKey:@"msn"];
+ [result_ addObject:fetch forKey:@"fetch"];
+ _consume(self, 1); /* consume ')' */
+ _consumeIfMatch(self, '\n');
+ }
+ else { /* no correct fetch line */
+ _parseUntil(self, '\n');
}
+
+ [fetch release]; fetch = nil;
return YES;
-}
+ }
static BOOL _parseGreetingsSieveResponse(NGImap4ResponseParser *self,
NGMutableHashMap *result_)