RT 4.0.22
[freeside.git] / rt / t / mail / header-characters.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 12;
5 use Test::Warn;
6
7 my ($baseurl, $m) = RT::Test->started_ok;
8
9 diag "Testing non-ASCII in From: header";
10 SKIP:{
11     skip "Test requires Email::Address 1.893 or later, "
12       . "you have $Email::Address::VERSION", 3,
13       if $Email::Address::VERSION < 1.893;
14
15     my $mail = Encode::encode( 'iso-8859-1', Encode::decode( "UTF-8", <<'.') );
16 From: René@example.com>
17 Reply-To: =?iso-8859-1?Q?Ren=E9?= <René@example.com>
18 Subject: testing non-ASCII From
19 Content-Type: text/plain; charset=iso-8859-1
20
21 here's some content
22 .
23
24     my ($status, $id);
25     warnings_like { ( $status, $id ) = RT::Test->send_via_mailgate($mail) }
26         [qr/Failed to parse Reply-To:.*, From:/,
27          qr/Couldn't parse or find sender's address/
28         ],
29         'Got parse error for non-ASCII in From';
30     is( $status >> 8, 0, "The mail gateway exited normally" );
31     TODO: {
32           local $TODO = "Currently don't handle non-ASCII for sender";
33           ok( $id, "Created ticket" );
34       }
35 }
36
37 diag "Testing iso-8859-1 encoded non-ASCII in From: header";
38 SKIP:{
39     skip "Test requires Email::Address 1.893 or later, "
40       . "you have $Email::Address::VERSION", 3,
41       if $Email::Address::VERSION < 1.893;
42
43     my $mail = Encode::encode( 'iso-8859-1', Encode::decode( "UTF-8", <<'.' ) );
44 From: =?iso-8859-1?Q?Ren=E9?= <René@example.com>
45 Reply-To: =?iso-8859-1?Q?Ren=E9?= <René@example.com>
46 Subject: testing non-ASCII From
47 Content-Type: text/plain; charset=iso-8859-1
48
49 here's some content
50 .
51
52     my ($status, $id);
53     warnings_like { ( $status, $id ) = RT::Test->send_via_mailgate($mail) }
54         [qr/Failed to parse Reply-To:.*, From:/,
55          qr/Couldn't parse or find sender's address/
56         ],
57         'Got parse error for iso-8859-1 in From';
58     is( $status >> 8, 0, "The mail gateway exited normally" );
59     TODO: {
60           local $TODO = "Currently don't handle non-ASCII in sender";
61           ok( $id, "Created ticket" );
62       }
63 }
64
65 diag "No sender";
66 {
67     my $mail = <<'.';
68 To: rt@example.com
69 Subject: testing non-ASCII From
70 Content-Type: text/plain; charset=iso-8859-1
71
72 here's some content
73 .
74
75     my ($status, $id);
76     warnings_like { ( $status, $id ) = RT::Test->send_via_mailgate($mail) }
77         [qr/Couldn't parse or find sender's address/],
78         'Got parse error with no sender fields';
79     is( $status >> 8, 0, "The mail gateway exited normally" );
80     ok( !$id, "No ticket created" );
81 }