4 use RT::Test tests => 78;
8 test => "\x{442}\x{435}\x{441}\x{442}",
9 autoreply => "\x{410}\x{432}\x{442}\x{43e}\x{43e}\x{442}\x{432}\x{435}\x{442}",
10 support => "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}",
13 test => Encode::decode('latin1', "t\xE9st"),
14 autoreply => Encode::decode('latin1', "a\xFCtoreply"),
15 support => Encode::decode('latin1', "supp\xF5rt"),
19 my $queue = RT::Test->load_or_create_queue(
21 CorrespondAddress => 'rt-recipient@example.com',
22 CommentAddress => 'rt-recipient@example.com',
24 ok $queue && $queue->id, 'loaded or created queue';
26 diag "make sure queue has no subject tag";
28 my ($status, $msg) = $queue->SetSubjectTag( undef );
29 ok $status, "set subject tag for the queue" or diag "error: $msg";
32 diag "set intial simple autoreply template";
34 my $template = RT::Template->new( RT->SystemUser );
35 $template->Load('Autoreply');
36 ok $template->id, "loaded autoreply tempalte";
38 my ($status, $msg) = $template->SetContent(
39 "Subject: Autreply { \$Ticket->Subject }\n"
41 ."hi there it's an autoreply.\n"
44 ok $status, "changed content of the template"
45 or diag "error: $msg";
48 diag "basic test of autoreply";
50 my $ticket = RT::Ticket->new( RT->SystemUser );
54 Requestor => 'root@localhost',
56 my @mails = RT::Test->fetch_caught_mails;
57 ok @mails, "got some outgoing emails";
60 diag "non-ascii Subject with ascii prefix set in the template";
61 foreach my $set ( 'ru', 'latin1' ) {
62 my $ticket = RT::Ticket->new( RT->SystemUser );
65 Subject => $string{$set}{test},
66 Requestor => 'root@localhost',
68 my @mails = RT::Test->fetch_caught_mails;
69 ok @mails, "got some outgoing emails";
72 foreach my $mail ( @mails ) {
73 my $entity = parse_mail( $mail );
74 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
75 $subject =~ /$string{$set}{test}/
76 or do { $status = 0; diag "wrong subject: $subject" };
78 ok $status, "all mails have correct data";
81 foreach my $tag_set ( 'ru', 'latin1' ) {
83 diag "set non-ascii subject tag for the queue";
85 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
86 ok $status, "set subject tag for the queue" or diag "error: $msg";
89 diag "ascii subject with non-ascii subject tag";
91 my $ticket = RT::Ticket->new( RT->SystemUser );
95 Requestor => 'root@localhost',
97 my @mails = RT::Test->fetch_caught_mails;
98 ok @mails, "got some outgoing emails";
101 foreach my $mail ( @mails ) {
102 my $entity = parse_mail( $mail );
103 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
104 $subject =~ /$string{$tag_set}{support}/
105 or do { $status = 0; diag "wrong subject: $subject" };
107 ok $status, "all mails have correct data";
110 diag "non-ascii subject with non-ascii subject tag";
111 foreach my $set ( 'ru', 'latin1' ) {
112 my $ticket = RT::Ticket->new( RT->SystemUser );
115 Subject => $string{$set}{test},
116 Requestor => 'root@localhost',
118 my @mails = RT::Test->fetch_caught_mails;
119 ok @mails, "got some outgoing emails";
122 foreach my $mail ( @mails ) {
123 my $entity = parse_mail( $mail );
124 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
125 $subject =~ /$string{$tag_set}{support}/
126 or do { $status = 0; diag "wrong subject: $subject" };
127 $subject =~ /$string{$set}{test}/
128 or do { $status = 0; diag "wrong subject: $subject" };
130 ok $status, "all mails have correct data";
135 diag "return back the empty subject tag";
137 my ($status, $msg) = $queue->SetSubjectTag( undef );
138 ok $status, "set subject tag for the queue" or diag "error: $msg";
142 foreach my $prefix_set ( 'ru', 'latin1' ) {
144 diag "add non-ascii subject prefix in the autoreply template";
146 my $template = RT::Template->new( RT->SystemUser );
147 $template->Load('Autoreply');
148 ok $template->id, "loaded autoreply tempalte";
150 my ($status, $msg) = $template->SetContent(
151 "Subject: $string{$prefix_set}{autoreply} { \$Ticket->Subject }\n"
153 ."hi there it's an autoreply.\n"
156 ok $status, "changed content of the template" or diag "error: $msg";
159 diag "ascii subject with non-ascii subject prefix in template";
161 my $ticket = RT::Ticket->new( RT->SystemUser );
165 Requestor => 'root@localhost',
167 my @mails = RT::Test->fetch_caught_mails;
168 ok @mails, "got some outgoing emails";
171 foreach my $mail ( @mails ) {
172 my $entity = parse_mail( $mail );
173 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
174 $subject =~ /$string{$prefix_set}{autoreply}/
175 or do { $status = 0; diag "wrong subject: $subject" };
177 ok $status, "all mails have correct data";
180 diag "non-ascii subject with non-ascii subject prefix in template";
181 foreach my $set ( 'ru', 'latin1' ) {
182 my $ticket = RT::Ticket->new( RT->SystemUser );
185 Subject => $string{$set}{test},
186 Requestor => 'root@localhost',
188 my @mails = RT::Test->fetch_caught_mails;
189 ok @mails, "got some outgoing emails";
192 foreach my $mail ( @mails ) {
193 my $entity = parse_mail( $mail );
194 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
195 $subject =~ /$string{$prefix_set}{autoreply}/
196 or do { $status = 0; diag "wrong subject: $subject" };
197 $subject =~ /$string{$set}{test}/
198 or do { $status = 0; diag "wrong subject: $subject" };
200 ok $status, "all mails have correct data";
203 foreach my $tag_set ( 'ru', 'latin1' ) {
204 diag "set non-ascii subject tag for the queue";
206 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
207 ok $status, "set subject tag for the queue" or diag "error: $msg";
210 diag "non-ascii subject, non-ascii prefix in template and non-ascii tag";
211 foreach my $set ( 'ru', 'latin1' ) {
212 my $ticket = RT::Ticket->new( RT->SystemUser );
215 Subject => $string{$set}{test},
216 Requestor => 'root@localhost',
218 my @mails = RT::Test->fetch_caught_mails;
219 ok @mails, "got some outgoing emails";
222 foreach my $mail ( @mails ) {
223 my $entity = parse_mail( $mail );
224 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
225 $subject =~ /$string{$prefix_set}{autoreply}/
226 or do { $status = 0; diag "wrong subject: $subject" };
227 $subject =~ /$string{$tag_set}{support}/
228 or do { $status = 0; diag "wrong subject: $subject" };
229 $subject =~ /$string{$set}{test}/
230 or do { $status = 0; diag "wrong subject: $subject" };
232 ok $status, "all mails have correct data";
237 diag "flush subject tag of the queue";
239 my ($status, $msg) = $queue->SetSubjectTag( undef );
240 ok $status, "set subject tag for the queue" or diag "error: $msg";
246 diag "don't change subject via template";
247 # clean DB has autoreply that always changes subject in template,
248 # we should test situation when subject is not changed from template
250 my $template = RT::Template->new( RT->SystemUser );
251 $template->Load('Autoreply');
252 ok $template->id, "loaded autoreply tempalte";
254 my ($status, $msg) = $template->SetContent(
257 ."hi there it's an autoreply.\n"
260 ok $status, "changed content of the template" or diag "error: $msg";
263 diag "non-ascii Subject without changes in template";
264 foreach my $set ( 'ru', 'latin1' ) {
265 my $ticket = RT::Ticket->new( RT->SystemUser );
268 Subject => $string{$set}{test},
269 Requestor => 'root@localhost',
271 my @mails = RT::Test->fetch_caught_mails;
272 ok @mails, "got some outgoing emails";
275 foreach my $mail ( @mails ) {
276 my $entity = parse_mail( $mail );
277 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
278 $subject =~ /$string{$set}{test}/
279 or do { $status = 0; diag "wrong subject: $subject" };
281 ok $status, "all mails have correct data";
284 foreach my $tag_set ( 'ru', 'latin1' ) {
285 diag "set non-ascii subject tag for the queue";
287 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
288 ok $status, "set subject tag for the queue" or diag "error: $msg";
291 diag "non-ascii Subject without changes in template and with non-ascii subject tag";
292 foreach my $set ( 'ru', 'latin1' ) {
293 my $ticket = RT::Ticket->new( RT->SystemUser );
296 Subject => $string{$set}{test},
297 Requestor => 'root@localhost',
299 my @mails = RT::Test->fetch_caught_mails;
300 ok @mails, "got some outgoing emails";
303 foreach my $mail ( @mails ) {
304 my $entity = parse_mail( $mail );
305 my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
306 $subject =~ /$string{$set}{test}/
307 or do { $status = 0; diag "wrong subject: $subject" };
308 $subject =~ /$string{$tag_set}{support}/
309 or do { $status = 0; diag "wrong subject: $subject" };
311 ok $status, "all mails have correct data";