2011-02-16 08:21:17 +00:00
|
|
|
|
#if defined(GNUSTEP_BASE_LIBRARY)
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import <GNUstepBase/GSMime.h>
|
|
|
|
|
#import "Testing.h"
|
2019-02-14 11:19:33 +00:00
|
|
|
|
|
|
|
|
|
static int
|
2021-01-22 08:47:16 +00:00
|
|
|
|
find(const char *buf, unsigned len, const char *str)
|
2019-02-14 11:19:33 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
|
int main(int argc,char **argv)
|
|
|
|
|
{
|
2024-04-04 10:27:57 +00:00
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
|
NSData *data = nil;
|
|
|
|
|
NSString *string = nil;
|
2024-11-14 20:26:37 +00:00
|
|
|
|
GSMimeDocument *doc = AUTORELEASE([[GSMimeDocument alloc] init]);
|
2024-04-04 10:27:57 +00:00
|
|
|
|
GSMimeDocument *mul;
|
2024-11-14 20:26:37 +00:00
|
|
|
|
NSMutableDictionary *par = AUTORELEASE([[NSMutableDictionary alloc] init]);
|
2016-02-25 11:55:58 +00:00
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
|
[par setObject: @"my/type" forKey: @"type"];
|
|
|
|
|
[doc setContent: @"Hello\r\n"];
|
2024-11-14 20:26:37 +00:00
|
|
|
|
[doc setHeader: [GSMimeHeader headerWithName: @"content-type"
|
|
|
|
|
value: @"text/plain"
|
|
|
|
|
parameters: par]];
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
2024-11-14 20:26:37 +00:00
|
|
|
|
[doc setHeader: [GSMimeHeader headerWithName: @"content-transfer-encoding"
|
|
|
|
|
value: @"binary"
|
|
|
|
|
parameters: nil]];
|
2011-02-16 08:21:17 +00:00
|
|
|
|
|
|
|
|
|
data = [NSData dataWithContentsOfFile: @"mime8.dat"];
|
|
|
|
|
PASS([[doc rawMimeData] isEqual: data], "Can make a simple document");
|
2016-02-25 11:55:58 +00:00
|
|
|
|
|
2016-02-25 13:07:08 +00:00
|
|
|
|
string = @"ABCD credit card account − more information about Peach Pay.";
|
2024-11-14 20:26:37 +00:00
|
|
|
|
[doc setHeader: [GSMimeHeader headerWithName: @"subject"
|
|
|
|
|
value: string
|
|
|
|
|
parameters: nil]];
|
2016-02-25 11:55:58 +00:00
|
|
|
|
data = [doc rawMimeData];
|
|
|
|
|
PASS(data != nil, "Can use non-ascii character in subject");
|
|
|
|
|
doc = [GSMimeParser documentFromData: data];
|
|
|
|
|
PASS_EQUAL([[doc headerNamed: @"subject"] value], string,
|
|
|
|
|
"Can restore non-ascii character in subject");
|
|
|
|
|
|
2016-08-03 09:24:53 +00:00
|
|
|
|
data = [[GSMimeSerializer smtp7bitSerializer] encodeDocument: doc];
|
|
|
|
|
PASS(data != nil, "Can serialize with non-ascii character in subject");
|
|
|
|
|
doc = [GSMimeParser documentFromData: data];
|
|
|
|
|
PASS_EQUAL([[doc headerNamed: @"subject"] value], string,
|
|
|
|
|
"Can restore non-ascii character in subject form serialized document");
|
|
|
|
|
|
2024-11-14 20:26:37 +00:00
|
|
|
|
[doc setHeader: [GSMimeHeader headerWithName: @"subject"
|
|
|
|
|
value: @"€"
|
|
|
|
|
parameters: nil]];
|
2019-02-14 11:19:33 +00:00
|
|
|
|
data = [doc rawMimeData];
|
2024-11-15 12:27:48 +00:00
|
|
|
|
/*
|
2019-02-14 11:19:33 +00:00
|
|
|
|
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";
|
2024-11-15 12:27:48 +00:00
|
|
|
|
*/
|
2021-01-22 08:47:16 +00:00
|
|
|
|
PASS(find((char*)[data bytes], (unsigned)[data length], "?B?4oKs?=") > 0,
|
2019-02-14 11:19:33 +00:00
|
|
|
|
"encodes utf-8 euro in subject");
|
|
|
|
|
|
2024-04-04 10:27:57 +00:00
|
|
|
|
mul = AUTORELEASE([GSMimeDocument new]);
|
|
|
|
|
[mul addHeader: @"Subject" value: @"subject" parameters: nil];
|
|
|
|
|
[mul setContentType: @"multipart/alternative"];
|
|
|
|
|
|
|
|
|
|
[mul addContent:
|
|
|
|
|
[GSMimeDocument documentWithContent: @"<body>some html</body>"
|
|
|
|
|
type: @"text/html; charset=utf-8"
|
|
|
|
|
name: @"html"]];
|
|
|
|
|
[mul addContent:
|
|
|
|
|
[GSMimeDocument documentWithContent: @"some text"
|
|
|
|
|
type: @"text/plain; charset=utf-8"
|
|
|
|
|
name: @"text"]];
|
|
|
|
|
doc = [[mul content] firstObject];
|
|
|
|
|
PASS_EQUAL([doc contentName], @"html", "before parse, first part is html")
|
|
|
|
|
doc = [[mul content] lastObject];
|
|
|
|
|
PASS_EQUAL([doc contentName], @"text", "before parse, last part is text")
|
|
|
|
|
data = [mul rawMimeData];
|
|
|
|
|
mul = [GSMimeParser documentFromData: data];
|
|
|
|
|
doc = [[mul content] firstObject];
|
|
|
|
|
PASS_EQUAL([doc contentName], @"html", "after parse, first part is html")
|
|
|
|
|
doc = [[mul content] lastObject];
|
|
|
|
|
PASS_EQUAL([doc contentName], @"text", "after parse, last part is text")
|
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
|
[arp release]; arp = nil;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
int main(int argc,char **argv)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|