From: helge Date: Sat, 2 Oct 2004 00:41:20 +0000 (+0000) Subject: fixed parsing of long subjects X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b02b3694e031ee337c4d59fb5160804f513d430;p=sope fixed parsing of long subjects git-svn-id: http://svn.opengroupware.org/SOPE/trunk@213 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 78965794..737d468c 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,5 +1,7 @@ 2004-10-02 Helge Hess + * NGImap4: fixed long subject envelope processing (v4.3.186) + * NGImap4: improved processing of envelope responses (v4.3.185) 2004-10-01 Helge Hess diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index eb060bac..b3bf7ba5 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,5 +1,8 @@ 2004-10-02 Helge Hess + * NGImap4ResponseParser.m: support data-style subjects in envelopes + (v4.3.186) + * NGImap4ResponseNormalizer.m: pass on envelope raw responses in normalized responses (v4.3.185) diff --git a/sope-mime/NGImap4/NGImap4Envelope.h b/sope-mime/NGImap4/NGImap4Envelope.h index e44bf914..8a0e5ea2 100644 --- a/sope-mime/NGImap4/NGImap4Envelope.h +++ b/sope-mime/NGImap4/NGImap4Envelope.h @@ -37,7 +37,7 @@ { @public NSCalendarDate *date; - NSString *subject; + id subject; /* can be either NSData or NSString */ NSString *inReplyTo; NSString *msgId; NGImap4EnvelopeAddress *from; @@ -51,7 +51,7 @@ /* accessors */ - (NSCalendarDate *)date; -- (NSString *)subject; +- (id)subject; - (NSString *)inReplyTo; - (NSString *)messageID; - (NGImap4EnvelopeAddress *)from; diff --git a/sope-mime/NGImap4/NGImap4Envelope.m b/sope-mime/NGImap4/NGImap4Envelope.m index 8e2bb082..cbeb1690 100644 --- a/sope-mime/NGImap4/NGImap4Envelope.m +++ b/sope-mime/NGImap4/NGImap4Envelope.m @@ -44,7 +44,7 @@ - (NSCalendarDate *)date { return self->date; } -- (NSString *)subject { +- (id)subject { return self->subject; } - (NSString *)inReplyTo { diff --git a/sope-mime/NGImap4/NGImap4ResponseParser.m b/sope-mime/NGImap4/NGImap4ResponseParser.m index c03db7bd..05f7b90a 100644 --- a/sope-mime/NGImap4/NGImap4ResponseParser.m +++ b/sope-mime/NGImap4/NGImap4ResponseParser.m @@ -146,6 +146,7 @@ static NSNull *null = nil; defCStringEncoding = [NSString defaultCStringEncoding]; debugOn = [ud boolForKey:@"ImapDebugEnabled"]; + debugDataOn = [ud boolForKey:@"ImapDebugDataEnabled"]; UseMemoryMappedData = [ud boolForKey:@"NoMemoryMappedDataForImapBlobs"]?0:1; Imap4MMDataBoundary = [ud integerForKey:@"Imap4MMDataBoundary"]; @@ -452,7 +453,7 @@ static void _parseSieveRespone(NGImap4ResponseParser *self, /* got header */ result = nil; - _consume(self, 1); + _consume(self, 1); // '{' if ((sizeNum = _parseUnsigned(self)) == nil) { NSException *e; @@ -624,10 +625,11 @@ static void _parseUntaggedResponse(NGImap4ResponseParser *self, - (NSString *)_parseQuotedString { /* parse a quoted string, eg '"' */ - if (_la(self, 0) != '"') - return nil; - _consume(self, 1); - return _parseUntil(self, '"'); + if (_la(self, 0) == '"') { + _consume(self, 1); + return _parseUntil(self, '"'); + } + return nil; } - (void)_consumeOptionalSpace { if (_la(self, 0) == ' ') _consume(self, 1); @@ -948,9 +950,21 @@ static BOOL _parseThreadResponse(NGImap4ResponseParser *self, return YES; } -- (id)_parseQuotedStringOrNIL { +- (NSString *)_parseQuotedStringOrNIL { if (_la(self, 0) == '"') return [self _parseQuotedString]; + if (_matchesString(self, "NIL")) { + _consume(self, 3); + return (id)null; + } + return nil; +} +- (id)_parseQuotedStringOrDataOrNIL { + if (_la(self, 0) == '"') + return [self _parseQuotedString]; + if (_la(self, 0) == '{') + return [self _parseData]; + if (_matchesString(self, "NIL")) { _consume(self, 3); return null; @@ -1078,41 +1092,72 @@ static BOOL _parseThreadResponse(NGImap4ResponseParser *self, /* parse subject */ - if ((tmp = [self _parseQuotedStringOrNIL])) + if ((tmp = [self _parseQuotedStringOrDataOrNIL])) { + // TODO: that one is an issue, the client does know the requested charset + // but doesn't pass it down to the parser? Requiring the client to + // deal with NSData's is a bit overkill? env->subject = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; - + [self _consumeOptionalSpace]; + } + else { + [self logWithFormat:@"ERROR(%s): failed on subject(%c): %@", + __PRETTY_FUNCTION__, _la(self, 0), self->serverResponseDebug]; + return nil; + } + [self logWithFormat:@"XX2: %c %@", _la(self, 0), self->serverResponseDebug]; + /* parse addresses */ - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->from = [tmp isNotNull] ? [[tmp lastObject] copy] : nil; - [self _consumeOptionalSpace]; - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + [self _consumeOptionalSpace]; + } + else { + [self logWithFormat:@"ERROR(%s): failed on from.", __PRETTY_FUNCTION__]; + return nil; + } + [self logWithFormat:@"XX3: %c %@", _la(self, 0), self->serverResponseDebug]; + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->sender = [tmp isNotNull] ? [[tmp lastObject] copy] : nil; - [self _consumeOptionalSpace]; - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + [self _consumeOptionalSpace]; + } + else { + [self logWithFormat:@"ERROR(%s): failed on sender.", __PRETTY_FUNCTION__]; + return nil; + } + [self logWithFormat:@"XX3: %c %@", _la(self, 0), self->serverResponseDebug]; + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->replyTo = [tmp isNotNull] ? [[tmp lastObject] copy] : nil; - [self _consumeOptionalSpace]; + [self _consumeOptionalSpace]; + } - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->to = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + [self _consumeOptionalSpace]; + } + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->cc = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; - if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) + [self _consumeOptionalSpace]; + } + if ((tmp = [self _parseEnvelopeAddressStructures]) != nil) { env->bcc = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; - - if ((tmp = [self _parseQuotedStringOrNIL])) + [self _consumeOptionalSpace]; + } + + if ((tmp = [self _parseQuotedStringOrNIL])) { env->inReplyTo = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; - if ((tmp = [self _parseQuotedStringOrNIL])) + [self _consumeOptionalSpace]; + } + if ((tmp = [self _parseQuotedStringOrNIL])) { env->msgId = [tmp isNotNull] ? [tmp copy] : nil; - [self _consumeOptionalSpace]; + [self _consumeOptionalSpace]; + } - if (_la(self, 0) != ')') - [self logWithFormat:@"WARNING: IMAP4 envelope not properly closed!"]; + if (_la(self, 0) != ')') { + [self logWithFormat:@"WARNING: IMAP4 envelope not properly closed" + @" (c0=%c,c1=%c): %@", + _la(self, 0), _la(self, 1), self->serverResponseDebug]; + } else _consume(self, 1); @@ -1137,9 +1182,10 @@ static BOOL _parseThreadResponse(NGImap4ResponseParser *self, _consume(self, 6); /* "FETCH " */ _consumeIfMatch(self, '('); while (_la(self, 0) != ')') { /* until closing parent */ - NSString *key = nil; + NSString *key; key = [_parseUntil(self, ' ') lowercaseString]; + [self logWithFormat:@"PARSE KEY: %@", key]; if ([key hasPrefix:@"body["]) { NSDictionary *content; @@ -1735,7 +1781,7 @@ static NSNumber *_parseUnsigned(NGImap4ResponseParser *self) { static NSString *_parseUntil(NGImap4ResponseParser *self, char _c) { /* - _parseUntil(self, char) consume the stop char + Note: this function consumes the stop char (_c)! normalize \r\n constructions */ // TODO: optimize! @@ -1750,9 +1796,10 @@ static NSString *_parseUntil(NGImap4ResponseParser *self, char _c) { _consume(self, 1); cnt++; if (cnt == 1024) { - if (str == nil) + if (str == nil) { str = (NSMutableString *) [NSMutableString stringWithCString:buf length:1024]; + } else { NSString *s; diff --git a/sope-mime/Version b/sope-mime/Version index 79942484..9033d0e8 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,6 +2,6 @@ MAJOR_VERSION:=4 MINOR_VERSION:=3 -SUBMINOR_VERSION:=185 +SUBMINOR_VERSION:=186 # v4.2.149 requires libNGStreams v4.2.34