charsets-outgoing.t 9.98 KB
Newer Older
1
2
use strict;
use warnings;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Encode;

use RT::Test tests => 78;

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"),
    },
);
19
20
21
22
23
24
25
26

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';

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

33
diag "set intial simple autoreply template";
34
{
35
    my $template = RT::Template->new( RT->SystemUser );
36
    $template->Load('Autoreply in HTML');
37
38
39
40
41
42
43
44
45
46
47
48
    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";
}

49
diag "basic test of autoreply";
50
{
51
    my $ticket = RT::Ticket->new( RT->SystemUser );
52
53
54
55
56
57
58
59
60
    $ticket->Create(
        Queue => $queue->id,
        Subject => 'test',
        Requestor => 'root@localhost',
    );
    my @mails = RT::Test->fetch_caught_mails;
    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 );
64
65
    $ticket->Create(
        Queue => $queue->id,
66
        Subject => $string{$set}{test},
67
68
69
70
71
72
73
74
        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
        $subject =~ /$string{$set}{test}/
77
78
79
80
81
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

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

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

90
diag "ascii subject with non-ascii subject tag";
91
{
92
    my $ticket = RT::Ticket->new( RT->SystemUser );
93
94
95
96
97
98
99
100
101
102
103
    $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
        $subject =~ /$string{$tag_set}{support}/
106
107
108
109
110
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    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 );
114
115
    $ticket->Create(
        Queue => $queue->id,
116
        Subject => $string{$set}{test},
117
118
119
120
121
122
123
124
        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
        $subject =~ /$string{$tag_set}{support}/
127
            or do { $status = 0; diag "wrong subject: $subject" };
128
        $subject =~ /$string{$set}{test}/
129
130
            or do { $status = 0; diag "wrong subject: $subject" };
    }
Alex Vandiver's avatar
Alex Vandiver committed
131
    ok $status, "all mails have correct data";
132
133
}

134
135
} # subject tag

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

142
143
144

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

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

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

160
diag "ascii subject with non-ascii subject prefix in template";
161
{
162
    my $ticket = RT::Ticket->new( RT->SystemUser );
163
164
165
166
167
168
169
170
171
172
173
    $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
        $subject =~ /$string{$prefix_set}{autoreply}/
176
177
178
179
180
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    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 );
184
185
    $ticket->Create(
        Queue => $queue->id,
186
        Subject => $string{$set}{test},
187
188
189
190
191
192
193
194
        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
        $subject =~ /$string{$prefix_set}{autoreply}/
197
            or do { $status = 0; diag "wrong subject: $subject" };
198
        $subject =~ /$string{$set}{test}/
199
200
201
202
203
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

204
foreach my $tag_set ( 'ru', 'latin1' ) {
205
diag "set non-ascii subject tag for the queue";
206
{
207
    my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
208
209
210
    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 );
214
215
    $ticket->Create(
        Queue => $queue->id,
216
        Subject => $string{$set}{test},
217
218
219
220
221
222
223
224
        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
        $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
232
            or do { $status = 0; diag "wrong subject: $subject" };
    }
Alex Vandiver's avatar
Alex Vandiver committed
233
    ok $status, "all mails have correct data";
234
235
}

236
237
} # subject tag

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

244
245
} # prefix set

246

247
diag "don't change subject via template";
248
249
# clean DB has autoreply that always changes subject in template,
# we should test situation when subject is not changed from template
250
{
251
    my $template = RT::Template->new( RT->SystemUser );
252
    $template->Load('Autoreply in HTML');
253
254
255
256
257
258
259
260
261
262
263
    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";
}

264
diag "non-ascii Subject without changes in template";
265
foreach my $set ( 'ru', 'latin1' ) {
266
    my $ticket = RT::Ticket->new( RT->SystemUser );
267
268
    $ticket->Create(
        Queue => $queue->id,
269
        Subject => $string{$set}{test},
270
271
272
273
274
275
276
277
        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
        $subject =~ /$string{$set}{test}/
280
281
282
283
284
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

285
foreach my $tag_set ( 'ru', 'latin1' ) {
286
diag "set non-ascii subject tag for the queue";
287
{
288
    my ($status, $msg) = $queue->SetSubjectTag( $string{$tag_set}{support} );
289
290
291
    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 );
295
296
    $ticket->Create(
        Queue => $queue->id,
297
        Subject => $string{$set}{test},
298
299
300
301
302
303
304
305
        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
        $subject =~ /$string{$set}{test}/
308
            or do { $status = 0; diag "wrong subject: $subject" };
309
        $subject =~ /$string{$tag_set}{support}/
310
311
312
313
314
            or do { $status = 0; diag "wrong subject: $subject" };
    }
    ok $status, "all mails have correct data";
}

315
316
} # subject tag set