We are developing a simple usenet reader for iOS5 implementing the NNTP protocol.
Unfortunately we have some problem with the encoding: A header may look like:
Subject: Re: [GA] =?ISO-8859-15?Q?Pr=FCfungsmodus?=
Date: 22 Apr 2012 22:50:38 +0200
Is there some simple way in Objective-C to convert a NSString containing =?ISO-8859-15?Q?Pr=FCfungsmodus?= to “Prüfungsmodus“?
Thanks
EDIT:
Hm. I’m not sure if I got this right:
You meant something like:
NSRange range = [input rangeOfString:@"=?"];
NSRange range2 = [input rangeOfString:@"?="];
NSString *string_to_decode = [input substringWithRange:NSMakeRange(range.location, range2.location-(range.location-2))];
NSData *data = [string_to_decode dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES];
NSString *converted = [[NSString alloc] initWithData:data encoding:(NSISOLatin1StringEncoding)];
Because that’s not working..
EDIT2
Trying to convert the raw bytes:
uint8_t buffer[1024];
iStream read:buffer maxLength:sizeof(buffer)
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSISOLatin1StringEncoding];
No matter which encoding I choose here the Subject: Field will always look the same (except for japanese etc encoding…)
If you are doing this yourself from first principles then in outline:
create an
NSStringfor each using- (id)initWithBytes:(const void *)bytes length:(NSUInteger)length encoding:(NSStringEncoding)encodingconcatenate
=?For details on MIME look at Wikipedia.
[Edit: added notes on MIME.]