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