Add method for getting all contents with specified name.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13743 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-05-31 09:02:39 +00:00
parent 3ae2273e0d
commit efc01e96e6
2 changed files with 44 additions and 0 deletions

View file

@ -97,6 +97,7 @@
- (NSString*) contentName;
- (NSString*) contentSubType;
- (NSString*) contentType;
- (NSArray*) contentsByName: (NSString*)key;
- (NSData*) convertToData;
- (NSString*) convertToText;
- (void) deleteHeader: (GSMimeHeader*)aHeader;

View file

@ -2884,6 +2884,49 @@ static NSCharacterSet *tokenSet = nil;
return [hdr objectForKey: @"Type"];
}
/**
* Search the content of this document to locate all parts whose content-type
* name or content-disposition name matches the specified key.
* Do <em>NOT</em> recurse into other documents.<br />
* Return nil if no match is found, an array of matching GSMimeDocument
* instances otherwise.
*/
- (NSArray*) contentsByName: (NSString*)key
{
NSMutableArray *a = nil;
if ([content isKindOfClass: [NSArray class]] == YES)
{
NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d;
while ((d = [e nextObject]) != nil)
{
GSMimeHeader *hdr;
BOOL match = YES;
hdr = [d headerNamed: @"content-type"];
if ([[hdr parameterForKey: @"name"] isEqualToString: key] == NO)
{
hdr = [d headerNamed: @"content-disposition"];
if ([[hdr parameterForKey: @"name"] isEqualToString: key] == NO)
{
match = NO;
}
}
if (match == YES)
{
if (a == nil)
{
a = [NSMutableArray arrayWithCapacity: 4];
}
[a addObject: d];
}
}
}
return a;
}
/**
* Return the content as an NSData object (unless it is multipart)
*/