Updates for header folding support (to preserve exact white space).

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39300 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2016-01-21 12:49:15 +00:00
parent 5b574299e7
commit e85cffee31
4 changed files with 583 additions and 156 deletions

View file

@ -1,3 +1,16 @@
2016-01-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: Fix errors in conversion from a constant utf-8
string containing non-ascii characters to latin1 encoded data.
* Source/Additions/GSMime.m: Change line folding code to preserve
exact whitespace (using encoded words if necessary). Add support
for generating more readable 'q' encoded words rather than just
base64 encoded. Uses old behavior of folding with a tab character
if the GSMimeOldStyleFolding user default is set to YES, though
it's likely that this backward compatibility feature will be removed
in future.
2015-12-30 Marcus Mueller <znek@mulle-kybernetik.com>
* Source/NSNumberFormatter.m: fixed a subtle off-by-one formatter

File diff suppressed because it is too large Load diff

View file

@ -67,9 +67,15 @@ int main()
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSData *cr;
NSData *data;
NSData *orig;
NSString *str;
GSMimeParser *parser;
GSMimeDocument *doc;
GSMimeDocument *idoc;
BOOL oldStyleFolding;
oldStyleFolding = [[NSUserDefaults standardUserDefaults]
boolForKey: @"GSMimeOldStyleFolding"];
cr = [NSData dataWithBytes: "\r" length: 1];
@ -164,11 +170,20 @@ int main()
data = [NSData dataWithContentsOfFile: @"mime9.dat"];
idoc = exact(0, data);
PASS(([[[idoc headerNamed: @"Long"] value] isEqual: @"first second third"]),
if (YES == oldStyleFolding)
{
str = @"first second third";
}
else
{
str = @"first\tsecond\tthird";
}
PASS(([[[idoc headerNamed: @"Long"] value] isEqual: str]),
"mime9.dat folded header unfolds correctly incrementally");
doc = [GSMimeParser documentFromData: data];
//NSLog(@"'%@'", [[doc headerNamed: @"Long"] value]);
PASS(([[[doc headerNamed: @"Long"] value] isEqual: @"first second third"]),
PASS(([[[doc headerNamed: @"Long"] value] isEqual: str]),
"mime9.dat folded header unfolds correctly in one go");
PASS([idoc isEqual: doc], "mime9.dat documents are the same");
@ -194,22 +209,37 @@ int main()
/* Test a document with adjacent encoded words in headers, as
* produced by GSMime
*/
data = [NSData dataWithContentsOfFile: @"mime12.dat"];
idoc = exact(0, data);
orig = [NSData dataWithContentsOfFile: @"mime12.dat"];
idoc = exact(0, orig);
if (YES == oldStyleFolding)
{
str = @"Avant de partir, n'oubliez pas de préparer votre séjour à Paris";
}
else
{
str = @"Avant de partir, n'oubliez pas de préparer votre\tséjour à Paris";
}
doc = [GSMimeDocument documentWithContent: @"hello"
type: @"text/plain"
name: nil];
[doc setHeader: @"MIME-Version" value: @"1.0" parameters: nil];
[doc setHeader: @"Subject"
value: @"Avant de partir, n'oubliez pas de préparer votre séjour à Paris"
parameters: nil];
[doc setHeader: @"Subject" value: str parameters: nil];
PASS_EQUAL(idoc, doc, "mime12.dat same as internally generated content");
doc = [GSMimeParser documentFromData: data];
doc = [GSMimeParser documentFromData: orig];
PASS_EQUAL(idoc, doc, "mime12.dat documents are the same");
data = [idoc rawMimeData];
doc = [GSMimeParser documentFromData: data];
PASS_EQUAL(idoc, doc, "rawMimeData reproduces document");
NSLog(@"Got %@", [doc rawMimeData]);
PASS_EQUAL(idoc, doc, "rawMimeData reproduces document with 'q' header");
NSLog(@"Made\n%@\nOrig\n%@", data, orig);
if (NO == oldStyleFolding)
{
[idoc setHeader: @"Subject" value: @"==répà==" parameters: nil];
data = [idoc rawMimeData];
NSLog(@"Made\n%@", data);
doc = [GSMimeParser documentFromData: data];
PASS_EQUAL(doc, idoc, "rawMimeData reproduces document with 'b' header");
}
[arp release]; arp = nil;
return 0;

View file

@ -86,12 +86,19 @@ int main()
[doc rawMimeData];
PASS([[[doc headerNamed:@"content-type"] parameterForKey:@"charset"] isEqual:@"utf-8"],"charset is inferred");
val = @"by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF; Sat, 22 Dec 2007 15:40:10 +0100 (CET)";
raw = @"Received: by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF;\r\n\tSat, 22 Dec 2007 15:40:10 +0100 (CET)\r\n";
if ([[NSUserDefaults standardUserDefaults]
boolForKey: @"GSMimeOldStyleFolding"] == YES)
{
raw = @"Received: by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF;\r\n\tSat, 22 Dec 2007 15:40:10 +0100 (CET)\r\n";
}
else
{
raw = @"Received: by mail.turbocat.net (Postfix, from userid 1002) id 90885422ECBF;\r\n Sat, 22 Dec 2007 15:40:10 +0100 (CET)\r\n";
}
hdr = [[GSMimeHeader alloc] initWithName: @"Received" value: val];
data = [hdr rawMimeDataPreservingCase: YES];
//NSLog(@"Header: '%*.*s'", [data length], [data length], [data bytes]);
// NSLog(@"Header: '%*.*s'", [data length], [data length], [data bytes]);
PASS([data isEqual: [raw dataUsingEncoding: NSASCIIStringEncoding]],
"raw mime data for long header is OK");