RT 4.0.22
[freeside.git] / rt / t / mail / not-supported-charset.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5 use Test::Warn;
6
7 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
8 ok $queue->id, 'loaded queue';
9
10 {
11     my $mail = <<'END';
12 From: root@localhost
13 Subject: test
14 Content-type: text/plain; charset="not-supported-encoding"
15
16 ho hum just some text
17
18 END
19
20     my ($stat, $id);
21     warning_like {
22         ($stat, $id) = RT::Test->send_via_mailgate($mail);
23         is( $stat >> 8, 0, "The mail gateway exited normally" );
24         ok( $id, "created ticket" );
25     } qr/Encoding 'not-supported-encoding' is not supported/;
26
27     my $ticket = RT::Ticket->new( RT->SystemUser );
28     $ticket->Load($id);
29     ok $ticket->id, "loaded ticket";
30
31     my $txn = $ticket->Transactions->First;
32     ok !$txn->ContentObj, 'no content';
33
34     my $attach = $txn->Attachments->First;
35     like $attach->Content, qr{ho hum just some text}, 'attachment is there';
36     is $attach->GetHeader('Content-Type'),
37         'application/octet-stream; charset="not-supported-encoding"',
38         'content type is changed'
39     ;
40     is $attach->GetHeader('X-RT-Original-Content-Type'),
41         'text/plain',
42         'original content type is saved'
43     ;
44 }
45
46 {
47     my $mail = <<'END';
48 From: root@localhost
49 Subject: =?not-supported?Q?=07test=A9?=
50 Content-type: text/plain; charset="ascii"
51
52 ho hum just some text
53
54 END
55
56     my ($stat, $id);
57     warning_like {
58         ($stat, $id) = RT::Test->send_via_mailgate($mail);
59         is( $stat >> 8, 0, "The mail gateway exited normally" );
60         ok( $id, "created ticket" );
61     } qr/Charset 'not-supported' is not supported/;
62
63     my $ticket = RT::Ticket->new( RT->SystemUser );
64     $ticket->Load($id);
65     ok $ticket->id, "loaded ticket";
66     is $ticket->Subject, "\x{FFFD}test\x{FFFD}";
67 }
68
69 done_testing;