diff --git a/ChangeLog b/ChangeLog index 2ef06c69b..9bf8adb05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-08-23 Richard Frith-Macdonald + + * Source/Additions/GSMime.m: Add content location methods. + 2004-08-22 Richard Frith-Macdonald * Source/NSString.m: Various minor optimisations ... uppercaseString diff --git a/Headers/Additions/GNUstepBase/GSMime.h b/Headers/Additions/GNUstepBase/GSMime.h index d164a41e8..164ef945f 100644 --- a/Headers/Additions/GNUstepBase/GSMime.h +++ b/Headers/Additions/GNUstepBase/GSMime.h @@ -113,10 +113,12 @@ - (NSArray*) allHeaders; - (id) content; - (id) contentByID: (NSString*)key; +- (id) contentByLocation: (NSString*)key; - (id) contentByName: (NSString*)key; - (id) copyWithZone: (NSZone*)z; - (NSString*) contentFile; - (NSString*) contentID; +- (NSString*) contentLocation; - (NSString*) contentName; - (NSString*) contentSubtype; - (NSString*) contentType; diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index ceb463bfd..366116577 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -60,6 +60,7 @@ static NSCharacterSet *whitespace = nil; static NSCharacterSet *rfc822Specials = nil; static NSCharacterSet *rfc2045Specials = nil; +static Class NSArrayClass = 0; /* * Name - decodebase64() @@ -652,6 +653,14 @@ wordData(NSString *word) return AUTORELEASE(newDocument); } ++ (void) initialize +{ + if (NSArrayClass == 0) + { + NSArrayClass = [NSArray class]; + } +} + /** * Create and return a parser. */ @@ -2635,6 +2644,10 @@ static NSCharacterSet *tokenSet = nil; tokenSet = [ms copy]; RELEASE(ms); nonToken = RETAIN([tokenSet invertedSet]); + if (NSArrayClass == 0) + { + NSArrayClass = [NSArray class]; + } } } @@ -3379,6 +3392,10 @@ static NSCharacterSet *tokenSet = nil; [m removeCharactersInString: @"."]; rfc2045Specials = [m copy]; whitespace = RETAIN([NSCharacterSet whitespaceAndNewlineCharacterSet]); + if (NSArrayClass == 0) + { + NSArrayClass = [NSArray class]; + } } } @@ -3543,7 +3560,7 @@ static NSCharacterSet *tokenSet = nil; { key = [NSString stringWithFormat: @"<%@>", key]; } - if ([content isKindOfClass: [NSArray class]] == YES) + if ([content isKindOfClass: NSArrayClass] == YES) { NSEnumerator *e = [content objectEnumerator]; GSMimeDocument *d; @@ -3564,6 +3581,35 @@ static NSCharacterSet *tokenSet = nil; return nil; } +/** + * Search the content of this document to locate a part whose content ID + * matches the specified key. Recursively descend into other documents.
+ * Wraps the supplied key in angle brackets if they are not present.
+ * Return nil if no match is found, the matching GSMimeDocument otherwise. + */ +- (id) contentByLocation: (NSString*)key +{ + if ([content isKindOfClass: NSArrayClass] == YES) + { + NSEnumerator *e = [content objectEnumerator]; + GSMimeDocument *d; + + while ((d = [e nextObject]) != nil) + { + if ([[d contentLocation] isEqualToString: key] == YES) + { + return d; + } + d = [d contentByLocation: key]; + if (d != nil) + { + return d; + } + } + } + return nil; +} + /** * Search the content of this document to locate a part whose content-type * name or content-disposition name matches the specified key. @@ -3573,7 +3619,7 @@ static NSCharacterSet *tokenSet = nil; - (id) contentByName: (NSString*)key { - if ([content isKindOfClass: [NSArray class]] == YES) + if ([content isKindOfClass: NSArrayClass] == YES) { NSEnumerator *e = [content objectEnumerator]; GSMimeDocument *d; @@ -3622,6 +3668,16 @@ static NSCharacterSet *tokenSet = nil; return [hdr value]; } +/** + * Convenience method to fetch the content location from the header. + */ +- (NSString*) contentLocation +{ + GSMimeHeader *hdr = [self headerNamed: @"content-location"]; + + return [hdr value]; +} + /** * Convenience method to fetch the content name from the header. */ @@ -3716,7 +3772,7 @@ static NSCharacterSet *tokenSet = nil; { NSMutableArray *a = nil; - if ([content isKindOfClass: [NSArray class]] == YES) + if ([content isKindOfClass: NSArrayClass] == YES) { NSEnumerator *e = [content objectEnumerator]; GSMimeDocument *d; @@ -3816,7 +3872,7 @@ static NSCharacterSet *tokenSet = nil; c->headers = [[NSMutableArray allocWithZone: z] initWithArray: headers copyItems: YES]; - if ([content isKindOfClass: [NSArray class]] == YES) + if ([content isKindOfClass: NSArrayClass] == YES) { c->content = [[NSMutableArray allocWithZone: z] initWithArray: content copyItems: YES]; @@ -4123,7 +4179,7 @@ static NSCharacterSet *tokenSet = nil; } } - if ([content isKindOfClass: [NSArray class]] == YES) + if ([content isKindOfClass: NSArrayClass] == YES) { count = [content count]; partData = [NSMutableArray arrayWithCapacity: count]; @@ -4540,7 +4596,7 @@ static NSCharacterSet *tokenSet = nil; ASSIGNCOPY(content, newContent); } } - else if ([newContent isKindOfClass: [NSArray class]] == YES) + else if ([newContent isKindOfClass: NSArrayClass] == YES) { if (newContent != content) { @@ -4670,7 +4726,7 @@ static NSCharacterSet *tokenSet = nil; if ([type isEqualToString: @"multipart"] == NO && [type isEqualToString: @"application"] == NO - && [content isKindOfClass: [NSArray class]] == YES) + && [content isKindOfClass: NSArrayClass] == YES) { [NSException raise: NSInvalidArgumentException format: @"[%@ -%@] content doesn't match content-type", diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index ee4b81536..32c4faf63 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -1027,7 +1027,6 @@ GSPropertyListFromStringsFormat(NSString *string) NSMutableDictionary *dict; pldata _pld; pldata *pld = &_pld; - unsigned length; NSData *d; /*