3484d14701e2737fe1958a2a8d86d1637a9f5d34
[freeside.git] / rt / t / mail / one-time-recipients.t
1 use strict;
2 use warnings;
3 use utf8;
4
5 use RT::Test tests => 38;
6
7 my $queue = RT::Test->load_or_create_queue(
8     Name              => 'General',
9     CorrespondAddress => 'rt-recipient@example.com',
10     CommentAddress    => 'rt-recipient@example.com',
11 );
12 ok $queue && $queue->id, 'loaded or created queue';
13
14 my $user = RT::Test->load_or_create_user(
15     Name         => 'root',
16     EmailAddress => 'root@localhost',
17 );
18 ok $user && $user->id, 'loaded or created user';
19
20 diag "Reply to ticket with actor as one time cc";
21 {
22     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
23     my ($status, undef, $msg) = $ticket->Create(
24         Queue => $queue->id,
25         Subject => 'test',
26         Requestor => 'root@localhost',
27     );
28     ok $status, "created ticket";
29
30     my @mails = RT::Test->fetch_caught_mails;
31     ok @mails, "got some outgoing emails";
32     foreach my $mail ( @mails ) {
33         my $entity = parse_mail( $mail );
34         my $to = $entity->head->get('To');
35         $to =~ s/^\s+|\s+$//; 
36         is $to, 'root@localhost', 'got mail'
37     }
38
39     RT->Config->Set( NotifyActor => 1 );
40     ($status, $msg) = $ticket->Correspond(
41         Content => 'test mail',
42     );
43     ok $status, "replied to a ticket";
44
45     @mails = RT::Test->fetch_caught_mails;
46     ok @mails, "got some outgoing emails";
47     foreach my $mail ( @mails ) {
48         my $entity = parse_mail( $mail );
49         my $to = $entity->head->get('To');
50         $to =~ s/^\s+|\s+$//; 
51         is $to, 'root@localhost', 'got mail'
52     }
53
54     RT->Config->Set( NotifyActor => 0 );
55     ($status, $msg) = $ticket->Correspond(
56         Content => 'test mail',
57     );
58     ok $status, "replied to a ticket";
59
60     @mails = RT::Test->fetch_caught_mails;
61     ok !@mails, "no mail - don't notify actor";
62
63     ($status, $msg) = $ticket->Correspond(
64         Content => 'test mail',
65         CcMessageTo => 'root@localhost',
66     );
67     ok $status, "replied to a ticket";
68
69     @mails = RT::Test->fetch_caught_mails;
70     ok @mails, "got some outgoing emails";
71     foreach my $mail ( @mails ) {
72         my $entity = parse_mail( $mail );
73         my $to = $entity->head->get('Cc');
74         $to =~ s/^\s+|\s+$//; 
75         is $to, 'root@localhost', 'got mail'
76     }
77 }
78
79 diag "Reply to ticket with requestor squelched";
80 {
81     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
82     my ($status, undef, $msg) = $ticket->Create(
83         Queue => $queue->id,
84         Subject => 'test',
85         Requestor => 'test@localhost',
86     );
87     ok $status, "created ticket";
88
89     my @mails = RT::Test->fetch_caught_mails;
90     ok @mails, "got some outgoing emails";
91     foreach my $mail ( @mails ) {
92         my $entity = parse_mail( $mail );
93         my $to = $entity->head->get('To');
94         $to =~ s/^\s+|\s+$//; 
95         is $to, 'test@localhost', 'got mail'
96     }
97
98     ($status, $msg) = $ticket->Correspond(
99         Content => 'test mail',
100     );
101     ok $status, "replied to a ticket";
102
103     @mails = RT::Test->fetch_caught_mails;
104     ok @mails, "got some outgoing emails";
105     foreach my $mail ( @mails ) {
106         my $entity = parse_mail( $mail );
107         my $to = $entity->head->get('To');
108         $to =~ s/^\s+|\s+$//; 
109         is $to, 'test@localhost', 'got mail'
110     }
111
112     $ticket->SquelchMailTo('test@localhost');
113     ($status, $msg) = $ticket->Correspond(
114         Content => 'test mail',
115     );
116     ok $status, "replied to a ticket";
117
118     @mails = RT::Test->fetch_caught_mails;
119     ok !@mails, "no mail - squelched";
120
121     ($status, $msg) = $ticket->Correspond(
122         Content => 'test mail',
123         CcMessageTo => 'test@localhost',
124     );
125     ok $status, "replied to a ticket";
126
127     @mails = RT::Test->fetch_caught_mails;
128     ok @mails, "got some outgoing emails";
129     foreach my $mail ( @mails ) {
130         my $entity = parse_mail( $mail );
131         my $to = $entity->head->get('Cc');
132         $to =~ s/^\s+|\s+$//; 
133         is $to, 'test@localhost', 'got mail'
134     }
135 }
136
137 diag "Reply to ticket with requestor squelched";
138 {
139     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
140     my ($status, undef, $msg) = $ticket->Create(
141         Queue => $queue->id,
142         Subject => 'test',
143         Requestor => 'test@localhost',
144     );
145     ok $status, "created ticket";
146
147     my @mails = RT::Test->fetch_caught_mails;
148     ok @mails, "got some outgoing emails";
149     foreach my $mail ( @mails ) {
150         my $entity = parse_mail( $mail );
151         my $to = $entity->head->get('To');
152         $to =~ s/^\s+|\s+$//; 
153         is $to, 'test@localhost', 'got mail'
154     }
155
156     ($status, $msg) = $ticket->Correspond(
157         Content => 'test mail',
158     );
159     ok $status, "replied to a ticket";
160
161     @mails = RT::Test->fetch_caught_mails;
162     ok @mails, "got some outgoing emails";
163     foreach my $mail ( @mails ) {
164         my $entity = parse_mail( $mail );
165         my $to = $entity->head->get('To');
166         $to =~ s/^\s+|\s+$//; 
167         is $to, 'test@localhost', 'got mail'
168     }
169
170     ($status, $msg) = $ticket->Correspond(
171         Content => 'test mail',
172         SquelchMailTo => ['test@localhost'],
173     );
174     ok $status, "replied to a ticket";
175
176     @mails = RT::Test->fetch_caught_mails;
177     ok !@mails, "no mail - squelched";
178
179     ($status, $msg) = $ticket->Correspond(
180         Content => 'test mail',
181     );
182     ok $status, "replied to a ticket";
183
184     @mails = RT::Test->fetch_caught_mails;
185     ok @mails, "got some outgoing emails";
186     foreach my $mail ( @mails ) {
187         my $entity = parse_mail( $mail );
188         my $to = $entity->head->get('To');
189         $to =~ s/^\s+|\s+$//; 
190         is $to, 'test@localhost', 'got mail'
191     }
192
193     ($status, $msg) = $ticket->Correspond(
194         Content => 'test mail',
195         CcMessageTo => 'test@localhost',
196         SquelchMailTo => ['test@localhost'],
197     );
198     ok $status, "replied to a ticket";
199
200     @mails = RT::Test->fetch_caught_mails;
201     ok @mails, "got some outgoing emails";
202     foreach my $mail ( @mails ) {
203         my $entity = parse_mail( $mail );
204         my $to = $entity->head->get('Cc');
205         $to =~ s/^\s+|\s+$//; 
206         is $to, 'test@localhost', 'got mail'
207     }
208 }