charsets-outgoing-plaintext.t 9.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use strict;
use warnings;
use Encode;

use RT::Test tests => 79, text_templates => 1;

my %string = (
    ru => {
        test      => "\x{442}\x{435}\x{441}\x{442}",
        autoreply => "\x{410}\x{432}\x{442}\x{43e}\x{43e}\x{442}\x{432}\x{435}\x{442}",
        support   => "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}",
    },
    latin1 => {
        test      => Encode::decode('latin1', "t\xE9st"),
        autoreply => Encode::decode('latin1', "a\xFCtoreply"),
        support   => Encode::decode('latin1', "supp\xF5rt"),
    },
);

my $queue = RT::Test->load_or_create_queue(
    Name              => 'Regression',
    CorrespondAddress => 'rt-recipient@example.com',
    CommentAddress    => 'rt-recipient@example.com',
);
ok $queue && $queue->id, 'loaded or created queue';

diag "make sure queue has no subject tag";
{
    my ($status, $msg) = $queue->SetSubjectTag( undef );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}

diag "set intial simple autoreply template";
{
    my $template = RT::Template->new( RT->SystemUser );
    $template->Load('Autoreply');
    ok $template->id, "loaded autoreply tempalte";

    my ($status, $msg) = $template->SetContent(
        "Subject: Autreply { \$Ticket->Subject }\n"
        ."\n"
        ."hi there it's an autoreply.\n"
        ."\n"
    );
    ok $status, "changed content of the template"
        or diag "error: $msg";
}

diag "basic test of autoreply";
{
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => 'test',
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";
}

diag "non-ascii Subject with ascii prefix set in the template";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
75
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

foreach my $tag_set ( 'ru', 'latin1' ) {

diag "set non-ascii subject tag for the queue";
{
    my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}

diag "ascii subject with non-ascii subject tag";
{
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => 'test',
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
104
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        $subject =~ /$string{$tag_set}{support}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

diag "non-ascii subject with non-ascii subject tag";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
125
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        $subject =~ /$string{$tag_set}{support}/
            or do { $status = 0; diag "wrong subject: $subject" };
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

} # subject tag

diag "return back the empty subject tag";
{
    my ($status, $msg) = $queue->SetSubjectTag( undef );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}


foreach my $prefix_set ( 'ru', 'latin1' ) {

diag "add non-ascii subject prefix in the autoreply template";
{
    my $template = RT::Template->new( RT->SystemUser );
    $template->Load('Autoreply');
    ok $template->id, "loaded autoreply tempalte";

    my ($status, $msg) = $template->SetContent(
        "Subject: $string{$prefix_set}{autoreply} { \$Ticket->Subject }\n"
        ."\n"
        ."hi there it's an autoreply.\n"
        ."\n"
    );
    ok $status, "changed content of the template" or diag "error: $msg";
}

diag "ascii subject with non-ascii subject prefix in template";
{
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => 'test',
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
174
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
        $subject =~ /$string{$prefix_set}{autoreply}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

diag "non-ascii subject with non-ascii subject prefix in template";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
195
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
        $subject =~ /$string{$prefix_set}{autoreply}/
            or do { $status = 0; diag "wrong subject: $subject" };
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

foreach my $tag_set ( 'ru', 'latin1' ) {
diag "set non-ascii subject tag for the queue";
{
    my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}

diag "non-ascii subject, non-ascii prefix in template and non-ascii tag";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
225
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
        $subject =~ /$string{$prefix_set}{autoreply}/
            or do { $status = 0; diag "wrong subject: $subject" };
        $subject =~ /$string{$tag_set}{support}/
            or do { $status = 0; diag "wrong subject: $subject" };
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

} # subject tag

diag "flush subject tag of the queue";
{
    my ($status, $msg) = $queue->SetSubjectTag( undef );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}

} # prefix set


diag "don't change subject via template";
# clean DB has autoreply that always changes subject in template,
# we should test situation when subject is not changed from template
{
    my $template = RT::Template->new( RT->SystemUser );
    $template->Load('Autoreply');
    ok $template->id, "loaded autoreply tempalte";

    my ($status, $msg) = $template->SetContent(
        "\n"
        ."\n"
        ."hi there it's an autoreply.\n"
        ."\n"
    );
    ok $status, "changed content of the template" or diag "error: $msg";
}

diag "non-ascii Subject without changes in template";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
278
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

foreach my $tag_set ( 'ru', 'latin1' ) {
diag "set non-ascii subject tag for the queue";
{
    my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
    ok $status, "set subject tag for the queue" or diag "error: $msg";
}

diag "non-ascii Subject without changes in template and with non-ascii subject tag";
foreach my $set ( 'ru', 'latin1' ) {
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Create(
        Queue => $queue->id,
        Subject => $string{$set}{test},
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    ok @mails, "got some outgoing emails";

    my $status = 1;
    foreach my $mail ( @mails ) {
        my $entity = parse_mail( $mail );
306
        my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') );
307
308
309
310
311
312
313
314
315
316
        $subject =~ /$string{$set}{test}/
            or do { $status = 0; diag "wrong subject: $subject" };
        $subject =~ /$string{$tag_set}{support}/
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

} # subject tag set