first pass RT4 merge, RT#13852
[freeside.git] / rt / t / mail / disposition-outgoing.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5
6 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
7 ok $queue->id, 'loaded queue';
8
9 my ($ok, $msg) = $queue->AddWatcher(
10     Type    => 'AdminCc',
11     Email   => 'test@example.com',
12 );
13 ok $ok, $msg;
14
15 my $mail = <<'.';
16 From: root@localhost
17 Subject: I like inline dispositions and I cannot lie
18 Content-type: multipart/related; boundary="foo"
19
20 --foo
21 Content-type: text/plain; charset="UTF-8"
22
23 ho hum just some text
24
25 --foo
26 Content-type: text/x-patch; name="filename.patch"
27 Content-disposition: inline; filename="filename.patch"
28
29 a fake patch
30
31 --foo
32 .
33
34 # inline
35 {
36     my $rt = send_and_receive($mail);
37     like $rt, qr/Content-Disposition:\s*inline.+?filename\.patch/is, 'found inline disposition';
38 }
39
40 # attachment
41 {
42     $mail =~ s/(?<=Content-disposition: )inline/attachment/i;
43
44     my $rt = send_and_receive($mail);
45     like $rt, qr/Content-Disposition:\s*attachment.+?filename\.patch/is, 'found attachment disposition';
46 }
47
48 # no disposition
49 {
50     $mail =~ s/^Content-disposition: .+?\n(?=\n)//ism;
51
52     my $rt = send_and_receive($mail);
53     like $rt, qr/Content-Disposition:\s*inline.+?filename\.patch/is, 'found default (inline) disposition';
54 }
55
56 sub send_and_receive {
57     my $mail = shift;
58     my ($stat, $id) = RT::Test->send_via_mailgate($mail);
59     is( $stat >> 8, 0, "The mail gateway exited normally" );
60     ok( $id, "created ticket" );
61
62     my @mails = RT::Test->fetch_caught_mails;
63     is @mails, 2, "got 2 outgoing emails";
64
65     # first is autoreply
66     pop @mails;
67 }
68
69 done_testing;