Author: rfm
Date: Tue Mar 11 10:46:54 2014
New Revision: 37740
URL: http://svn.gna.org/viewcvs/gnustep?rev=37740&view=rev
Log:
fixup for encoded words
Added:
libs/base/trunk/Tests/base/GSMime/mime12.dat
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/Additions/GSMime.m
libs/base/trunk/Tests/base/GSMime/general.m
libs/base/trunk/Tests/base/GSMime/test01.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=37740&r1=37739&r2=37740&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Tue Mar 11 10:46:54 2014
@@ -1,16 +1,24 @@
+2014-03-11 Richard Frith-Macdonald <[email protected]>
+
+ * Source/Additions/GSMime.m:
+ When generating document with a header containing adjacent non-ascii
+ words which need to be encoded, omit the space between those words
+ for consistency with the change on Fe 3rd.
+
2014-02-18 Fred Kiefer <[email protected]>
* Source/NSDateFormatter.m
(-initWithDateFormat:allowNaturalLanguage:):
Use method -setDateFormat: to get correct behaviour.
- * Source/NSDateFormatter.m (-setDateFormat:): User ASSIGNCOPY for
_dateFormat.
+ * Source/NSDateFormatter.m (-setDateFormat:):
+ Use ASSIGNCOPY for _dateFormat.
2014-02-14 Quentin Mathe <[email protected]>
* Headers/Foundation/NSNotification.h
* Source/NSNotificationCenter.m
- (-addObserverForName:selector:queue:usingBlock:): Added new Mac OS X
10.6
- method.
+ (-addObserverForName:selector:queue:usingBlock:):
+ Added new Mac OS X 10.6 method.
2014-02-14 Quentin Mathe <[email protected]>
Modified: libs/base/trunk/Source/Additions/GSMime.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/Additions/GSMime.m?rev=37740&r1=37739&r2=37740&view=diff
==============================================================================
--- libs/base/trunk/Source/Additions/GSMime.m (original)
+++ libs/base/trunk/Source/Additions/GSMime.m Tue Mar 11 10:46:54 2014
@@ -509,7 +509,7 @@
* For an ascii word, we just return the data.
*/
static NSData*
-wordData(NSString *word)
+wordData(NSString *word, BOOL *encoded)
{
NSData *d = nil;
NSString *charset;
@@ -517,6 +517,7 @@
charset = selectCharacterSet(word, &d);
if ([charset isEqualToString: @"us-ascii"] == YES)
{
+ *encoded = NO;
return d;
}
else
@@ -525,6 +526,7 @@
char buf[len + 1];
NSMutableData *md;
+ *encoded = YES;
[charset getCString: buf
maxLength: len + 1
encoding: NSISOLatin1StringEncoding];
@@ -3734,13 +3736,18 @@
appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
NSString *str, BOOL *ok)
{
- NSUInteger pos = 0;
- NSUInteger size = [str length];
+ NSUInteger pos = 0;
+ NSUInteger size = [str length];
+ BOOL hadEncodedWord = NO;
+ BOOL needSpace = NO;
*ok = YES;
while (pos < size)
{
NSRange r = NSMakeRange(pos, size - pos);
+ NSString *s = nil;
+ NSData *d = nil;
+ BOOL e = NO;
r = [str rangeOfCharacterFromSet: whitespace
options: NSLiteralSearch
@@ -3749,7 +3756,7 @@
{
/* Found space at the start of the string, so we reduce
* it to a single space in the output, or omit it entirely
- * if the string is nothing but space.
+ * if the string is contains nothing more but space.
*/
pos++;
while (pos < size
@@ -3759,37 +3766,60 @@
}
if (pos < size)
{
- offset = appendBytes(m, offset, fold, " ", 1);
+ needSpace = YES; // We need a space before the next word.
}
}
else if (r.length == 0)
{
- NSString *sub;
- NSData *d;
-
- /* No space found ... we must output the entire string without
- * folding it.
+ /* No more space found ... we must output the remaining string
+ * without folding it.
*/
- sub = [str substringWithRange: NSMakeRange(pos, size - pos)];
+ s = [str substringWithRange: NSMakeRange(pos, size - pos)];
pos = size;
- d = wordData(sub);
- offset = appendBytes(m, offset, fold, [d bytes], [d length]);
+ d = wordData(s, &e);
}
else
{
- NSString *sub;
- NSData *d;
-
- /* Output the substring up to the first space.
+ /* Output the substring up to the next space.
*/
- sub = [str substringWithRange: NSMakeRange(pos, r.location - pos)];
+ s = [str substringWithRange: NSMakeRange(pos, r.location - pos)];
pos = r.location;
- d = wordData(sub);
+ d = wordData(s, &e);
+ }
+ if (nil != d)
+ {
+ /* We have a 'word' to output ... do that after dealing with any
+ * space needede between the last word and the new one.
+ */
+ if (YES == needSpace)
+ {
+ if (YES == e && YES == hadEncodedWord)
+ {
+ /* We can't have space between two encoded words, so
+ * we incorporate the space at the start of the next
+ * encoded word.
+ */
+ s = [@" " stringByAppendingString: s];
+ d = wordData(s, &e);
+ }
+ else
+ {
+ /* Add the needed space before the next word.
+ */
+ offset = appendBytes(m, offset, fold, " ", 1);
+ if (fold > 0 && offset > fold)
+ {
+ *ok = NO;
+ }
+ }
+ needSpace = NO;
+ }
+ hadEncodedWord = e;
offset = appendBytes(m, offset, fold, [d bytes], [d length]);
- }
- if (fold > 0 && offset > fold)
- {
- *ok = NO;
+ if (fold > 0 && offset > fold)
+ {
+ *ok = NO;
+ }
}
}
return offset;
Modified: libs/base/trunk/Tests/base/GSMime/general.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/GSMime/general.m?rev=37740&r1=37739&r2=37740&view=diff
==============================================================================
--- libs/base/trunk/Tests/base/GSMime/general.m (original)
+++ libs/base/trunk/Tests/base/GSMime/general.m Tue Mar 11 10:46:54 2014
@@ -94,7 +94,7 @@
data = [[data mutableCopy] autorelease];
[(NSMutableData*)data appendBytes: "\r\n\r\n" length: 4];
[parser parse: data];
- doc = [parser document];
+ doc = [parser mimeDocument];
PASS([[parser excess] length] == 5, "Can detect excess data in multipart");
[parser release];
@@ -182,12 +182,25 @@
doc = [GSMimeParser documentFromData: data];
PASS_EQUAL(idoc, doc, "rawMimeData reproduces document");
- /* Test a document containing encoded words in header
+ /* Test parse of a document containing encoded words in header.
+ * Use JavaMail encoded words (different format from those GSMime
+ * produces).
*/
data = [NSData dataWithContentsOfFile: @"mime11.dat"];
idoc = exact(0, data);
doc = [GSMimeParser documentFromData: data];
PASS_EQUAL(idoc, doc, "mime11.dat documents are the same");
+
+ /* Test a document with adjacent encoded words in headers, as
+ * produced by GSMime
+ */
+ data = [NSData dataWithContentsOfFile: @"mime12.dat"];
+ idoc = exact(0, data);
+ doc = [GSMimeParser documentFromData: data];
+ PASS_EQUAL(idoc, doc, "mime12.dat documents are the same");
+ data = [idoc rawMimeData];
+ doc = [GSMimeParser documentFromData: data];
+ PASS_EQUAL(idoc, doc, "rawMimeData reproduces document");
[arp release]; arp = nil;
Added: libs/base/trunk/Tests/base/GSMime/mime12.dat
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/GSMime/mime12.dat?rev=37740&view=auto
==============================================================================
--- libs/base/trunk/Tests/base/GSMime/mime12.dat (added)
+++ libs/base/trunk/Tests/base/GSMime/mime12.dat Tue Mar 11 10:46:54 2014
@@ -0,0 +1,6 @@
+MIME-Version: 1.0
+Content-Type: text/plain
+Subject: Avant de partir, n'oubliez pas de =?iso-8859-1?b?cHLpcGFyZXI=?= votre
+ =?iso-8859-1?b?c+lqb3Vy?==?iso-8859-1?b?IOA=?= Paris
+
+hello
Modified: libs/base/trunk/Tests/base/GSMime/test01.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/GSMime/test01.m?rev=37740&r1=37739&r2=37740&view=diff
==============================================================================
--- libs/base/trunk/Tests/base/GSMime/test01.m (original)
+++ libs/base/trunk/Tests/base/GSMime/test01.m Tue Mar 11 10:46:54 2014
@@ -106,7 +106,7 @@
PASS ([parser isComplete], "parse is complete");
PASS ([parser isComplete], "parse is complete");
- PASS_EQUAL([[parser document] convertToText],
+ PASS_EQUAL([[parser mimeDocument] convertToText],
@"This is the data in the first chunk\r\nand this is the second one\r\n"
@"consequence", "content correct");
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs