6 use RT::Test tests => 78;
10 test => "\x{442}\x{435}\x{441}\x{442}",
11 autoreply => "\x{410}\x{432}\x{442}\x{43e}\x{43e}\x{442}\x{432}\x{435}\x{442}",
12 support => "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}",
15 test => Encode::decode('latin1', "t\xE9st"),
16 autoreply => Encode::decode('latin1', "a\xFCtoreply"),
17 support => Encode::decode('latin1', "supp\xF5rt"),
21 my $queue = RT::Test->load_or_create_queue(
23 CorrespondAddress => 'rt-recipient@example.com',
24 CommentAddress => 'rt-recipient@example.com',
26 ok $queue && $queue->id, 'loaded or created queue';
28 diag "make sure queue has no subject tag";
30 my ($status, $msg) = $queue->SetSubjectTag( undef );
31 ok $status, "set subject tag for the queue" or diag "error: $msg";
34 diag "set intial simple autoreply template";
36 my $template = RT::Template->new( RT->SystemUser );
37 $template->Load('Autoreply');
38 ok $template->id, "loaded autoreply tempalte";
40 my ($status, $msg) = $template->SetContent(
41 "Subject: Autreply { \$Ticket->Subject }\n"
43 ."hi there it's an autoreply.\n"
46 ok $status, "changed content of the template"
47 or diag "error: $msg";
50 diag "basic test of autoreply";
52 my $ticket = RT::Ticket->new( RT->SystemUser );
56 Requestor => 'root@localhost',
58 my @mails = RT::Test->fetch_caught_mails;
59 ok @mails, "got some outgoing emails";
62 diag "non-ascii Subject with ascii prefix set in the template";
63 foreach my $set ( 'ru', 'latin1' ) {
64 my $ticket = RT::Ticket->new( RT->SystemUser );
67 Subject => $string{$set}{test},
68 Requestor => 'root@localhost',
70 my @mails = RT::Test->fetch_caught_mails;
71 ok @mails, "got some outgoing emails";
74 foreach my $mail ( @mails ) {
75 my $entity = parse_mail( $mail );
76 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
77 $subject =~ /$string{$set}{test}/
78 or do { $status = 0; diag "wrong subject: $subject" };
80 ok $status, "all mails have correct data";
83 foreach my $tag_set ( 'ru', 'latin1' ) {
85 diag "set non-ascii subject tag for the queue";
87 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
88 ok $status, "set subject tag for the queue" or diag "error: $msg";
91 diag "ascii subject with non-ascii subject tag";
93 my $ticket = RT::Ticket->new( RT->SystemUser );
97 Requestor => 'root@localhost',
99 my @mails = RT::Test->fetch_caught_mails;
100 ok @mails, "got some outgoing emails";
103 foreach my $mail ( @mails ) {
104 my $entity = parse_mail( $mail );
105 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
106 $subject =~ /$string{$tag_set}{support}/
107 or do { $status = 0; diag "wrong subject: $subject" };
109 ok $status, "all mails have correct data";
112 diag "non-ascii subject with non-ascii subject tag";
113 foreach my $set ( 'ru', 'latin1' ) {
114 my $ticket = RT::Ticket->new( RT->SystemUser );
117 Subject => $string{$set}{test},
118 Requestor => 'root@localhost',
120 my @mails = RT::Test->fetch_caught_mails;
121 ok @mails, "got some outgoing emails";
124 foreach my $mail ( @mails ) {
125 my $entity = parse_mail( $mail );
126 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
127 $subject =~ /$string{$tag_set}{support}/
128 or do { $status = 0; diag "wrong subject: $subject" };
129 $subject =~ /$string{$set}{test}/
130 or do { $status = 0; diag "wrong subject: $subject" };
132 ok $status, "all mails have correct data";
137 diag "return back the empty subject tag";
139 my ($status, $msg) = $queue->SetSubjectTag( undef );
140 ok $status, "set subject tag for the queue" or diag "error: $msg";
144 foreach my $prefix_set ( 'ru', 'latin1' ) {
146 diag "add non-ascii subject prefix in the autoreply template";
148 my $template = RT::Template->new( RT->SystemUser );
149 $template->Load('Autoreply');
150 ok $template->id, "loaded autoreply tempalte";
152 my ($status, $msg) = $template->SetContent(
153 "Subject: $string{$prefix_set}{autoreply} { \$Ticket->Subject }\n"
155 ."hi there it's an autoreply.\n"
158 ok $status, "changed content of the template" or diag "error: $msg";
161 diag "ascii subject with non-ascii subject prefix in template";
163 my $ticket = RT::Ticket->new( RT->SystemUser );
167 Requestor => 'root@localhost',
169 my @mails = RT::Test->fetch_caught_mails;
170 ok @mails, "got some outgoing emails";
173 foreach my $mail ( @mails ) {
174 my $entity = parse_mail( $mail );
175 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
176 $subject =~ /$string{$prefix_set}{autoreply}/
177 or do { $status = 0; diag "wrong subject: $subject" };
179 ok $status, "all mails have correct data";
182 diag "non-ascii subject with non-ascii subject prefix in template";
183 foreach my $set ( 'ru', 'latin1' ) {
184 my $ticket = RT::Ticket->new( RT->SystemUser );
187 Subject => $string{$set}{test},
188 Requestor => 'root@localhost',
190 my @mails = RT::Test->fetch_caught_mails;
191 ok @mails, "got some outgoing emails";
194 foreach my $mail ( @mails ) {
195 my $entity = parse_mail( $mail );
196 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
197 $subject =~ /$string{$prefix_set}{autoreply}/
198 or do { $status = 0; diag "wrong subject: $subject" };
199 $subject =~ /$string{$set}{test}/
200 or do { $status = 0; diag "wrong subject: $subject" };
202 ok $status, "all mails have correct data";
205 foreach my $tag_set ( 'ru', 'latin1' ) {
206 diag "set non-ascii subject tag for the queue";
208 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
209 ok $status, "set subject tag for the queue" or diag "error: $msg";
212 diag "non-ascii subject, non-ascii prefix in template and non-ascii tag";
213 foreach my $set ( 'ru', 'latin1' ) {
214 my $ticket = RT::Ticket->new( RT->SystemUser );
217 Subject => $string{$set}{test},
218 Requestor => 'root@localhost',
220 my @mails = RT::Test->fetch_caught_mails;
221 ok @mails, "got some outgoing emails";
224 foreach my $mail ( @mails ) {
225 my $entity = parse_mail( $mail );
226 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
227 $subject =~ /$string{$prefix_set}{autoreply}/
228 or do { $status = 0; diag "wrong subject: $subject" };
229 $subject =~ /$string{$tag_set}{support}/
230 or do { $status = 0; diag "wrong subject: $subject" };
231 $subject =~ /$string{$set}{test}/
232 or do { $status = 0; diag "wrong subject: $subject" };
234 ok $status, "all mails have correct data";
239 diag "flush subject tag of the queue";
241 my ($status, $msg) = $queue->SetSubjectTag( undef );
242 ok $status, "set subject tag for the queue" or diag "error: $msg";
248 diag "don't change subject via template";
249 # clean DB has autoreply that always changes subject in template,
250 # we should test situation when subject is not changed from template
252 my $template = RT::Template->new( RT->SystemUser );
253 $template->Load('Autoreply');
254 ok $template->id, "loaded autoreply tempalte";
256 my ($status, $msg) = $template->SetContent(
259 ."hi there it's an autoreply.\n"
262 ok $status, "changed content of the template" or diag "error: $msg";
265 diag "non-ascii Subject without changes in template";
266 foreach my $set ( 'ru', 'latin1' ) {
267 my $ticket = RT::Ticket->new( RT->SystemUser );
270 Subject => $string{$set}{test},
271 Requestor => 'root@localhost',
273 my @mails = RT::Test->fetch_caught_mails;
274 ok @mails, "got some outgoing emails";
277 foreach my $mail ( @mails ) {
278 my $entity = parse_mail( $mail );
279 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
280 $subject =~ /$string{$set}{test}/
281 or do { $status = 0; diag "wrong subject: $subject" };
283 ok $status, "all mails have correct data";
286 foreach my $tag_set ( 'ru', 'latin1' ) {
287 diag "set non-ascii subject tag for the queue";
289 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
290 ok $status, "set subject tag for the queue" or diag "error: $msg";
293 diag "non-ascii Subject without changes in template and with non-ascii subject tag";
294 foreach my $set ( 'ru', 'latin1' ) {
295 my $ticket = RT::Ticket->new( RT->SystemUser );
298 Subject => $string{$set}{test},
299 Requestor => 'root@localhost',
301 my @mails = RT::Test->fetch_caught_mails;
302 ok @mails, "got some outgoing emails";
305 foreach my $mail ( @mails ) {
306 my $entity = parse_mail( $mail );
307 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
308 $subject =~ /$string{$set}{test}/
309 or do { $status = 0; diag "wrong subject: $subject" };
310 $subject =~ /$string{$tag_set}{support}/
311 or do { $status = 0; diag "wrong subject: $subject" };
313 ok $status, "all mails have correct data";