diff --git a/ChangeLog b/ChangeLog index 6c7c29203..acefbfbc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-10-07 Richard Frith-Macdonald + + * Source/Additions/GSMime.m: ([GSMimeDocument-setContentType:]) + New convenience method. + 2003-10-05 Adam Fedor * Documentation/GNUmakefile: Make manual diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index f776e5418..e824d7e72 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -4412,6 +4412,31 @@ static NSCharacterSet *tokenSet = nil; RELEASE(arp); } +/** + *

Convenience method to set the content type of the document without + * altering any content. + * The supplied newType may be full type information including subtype + * and parameters as found after the colon in a mime Content-Type header. + *

+ */ +- (void) setContentType: (id)newType +{ + CREATE_AUTORELEASE_POOL(arp); + GSMimeHeader *hdr = nil; + GSMimeParser *p = AUTORELEASE([GSMimeParser new]); + NSScanner *scanner = [NSScanner scannerWithString: newType]; + + hdr = AUTORELEASE([GSMimeHeader new]); + [hdr setName: @"content-type"]; + if ([p scanHeaderBody: scanner into: hdr] == NO) + { + [NSException raise: NSInvalidArgumentException + format: @"Unable to parse type information"]; + } + [self setHeader: hdr]; + RELEASE(arp); +} + /** * This method may be called to set a header in the document. * Any other headers with the same name will be removed from