mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
fixup for whitespace between encoded words
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37672 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ede8af3da2
commit
5f03a0bfa2
3 changed files with 38 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2014-02-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/Additions/GSMime.m:
|
||||
* Headers/GNUstepBase/GSMime.h:
|
||||
Add support for stripping white space between encoded words (RFC2047)
|
||||
|
||||
2014-02-02 Yavor Doganov <yavor@gnu.org>
|
||||
|
||||
* configure.ac: Force use for fake main on kfreebsd to work around bug
|
||||
|
|
|
@ -213,6 +213,10 @@ extern "C" {
|
|||
unsigned lineStart;
|
||||
unsigned lineEnd;
|
||||
unsigned input;
|
||||
/* During header parsing, we use this field to count white space we are
|
||||
* expecting to have after an encoded word.
|
||||
* During bnody parsing, we use the field to count expected content bytes.
|
||||
*/
|
||||
unsigned expect;
|
||||
unsigned rawBodyLength;
|
||||
struct {
|
||||
|
@ -224,6 +228,7 @@ extern "C" {
|
|||
unsigned int wantEndOfLine:1;
|
||||
unsigned int excessData:1;
|
||||
unsigned int headersOnly:1;
|
||||
unsigned int encodedWord:1;
|
||||
} flags;
|
||||
NSData *boundary; // Also overloaded to hold excess
|
||||
GSMimeDocument *document;
|
||||
|
|
|
@ -3039,6 +3039,14 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
|||
NSLog(@"Bad encoded word - data terminator missing");
|
||||
break;
|
||||
}
|
||||
/* If we are expecting to have white space after an encoded
|
||||
* word, we must get rid of it between words.
|
||||
*/
|
||||
if (1 == flags.encodedWord && expect > 0)
|
||||
{
|
||||
[hdr deleteCharactersInRange:
|
||||
NSMakeRange([hdr length] - expect, expect)];
|
||||
}
|
||||
/* If the data part is not empty, decode it and append to header.
|
||||
*/
|
||||
if (tmp > src)
|
||||
|
@ -3058,6 +3066,8 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
|||
*/
|
||||
src = tmp + 2;
|
||||
beg = src;
|
||||
flags.encodedWord = 1; // We just parsed an encoded word
|
||||
expect = 0; // No space expected after word yet
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
@ -3073,6 +3083,8 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
|||
* between headers and body.
|
||||
*/
|
||||
flags.inBody = 1;
|
||||
flags.encodedWord = 0;
|
||||
expect = 0;
|
||||
input = src - bytes;
|
||||
return nil;
|
||||
}
|
||||
|
@ -3086,15 +3098,30 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
|||
/* End of line ... return this header.
|
||||
*/
|
||||
input = src - bytes;
|
||||
flags.encodedWord = 0;
|
||||
expect = 0;
|
||||
return hdr;
|
||||
}
|
||||
/* Folded line ... add space at fold and continue parsing.
|
||||
* NB Space is ignored between encoded words; don't reset flag.
|
||||
*/
|
||||
[hdr appendString: @" "];
|
||||
beg = src;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (1 == flags.encodedWord)
|
||||
{
|
||||
if (isspace(src[0]))
|
||||
{
|
||||
expect++; // Count expected space after word
|
||||
}
|
||||
else
|
||||
{
|
||||
flags.encodedWord = 0; // No longer in encoded word
|
||||
expect = 0;
|
||||
}
|
||||
}
|
||||
src++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue