Added convenience methods.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21754 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-09-28 09:47:31 +00:00
parent 460d4a3e88
commit b6677d38d1
3 changed files with 67 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2005-09-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSMime.m: (-convertToBinary, -convertToBase64)
new convenience methods for making documents comapct or 7bit safe.
2005-09-25 David Ayers <d.ayers@inode.at>
* Testing/benchmark.m: Add some NSMapTable tests.

View file

@ -123,6 +123,8 @@
- (NSString*) contentSubtype;
- (NSString*) contentType;
- (NSArray*) contentsByName: (NSString*)key;
- (void) convertToBase64;
- (void) convertToBinary;
- (NSData*) convertToData;
- (NSString*) convertToText;
- (void) deleteContent: (GSMimeDocument*)aPart;

View file

@ -4134,6 +4134,66 @@ static NSCharacterSet *tokenSet = nil;
return a;
}
/**
* Converts any binary parts of the receiver's content to be base64
* encoded rather than 8bit or binary encoded ... a convenience method to
* make the results of the -rawMimeData method safe for sending via
* routes which only support 7bit data.
*/
- (void) convertToBase64
{
if ([content isKindOfClass: NSArrayClass] == YES)
{
NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d;
while ((d = [e nextObject]) != nil)
{
[d convertToBase64];
}
}
else
{
GSMimeHeader *h = [self headerNamed: @"content-transfer-encoding"];
NSString *v = [h value];
if ([v isEqual: @"binary"] == YES || [v isEqual: @"8bit"] == YES)
{
[h setValue: @"base64"];
}
}
}
/**
* Converts any base64 encoded parts of the receiver's content to be
* binary encoded instead ... a convenience method to
* shrink down the size of the message when converted to data using
* the -rawMimeData method.
*/
- (void) convertToBinary
{
if ([content isKindOfClass: NSArrayClass] == YES)
{
NSEnumerator *e = [content objectEnumerator];
GSMimeDocument *d;
while ((d = [e nextObject]) != nil)
{
[d convertToBinary];
}
}
else
{
GSMimeHeader *h = [self headerNamed: @"content-transfer-encoding"];
NSString *v = [h value];
if ([v isEqual: @"base64"] == YES)
{
[h setValue: @"binary"];
}
}
}
/**
* Return the content as an NSData object (unless it is multipart)<br />
* Perform conversion from text to data using the charset specified in