fixes for encoding in mime header encoded word

This commit is contained in:
Richard Frith-Macdonald 2019-02-14 11:19:33 +00:00
parent 9afe522216
commit d6ef10f224
3 changed files with 45 additions and 6 deletions

View file

@ -1,3 +1,13 @@
2019-02-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSMime.m: Fix encoded word encoding specifier
to be uppercase ('B' or 'Q') as pere strict RFC specification.
* Tests/base/GSMime/build.m: Add testcase for correct encoding.
2019-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Tests/base/GSTLS/basic.m: Update testcase to use correct guard.
2019-02-12 Ivan Vucica <ivan@vucica.net>
* Headers/GNUstepBase/GSTLS.h: Change guard to check for value of

View file

@ -2998,12 +2998,12 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
src = tmp + 1;
if (src >= end) return nil;
c = tolower(*src);
if (c == 'b')
c = toupper(*src);
if (c == 'B')
{
encoding = WE_BASE64;
}
else if (c == 'q')
else if (c == 'Q')
{
encoding = WE_QUOTED;
}
@ -4153,7 +4153,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
NSUInteger existingLength;
NSUInteger quotedLength;
NSUInteger charLength;
uint8_t style = 'q';
uint8_t style = 'Q';
/* Calculate the number of encoded characters we can
* fit on the current line. If there's no room, we
@ -4178,7 +4178,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
/* Using base64 is more compact than using quoted
* text, so lets do that.
*/
style = 'b';
style = 'B';
charLength = ((fold - offset - overhead) / 4) * 3;
if (charLength >= len - pos)
{
@ -4205,7 +4205,7 @@ appendString(NSMutableData *m, NSUInteger offset, NSUInteger fold,
*buffer++ = '?';
*buffer++ = style;
*buffer++ = '?';
if ('q' == style)
if ('Q' == style)
{
quotedWord(ptr + pos, charLength, buffer);
}

View file

@ -2,6 +2,24 @@
#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>
#import "Testing.h"
static int
strnstr(const uint8_t *buf, unsigned len, const uint8_t *str)
{
int l = strlen(str);
int max = len - l;
int i;
for (i = 0; i < max; i++)
{
if (strncmp(buf + i, str, l) == 0)
{
return i;
}
}
return -1;
}
int main(int argc,char **argv)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
@ -41,6 +59,17 @@ int main(int argc,char **argv)
PASS_EQUAL([[doc headerNamed: @"subject"] value], string,
"Can restore non-ascii character in subject form serialized document");
[doc setHeader:
[[GSMimeHeader alloc] initWithName: @"subject"
value: @"€"
parameters: nil]];
data = [doc rawMimeData];
const char *bytes = "MIME-Version: 1.0\r\n"
"Content-Type: text/plain; type=\"my/type\"\r\n"
"Subject: =?utf-8?B?4oKs?=\r\n\r\n";
PASS(strnstr([data bytes], [data length], "?B?4oKs?=") > 0,
"encodes utf-8 euro in subject");
[arp release]; arp = nil;
return 0;
}