5 use RT::Test tests => 78;
9 test => "\x{442}\x{435}\x{441}\x{442}",
10 autoreply => "\x{410}\x{432}\x{442}\x{43e}\x{43e}\x{442}\x{432}\x{435}\x{442}",
11 support => "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}",
14 test => Encode::decode('latin1', "t\xE9st"),
15 autoreply => Encode::decode('latin1', "a\xFCtoreply"),
16 support => Encode::decode('latin1', "supp\xF5rt"),
20 my $queue = RT::Test->load_or_create_queue(
22 CorrespondAddress => 'rt-recipient@example.com',
23 CommentAddress => 'rt-recipient@example.com',
25 ok $queue && $queue->id, 'loaded or created queue';
27 diag "make sure queue has no subject tag";
29 my ($status, $msg) = $queue->SetSubjectTag( undef );
30 ok $status, "set subject tag for the queue" or diag "error: $msg";
33 diag "set intial simple autoreply template";
35 my $template = RT::Template->new( RT->SystemUser );
36 $template->Load('Autoreply');
37 ok $template->id, "loaded autoreply tempalte";
39 my ($status, $msg) = $template->SetContent(
40 "Subject: Autreply { \$Ticket->Subject }\n"
42 ."hi there it's an autoreply.\n"
45 ok $status, "changed content of the template"
46 or diag "error: $msg";
49 diag "basic test of autoreply";
51 my $ticket = RT::Ticket->new( RT->SystemUser );
55 Requestor => 'root@localhost',
57 my @mails = RT::Test->fetch_caught_mails;
58 ok @mails, "got some outgoing emails";
61 diag "non-ascii Subject with ascii prefix set in the template";
62 foreach my $set ( 'ru', 'latin1' ) {
63 my $ticket = RT::Ticket->new( RT->SystemUser );
66 Subject => $string{$set}{test},
67 Requestor => 'root@localhost',
69 my @mails = RT::Test->fetch_caught_mails;
70 ok @mails, "got some outgoing emails";
73 foreach my $mail ( @mails ) {
74 my $entity = parse_mail( $mail );
75 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
76 $subject =~ /$string{$set}{test}/
77 or do { $status = 0; diag "wrong subject: $subject" };
79 ok $status, "all mails have correct data";
82 foreach my $tag_set ( 'ru', 'latin1' ) {
84 diag "set non-ascii subject tag for the queue";
86 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
87 ok $status, "set subject tag for the queue" or diag "error: $msg";
90 diag "ascii subject with non-ascii subject tag";
92 my $ticket = RT::Ticket->new( RT->SystemUser );
96 Requestor => 'root@localhost',
98 my @mails = RT::Test->fetch_caught_mails;
99 ok @mails, "got some outgoing emails";
102 foreach my $mail ( @mails ) {
103 my $entity = parse_mail( $mail );
104 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
105 $subject =~ /$string{$tag_set}{support}/
106 or do { $status = 0; diag "wrong subject: $subject" };
108 ok $status, "all mails have correct data";
111 diag "non-ascii subject with non-ascii subject tag";
112 foreach my $set ( 'ru', 'latin1' ) {
113 my $ticket = RT::Ticket->new( RT->SystemUser );
116 Subject => $string{$set}{test},
117 Requestor => 'root@localhost',
119 my @mails = RT::Test->fetch_caught_mails;
120 ok @mails, "got some outgoing emails";
123 foreach my $mail ( @mails ) {
124 my $entity = parse_mail( $mail );
125 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
126 $subject =~ /$string{$tag_set}{support}/
127 or do { $status = 0; diag "wrong subject: $subject" };
128 $subject =~ /$string{$set}{test}/
129 or do { $status = 0; diag "wrong subject: $subject" };
131 ok $status, "all mails have correct data";
136 diag "return back the empty subject tag";
138 my ($status, $msg) = $queue->SetSubjectTag( undef );
139 ok $status, "set subject tag for the queue" or diag "error: $msg";
143 foreach my $prefix_set ( 'ru', 'latin1' ) {
145 diag "add non-ascii subject prefix in the autoreply template";
147 my $template = RT::Template->new( RT->SystemUser );
148 $template->Load('Autoreply');
149 ok $template->id, "loaded autoreply tempalte";
151 my ($status, $msg) = $template->SetContent(
152 "Subject: $string{$prefix_set}{autoreply} { \$Ticket->Subject }\n"
154 ."hi there it's an autoreply.\n"
157 ok $status, "changed content of the template" or diag "error: $msg";
160 diag "ascii subject with non-ascii subject prefix in template";
162 my $ticket = RT::Ticket->new( RT->SystemUser );
166 Requestor => 'root@localhost',
168 my @mails = RT::Test->fetch_caught_mails;
169 ok @mails, "got some outgoing emails";
172 foreach my $mail ( @mails ) {
173 my $entity = parse_mail( $mail );
174 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
175 $subject =~ /$string{$prefix_set}{autoreply}/
176 or do { $status = 0; diag "wrong subject: $subject" };
178 ok $status, "all mails have correct data";
181 diag "non-ascii subject with non-ascii subject prefix in template";
182 foreach my $set ( 'ru', 'latin1' ) {
183 my $ticket = RT::Ticket->new( RT->SystemUser );
186 Subject => $string{$set}{test},
187 Requestor => 'root@localhost',
189 my @mails = RT::Test->fetch_caught_mails;
190 ok @mails, "got some outgoing emails";
193 foreach my $mail ( @mails ) {
194 my $entity = parse_mail( $mail );
195 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
196 $subject =~ /$string{$prefix_set}{autoreply}/
197 or do { $status = 0; diag "wrong subject: $subject" };
198 $subject =~ /$string{$set}{test}/
199 or do { $status = 0; diag "wrong subject: $subject" };
201 ok $status, "all mails have correct data";
204 foreach my $tag_set ( 'ru', 'latin1' ) {
205 diag "set non-ascii subject tag for the queue";
207 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
208 ok $status, "set subject tag for the queue" or diag "error: $msg";
211 diag "non-ascii subject, non-ascii prefix in template and non-ascii tag";
212 foreach my $set ( 'ru', 'latin1' ) {
213 my $ticket = RT::Ticket->new( RT->SystemUser );
216 Subject => $string{$set}{test},
217 Requestor => 'root@localhost',
219 my @mails = RT::Test->fetch_caught_mails;
220 ok @mails, "got some outgoing emails";
223 foreach my $mail ( @mails ) {
224 my $entity = parse_mail( $mail );
225 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
226 $subject =~ /$string{$prefix_set}{autoreply}/
227 or do { $status = 0; diag "wrong subject: $subject" };
228 $subject =~ /$string{$tag_set}{support}/
229 or do { $status = 0; diag "wrong subject: $subject" };
230 $subject =~ /$string{$set}{test}/
231 or do { $status = 0; diag "wrong subject: $subject" };
233 ok $status, "all mails have correct data";
238 diag "flush subject tag of the queue";
240 my ($status, $msg) = $queue->SetSubjectTag( undef );
241 ok $status, "set subject tag for the queue" or diag "error: $msg";
247 diag "don't change subject via template";
248 # clean DB has autoreply that always changes subject in template,
249 # we should test situation when subject is not changed from template
251 my $template = RT::Template->new( RT->SystemUser );
252 $template->Load('Autoreply');
253 ok $template->id, "loaded autoreply tempalte";
255 my ($status, $msg) = $template->SetContent(
258 ."hi there it's an autoreply.\n"
261 ok $status, "changed content of the template" or diag "error: $msg";
264 diag "non-ascii Subject without changes in template";
265 foreach my $set ( 'ru', 'latin1' ) {
266 my $ticket = RT::Ticket->new( RT->SystemUser );
269 Subject => $string{$set}{test},
270 Requestor => 'root@localhost',
272 my @mails = RT::Test->fetch_caught_mails;
273 ok @mails, "got some outgoing emails";
276 foreach my $mail ( @mails ) {
277 my $entity = parse_mail( $mail );
278 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
279 $subject =~ /$string{$set}{test}/
280 or do { $status = 0; diag "wrong subject: $subject" };
282 ok $status, "all mails have correct data";
285 foreach my $tag_set ( 'ru', 'latin1' ) {
286 diag "set non-ascii subject tag for the queue";
288 my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
289 ok $status, "set subject tag for the queue" or diag "error: $msg";
292 diag "non-ascii Subject without changes in template and with non-ascii subject tag";
293 foreach my $set ( 'ru', 'latin1' ) {
294 my $ticket = RT::Ticket->new( RT->SystemUser );
297 Subject => $string{$set}{test},
298 Requestor => 'root@localhost',
300 my @mails = RT::Test->fetch_caught_mails;
301 ok @mails, "got some outgoing emails";
304 foreach my $mail ( @mails ) {
305 my $entity = parse_mail( $mail );
306 my $subject = Encode::decode_utf8( $entity->head->get('Subject') );
307 $subject =~ /$string{$set}{test}/
308 or do { $status = 0; diag "wrong subject: $subject" };
309 $subject =~ /$string{$tag_set}{support}/
310 or do { $status = 0; diag "wrong subject: $subject" };
312 ok $status, "all mails have correct data";