1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9use strict;
10use warnings;
11use utf8;
12
13use vars (qw($Self));
14
15use Kernel::System::EmailParser;
16
17# get main object
18my $MainObject = $Kernel::OM->Get('Kernel::System::Main');
19
20my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
21
22# test #1
23my @Array = ();
24open( my $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test1.box" );    ## no critic
25while (<$IN>) {
26    push( @Array, $_ );
27}
28close($IN);
29
30# create local object
31my $EmailParserObject = Kernel::System::EmailParser->new(
32    Email => \@Array,
33);
34
35$Self->Is(
36    $EmailParserObject->GetParam( WHAT => 'To' ),
37    'darthvader@otrs.org',
38    "#1 GetParam(WHAT => 'To')",
39);
40
41$Self->Is(
42    $EmailParserObject->GetParam( WHAT => 'From' ),
43    'Skywalker Attachment <skywalker@otrs.org>',
44    "#1 GetParam(WHAT => 'From')",
45);
46
47$Self->Is(
48    $EmailParserObject->GetCharset(),
49    'us-ascii',
50    "#1 GetCharset()",
51);
52
53my @Attachments = $EmailParserObject->GetAttachments();
54$Self->False(
55    $Attachments[1]->{Filename} || '',
56    "#1 GetAttachments() - no attachments",
57);
58
59# test #2
60my @Addresses = $EmailParserObject->SplitAddressLine(
61    Line => 'Juergen Weber <juergen.qeber@air.com>, me@example.com, hans@example.com (Hans Huber),
62        Juergen "quoted name" Weber <juergen.qeber@air.com>',
63);
64
65$Self->Is(
66    $Addresses[2],
67    'hans@example.com (Hans Huber)',
68    "#2 SplitAddressLine()",
69);
70
71$Self->Is(
72    $Addresses[3],
73    'Juergen "quoted name" Weber <juergen.qeber@air.com>',
74    "#2 SplitAddressLine() with quoted name",
75);
76
77$Self->Is(
78    $EmailParserObject->GetEmailAddress( Email => 'Juergen Weber <juergen.qeber@air.com>' ),
79    'juergen.qeber@air.com',
80    "#1 GetEmailAddress()",
81);
82
83$Self->Is(
84    $EmailParserObject->GetEmailAddress( Email => 'Juergen Weber <juergen+qeber@air.com>' ),
85    'juergen+qeber@air.com',
86    "#1 GetEmailAddress()",
87);
88
89$Self->Is(
90    $EmailParserObject->GetEmailAddress(
91        Email => 'Juergen Weber <juergen+qeber@air.com> (Comment)'
92    ),
93    'juergen+qeber@air.com',
94    "#1 GetEmailAddress()",
95);
96
97$Self->Is(
98    $EmailParserObject->GetEmailAddress( Email => 'juergen+qeber@air.com (Comment)' ),
99    'juergen+qeber@air.com',
100    "#1 GetEmailAddress()",
101);
102
103$Self->Is(
104    $EmailParserObject->GetRealname( Email => '"Juergen "quoted name" Weber" <juergen.qeber@air.com>' ),
105    'Juergen "quoted name" Weber',
106    "#1 GetRealname() with quoted name",
107);
108
109$Self->Is(
110    $EmailParserObject->GetRealname( Email => '"Juergen " quoted name " Weber" <juergen.qeber@air.com>' ),
111    'Juergen "quoted name" Weber',
112    "#1 GetRealname() with quoted name",
113);
114
115# test #3
116@Array = ();
117open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test3.box" );    ## no critic
118while (<$IN>) {
119    push( @Array, $_ );
120}
121close($IN);
122
123$EmailParserObject = Kernel::System::EmailParser->new(
124    Email => \@Array,
125);
126$Self->Is(
127    $EmailParserObject->GetCharset(),
128    'utf-8',                                                                       # automatically converted
129    "#3 GetCharset()",
130);
131@Attachments = $EmailParserObject->GetAttachments();
132my $MD5 = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
133$Self->Is(
134    $MD5,
135    '4e78ae6bffb120669f50bca56965f552',
136    "#3 md5 check",
137);
138$Self->Is(
139    $Attachments[1]->{Filename},
140    'utf-8-file-äöüß-カスタマ.txt',
141    "#3 GetAttachments()",
142);
143
144# test #4
145@Array = ();
146open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test4.box" );    ## no critic
147while (<$IN>) {
148    push( @Array, $_ );
149}
150close($IN);
151
152$EmailParserObject = Kernel::System::EmailParser->new(
153    Email => \@Array,
154);
155$Self->Is(
156    $EmailParserObject->GetCharset(),
157    'iso-8859-15',
158    "#4 GetCharset()",
159);
160$Self->Is(
161    $EmailParserObject->GetParam( WHAT => 'From' ),
162    'Hans BÄKOSchönland <me@bogen.net>',
163    "#4 From()",
164);
165$Self->Is(
166    $EmailParserObject->GetParam( WHAT => 'To' ),
167    'Namedyński (hans@example.com)',
168    "#4 To()",
169);
170$Self->Is(
171    $EmailParserObject->GetParam( WHAT => 'Subject' ),
172    'utf8: 使って / ISO-8859-1: Priorität"  / cp-1251: Сергей Углицких',
173    "#4 Subject()",
174);
175
176# match values
177my %Match = (
178    "Test1:" . chr(8211)              => 0,
179    "Test2:&"                         => 0,
180    "Test3:" . chr(8715)              => 0,
181    "Test4:&"                         => 0,
182    "Test5:" . chr( hex("3d") )       => 0,
183    "Compare Cable, DSL or Satellite" => 0,
184);
185for my $Key ( sort keys %Match ) {
186    if ( $EmailParserObject->GetMessageBody() =~ /$Key/ ) {
187        $Match{$Key} = 1;
188    }
189    $Self->True(
190        $Match{$Key},
191        "#4 html2ascii - Body match - $Key",
192    );
193}
194
195# match values not
196my %MatchNot = (
197    "style"      => 0,
198    "background" => 0,
199    "br"         => 0,
200    "div"        => 0,
201    "html"       => 0,
202);
203for my $Key ( sort keys %MatchNot ) {
204    if ( $EmailParserObject->GetMessageBody() !~ /$Key/ ) {
205        $MatchNot{$Key} = 1;
206    }
207    $Self->True(
208        $MatchNot{$Key},
209        "#4 html2ascii - Body match not - $Key",
210    );
211}
212
213# test #5
214@Array = ();
215open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test5.box" );    ## no critic
216while (<$IN>) {
217    push( @Array, $_ );
218}
219close($IN);
220
221$EmailParserObject = Kernel::System::EmailParser->new(
222    Email => \@Array,
223);
224$Self->Is(
225    $EmailParserObject->GetCharset(),
226    'utf-8',                                                                       # automatically converted
227    "#5 GetCharset()",
228);
229@Attachments = $EmailParserObject->GetAttachments();
230$MD5         = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
231$Self->Is(
232    $MD5,
233    '0596f2939525c6bd50fc2b649e40fbb6',
234    "#5 md5 check",
235);
236$Self->Is(
237    $Attachments[1]->{Filename},
238    'test-attachment-äöüß-iso-8859-1.txt',
239    "#5 GetAttachments()",
240);
241$Self->Is(
242    $Attachments[1]->{ContentAlternative} || '',
243    '',
244    "#5 ContentAlternative check",
245);
246$MD5 = $MainObject->MD5sum( String => $Attachments[2]->{Content} ) || '';
247$Self->Is(
248    $MD5,
249    'bb29962e132ba159539f1e88b41663b1',
250    "#5 md5 check",
251);
252$Self->Is(
253    $Attachments[2]->{Filename},
254    'test-attachment-äöüß-utf-8.txt',
255    "#5 GetAttachments()",
256);
257$MD5 = $MainObject->MD5sum( String => $Attachments[3]->{Content} ) || '';
258$Self->Is(
259    $MD5,
260    '5ee767f3b68f24a9213e0bef82dc53e5',
261    "#5 md5 check",
262);
263$Self->Is(
264    $Attachments[3]->{Filename},
265    'test-attachment-äöüß.pdf',
266    "#5 GetAttachments()",
267);
268
269# test #6
270@Array = ();
271open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test6.box" );    ## no critic
272while (<$IN>) {
273    push( @Array, $_ );
274}
275close($IN);
276
277$EmailParserObject = Kernel::System::EmailParser->new(
278    Email => \@Array,
279);
280$Self->Is(
281    $EmailParserObject->GetCharset(),
282    'utf-8',
283    "#6 GetCharset()",
284);
285@Attachments = $EmailParserObject->GetAttachments();
286$MD5         = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
287$Self->Is(
288    $MD5,
289    '5ee767f3b68f24a9213e0bef82dc53e5',
290    "#6 md5 check",
291);
292$Self->Is(
293    $Attachments[1]->{Filename},
294    'test-attachment-äöüß.pdf',
295    "#6 GetAttachments()",
296);
297
298$MD5 = $MainObject->MD5sum( String => $Attachments[2]->{Content} ) || '';
299$Self->Is(
300    $MD5,
301    'bb29962e132ba159539f1e88b41663b1',
302    "#6 md5 check",
303);
304$Self->Is(
305    $Attachments[2]->{Filename},
306    'test-attachment-äöüß-utf-8.txt',
307    "#6 GetAttachments()",
308);
309
310$MD5 = $MainObject->MD5sum( String => $Attachments[3]->{Content} ) || '';
311$Self->Is(
312    $MD5,
313    '0596f2939525c6bd50fc2b649e40fbb6',
314    "#6 md5 check",
315);
316$Self->Is(
317    $Attachments[3]->{Filename},
318    'test-attachment-äöüß-iso-8859-1.txt',
319    "#6 GetAttachments()",
320);
321
322# test #7
323@Array = ();
324open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test7.box" );    ## no critic
325while (<$IN>) {
326    push( @Array, $_ );
327}
328close($IN);
329
330$EmailParserObject = Kernel::System::EmailParser->new(
331    Email => \@Array,
332);
333$Self->Is(
334    $EmailParserObject->GetCharset(),
335    'utf-8',                                                                       # automatically converted
336    "#7 GetCharset()",
337);
338@Attachments = $EmailParserObject->GetAttachments();
339$MD5         = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
340$Self->Is(
341    $MD5,
342    '5ee767f3b68f24a9213e0bef82dc53e5',
343    "#7 md5 check",
344);
345$Self->Is(
346    $Attachments[1]->{Filename},
347    'test-attachment-äöüß.pdf',
348    "#7 GetAttachments()",
349);
350$MD5 = $MainObject->MD5sum( String => $Attachments[2]->{Content} ) || '';
351$Self->Is(
352    $MD5,
353    'bb29962e132ba159539f1e88b41663b1',
354    "#7 md5 check",
355);
356$Self->Is(
357    $Attachments[2]->{Filename},
358    'test-attachment-äöüß-utf-8.txt',
359    "#7 GetAttachments()",
360);
361$MD5 = $MainObject->MD5sum( String => $Attachments[3]->{Content} ) || '';
362$Self->Is(
363    $MD5,
364    '0596f2939525c6bd50fc2b649e40fbb6',
365    "#7 md5 check",
366);
367$Self->Is(
368    $Attachments[3]->{Filename},
369    'test-attachment-äöüß-iso-8859-1.txt',
370    "#7 GetAttachments()",
371);
372
373# test #8
374@Array = ();
375open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test8.box" );    ## no critic
376while (<$IN>) {
377    push( @Array, $_ );
378}
379close($IN);
380
381$EmailParserObject = Kernel::System::EmailParser->new(
382    Email => \@Array,
383);
384$Self->Is(
385    $EmailParserObject->GetCharset(),
386    '',
387    "#8 GetCharset() - no charset should be found (non text body)",
388);
389
390my $Body = $EmailParserObject->GetMessageBody();
391@Attachments = $EmailParserObject->GetAttachments();
392$MD5         = $MainObject->MD5sum( String => $Body ) || '';
393
394$Self->Is(
395    $MD5,
396    '5ee767f3b68f24a9213e0bef82dc53e5',
397    "#8 md5 check",
398);
399
400$Self->True(
401    !$Attachments[0] || 0,
402    "#8 no attachment check",
403);
404
405# test #9
406@Array = ();
407open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test9.box" );    ## no critic
408while (<$IN>) {
409    push( @Array, $_ );
410}
411close($IN);
412
413$EmailParserObject = Kernel::System::EmailParser->new(
414    Email => \@Array,
415);
416$Self->Is(
417    $EmailParserObject->GetCharset(),
418    'us-ascii',
419    "#9 GetCharset() - us-ascii charset should be found",
420);
421
422@Attachments = $EmailParserObject->GetAttachments();
423$MD5         = $MainObject->MD5sum( String => $Attachments[0]->{Content} ) || '';
424
425$Self->Is(
426    $MD5,
427    '5ee767f3b68f24a9213e0bef82dc53e5',
428    "#9 md5 check",
429);
430
431$Self->True(
432    $Attachments[0] || 0,
433    "#9 attachment check #1",
434);
435
436$Self->True(
437    !$Attachments[1] || 0,
438    "#9 attachment check #2",
439);
440
441# test #10
442@Array = ();
443open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test10.box" );    ## no critic
444while (<$IN>) {
445    push( @Array, $_ );
446}
447close($IN);
448
449$EmailParserObject = Kernel::System::EmailParser->new(
450    Email => \@Array,
451);
452$Self->Is(
453    $EmailParserObject->GetCharset(),
454    'iso-8859-1',
455    "#10 GetCharset() - iso-8859-1 charset should be found",
456);
457
458$MD5 = $MainObject->MD5sum( String => $EmailParserObject->GetMessageBody() ) || '';
459$Self->Is(
460    $MD5,
461    '7ddc731e5a3e76cd27d4b1e0628468b1',
462    "#10 md5 body check",
463);
464
465@Attachments = $EmailParserObject->GetAttachments();
466$MD5         = $MainObject->MD5sum( String => $Attachments[0]->{Content} ) || '';
467$Self->Is(
468    $MD5,
469    '7ddc731e5a3e76cd27d4b1e0628468b1',
470    "#10 md5 check",
471);
472
473$Self->True(
474    $Attachments[0] || 0,
475    "#10 attachment check #1",
476);
477
478$Self->True(
479    $Attachments[1] || 0,
480    "#10 attachment check #2",
481);
482
483$Self->True(
484    $Attachments[2] || 0,
485    "#10 attachment check #3",
486);
487
488$Self->True(
489    !$Attachments[3] || 0,
490    "#10 attachment check #4",
491);
492
493# test #11
494@Array = ();
495open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test11.box" );    ## no critic
496while (<$IN>) {
497    push( @Array, $_ );
498}
499close($IN);
500
501$EmailParserObject = Kernel::System::EmailParser->new(
502    Email => \@Array,
503);
504$Self->Is(
505    $EmailParserObject->GetCharset(),
506    'ISO-8859-1',
507    "#11 GetCharset() - iso-8859-1 charset should be found",
508);
509
510$MD5 = $MainObject->MD5sum( String => $EmailParserObject->GetMessageBody() ) || '';
511$Self->Is(
512    $MD5,
513    '52f20c90a1f0d8cf3bd415e278992001',
514    "#11 md5 body check",
515);
516
517@Attachments = $EmailParserObject->GetAttachments();
518$Self->True(
519    !$Attachments[0] || 0,
520    "#11 attachment check #0",
521);
522
523# test #12
524@Array = ();
525open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test12.box" );    ## no critic
526while (<$IN>) {
527    push( @Array, $_ );
528}
529close($IN);
530
531$EmailParserObject = Kernel::System::EmailParser->new(
532    Email => \@Array,
533);
534$Self->Is(
535    $EmailParserObject->GetCharset(),
536    'utf-8',                                                                        # automatically converted
537    "#12 GetCharset() - iso-8859-1 charset should be found",
538);
539$Self->Is(
540    $EmailParserObject->GetParam( WHAT => 'To' ),
541    '金田 美羽 <support@example.com>',
542    "#12 GetParam(WHAT => 'To')",
543);
544$Self->Is(
545    $EmailParserObject->GetParam( WHAT => 'Cc' ),
546    '張雅惠 <support2@example.com>, "문화연대" <support3@example.com>',
547    "#12 GetParam(WHAT => 'Cc')",
548);
549
550$MD5 = $MainObject->MD5sum( String => $EmailParserObject->GetMessageBody() ) || '';
551$Self->Is(
552    $MD5,
553    '603c11a38065909cc13bf53c650506c1',
554    "#12 md5 body check",
555);
556
557@Attachments = $EmailParserObject->GetAttachments();
558$MD5         = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
559$Self->Is(
560    $MD5,
561    'ecfbec2030e6bf91cc97ed22f7c6551a',
562    "#12 md5 check",
563);
564$Self->Is(
565    $Attachments[1]->{Filename} || '',
566    'attachment-äöüß-utf8.txt',
567    "#12 Filename check",
568);
569$MD5 = $MainObject->MD5sum( String => $Attachments[2]->{Content} ) || '';
570$Self->Is(
571    $MD5,
572    'b25beeea18c52cdc791864b52862743e',
573    "#12 md5 check",
574);
575$Self->Is(
576    $Attachments[2]->{Filename} || '',
577    'attachment-äöüß-iso.txt',
578    "#12 Filename check",
579);
580$MD5 = $MainObject->MD5sum( String => $Attachments[3]->{Content} ) || '';
581$Self->Is(
582    $MD5,
583    'f287d0dd6d0f90da4ac69348b09ec281',
584    "#12 md5 check",
585);
586$Self->Is(
587    $Attachments[3]->{Filename} || '',
588    'Обяснительная.jpg',
589    "#12 Filename check",
590);
591$MD5 = $MainObject->MD5sum( String => $Attachments[4]->{Content} ) || '';
592$Self->Is(
593    $MD5,
594    'f287d0dd6d0f90da4ac69348b09ec281',
595    "#12 md5 check",
596);
597$Self->Is(
598    $Attachments[4]->{Filename} || '',
599    'Сообщение.jpg',
600    "#12 Filename check",
601);
602$Self->Is(
603    $Attachments[5]->{Filename} || '',
604    '報告書_..txt',
605    "#12 Filename check",
606);
607$Self->Is(
608    $Attachments[6]->{Filename} || '',
609    '金田_美羽',
610    "#12 Filename check",
611);
612$Self->Is(
613    $Attachments[7]->{Filename} || '',
614    '國科會50科學之旅活動計畫徵求書_r_final_.doc',
615    "#12 Filename check",
616);
617$Self->Is(
618    $Attachments[8]->{Filename} || '',
619    '2차_보도자료.hwp',
620    "#12 Filename check",
621);
622$Self->True(
623    !$Attachments[9] || 0,
624    "#12 attachment check #0",
625);
626
627# test #13
628@Array = ();
629open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test13.box" );    ## no critic
630while (<$IN>) {
631    push( @Array, $_ );
632}
633close($IN);
634
635$EmailParserObject = Kernel::System::EmailParser->new(
636    Email => \@Array,
637);
638$Self->Is(
639    $EmailParserObject->GetCharset(),
640    '',
641    "#13 GetCharset() - no charset should be found",
642);
643$Self->Is(
644    $EmailParserObject->GetParam( WHAT => 'To' ),
645    'support@example.com',
646    "#13 GetParam(WHAT => 'To')",
647);
648$MD5 = $MainObject->MD5sum( String => $EmailParserObject->GetMessageBody() ) || '';
649$Self->Is(
650    $MD5,
651    '474f97c23688e88edfb70139d5658e01',
652    "#13 md5 body check",
653);
654
655# test #14
656@Array = ();
657open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test14.box" );    ## no critic
658while (<$IN>) {
659    push( @Array, $_ );
660}
661close($IN);
662
663$EmailParserObject = Kernel::System::EmailParser->new(
664    Email => \@Array,
665);
666$Self->Is(
667    $EmailParserObject->GetCharset(),
668    'UTF-8',
669    "#14 GetCharset() - no charset should be found",
670);
671$Self->Is(
672    $EmailParserObject->GetParam( WHAT => 'To' ),
673    'security@example.org',
674    "#14 GetParam(WHAT => 'To')",
675);
676$Self->Is(
677    $EmailParserObject->GetParam( WHAT => 'From' ),
678    '"VIAGRA � Official Site" <security@example.org>',
679    "#14 GetParam(WHAT => 'From')",
680);
681$MD5 = $MainObject->MD5sum( String => $EmailParserObject->GetMessageBody() ) || '';
682$Self->Is(
683    $MD5,
684    'b8b01a1acd8fe7efeff8351bf48d8f63',
685    "#14 md5 body check",
686);
687
688# test #15
689@Array = ();
690open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test16.box" );    ## no critic
691while (<$IN>) {
692    push( @Array, $_ );
693}
694close($IN);
695
696$EmailParserObject = Kernel::System::EmailParser->new(
697    Email => \@Array,
698);
699$Self->Is(
700    $EmailParserObject->GetCharset(),
701    'ISO-8859-1',
702    "#15 GetCharset() - iso-8859-1 charset should be found",
703);
704
705@Attachments = $EmailParserObject->GetAttachments();
706$MD5         = $MainObject->MD5sum( String => $Attachments[1]->{Content} ) || '';
707$Self->Is(
708    $MD5,
709    'e86c2c15e59fc1e1695f890ff102b06c',
710    "#15 md5 check",
711);
712$Self->Is(
713    $Attachments[0]->{ContentAlternative} || '',
714    1,
715    "#15 ContentAlternative check",
716);
717$Self->Is(
718    $Attachments[1]->{ContentAlternative} || '',
719    1,
720    "#15 ContentAlternative check",
721);
722
723# content type tests
724my @Tests = (
725    {
726        ContentType => 'Content-Type: text/plain; charset="iso-8859-1"; charset="iso-8859-1"',
727        Charset     => 'iso-8859-1',
728        MimeType    => 'text/plain',
729    },
730    {
731        ContentType => 'Content-Type: text/plain; charset="iso-8859-1"',
732        Charset     => 'iso-8859-1',
733        MimeType    => 'text/plain',
734    },
735    {
736        ContentType => 'Content-Type: text/xls-2; charset="iso-8859-1";',
737        Charset     => 'iso-8859-1',
738        MimeType    => 'text/xls-2',
739    },
740    {
741        ContentType => 'Content-Type: text/plain; charset="iso-8859-1"; format=flowed',
742        Charset     => 'iso-8859-1',
743        MimeType    => 'text/plain',
744    },
745    {
746        ContentType => 'Content-Type: text/plain; charset="utf8"; format=flowed',
747        Charset     => 'utf8',
748        MimeType    => 'text/plain',
749    },
750    {
751        ContentType => 'Content-Type: text/plain; charset=iso-8859-1',
752        Charset     => 'iso-8859-1',
753        MimeType    => 'text/plain',
754    },
755    {
756        ContentType => 'Content-Type: text/plain; charset=\'iso-8859-1\'',
757        Charset     => 'iso-8859-1',
758        MimeType    => 'text/plain',
759    },
760    {
761        ContentType => 'Content-Type:text/plain; charset=\'iso-8859-1\'',
762        Charset     => 'iso-8859-1',
763        MimeType    => 'text/plain',
764    },
765    {
766        ContentType => 'Content-Type: text/plain; charset = "utf8"; format=flowed',
767        Charset     => 'utf8',
768        MimeType    => 'text/plain',
769    },
770);
771
772for my $Test (@Tests) {
773    my %Data = $EmailParserObject->GetContentTypeParams(
774        ContentType => $Test->{ContentType},
775    );
776    $Self->Is(
777        $Data{Charset},
778        $Test->{Charset},
779        "#16 ContentType - Charset check",
780    );
781    $Self->Is(
782        $Data{MimeType},
783        $Test->{MimeType},
784        "#16 MimeType - Charset check",
785    );
786}
787
788# test #17
789@Array = ();
790open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test19.box" );    ## no critic
791while (<$IN>) {
792    push( @Array, $_ );
793}
794close($IN);
795
796$EmailParserObject = Kernel::System::EmailParser->new(
797    Email => \@Array,
798);
799$Self->Is(
800    $EmailParserObject->GetCharset(),
801    'iso-8859-1',
802    "#17 GetCharset() - iso-8859-1 charset should be found",
803);
804
805#test #18
806my $ContentType = qq(Content-Type: text/html; charset="iso-8859-1"; charset="iso-8859-1");
807my %Data        = $EmailParserObject->GetContentTypeParams(
808    ContentType => $ContentType,
809);
810$Self->Is(
811    $Data{Charset},
812    'iso-8859-1',
813    "#18 ContentType - iso-8859-1 charset should be found",
814);
815
816# test #20
817@Array = ();
818open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test20.box" );    ## no critic
819while (<$IN>) {
820    push( @Array, $_ );
821}
822close($IN);
823
824$EmailParserObject = Kernel::System::EmailParser->new(
825    Email => \@Array,
826);
827
828@Attachments = $EmailParserObject->GetAttachments();
829my $ContentLocation;
830
831ATTACHMENT:
832for my $Attachment (@Attachments) {
833    next ATTACHMENT if $Attachment->{ContentType} ne 'image/bmp; name="ole0.bmp"';
834    $ContentLocation = $Attachment->{ContentID};
835}
836
837$Self->Is(
838    $ContentLocation,
839    'Untitled%20Attachment',
840    "#20 Get Content-Location",
841);
842
843# test #21
844@Array = ();
845open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test21.box" );    ## no critic
846while (<$IN>) {
847    push( @Array, $_ );
848}
849close($IN);
850
851$EmailParserObject = Kernel::System::EmailParser->new(
852    Email => \@Array,
853);
854
855$Self->Is(
856    $EmailParserObject->GetParam( WHAT => 'To' ),
857    'Евгений Васильев Новоподзалупинский <xxzzyy@gmail.com>',
858    "#21 GetParam(WHAT => 'To' Multiline encode quote printable)",
859);
860$Self->Is(
861    $EmailParserObject->GetParam( WHAT => 'Subject' ),
862    'Евгений Васильев Новоподзалупинский <xxzzyy@gmail.com>',
863    "#21 GetParam(WHAT => 'Subject' Multiline encode quote printable)",
864);
865
866# test #22
867@Array = ();
868open( $IN, "<", "$Home/scripts/test/sample/EmailParser/PostMaster-Test22.box" );    ## no critic
869while (<$IN>) {
870    push( @Array, $_ );
871}
872close($IN);
873
874$EmailParserObject = Kernel::System::EmailParser->new(
875    Email => \@Array,
876);
877
878$Self->Is(
879    $EmailParserObject->GetParam( WHAT => 'To' ),
880    'QBQB Евгений Васильев Новоподзалупинский <xxzzyy@gmail.com>',
881    "#22 GetParam(WHAT => 'To' Multiline encode)",
882);
883$Self->Is(
884    $EmailParserObject->GetParam( WHAT => 'Subject' ),
885    'QBQB Евгений Васильев Новоподзалупинский <xxzzyy@gmail.com>',
886    "#22 GetParam(WHAT => 'Subject' Multiline encode)",
887);
888
889# test #23
890@Array = ();
891open( $IN, "<", "$Home/scripts/test/sample/EmailParser/UTF-7.box" );    ## no critic
892while (<$IN>) {
893    push( @Array, $_ );
894}
895close($IN);
896
897$EmailParserObject = Kernel::System::EmailParser->new(
898    Email => \@Array,
899);
900
901$Self->Is(
902    $EmailParserObject->GetParam( WHAT => 'To' ),
903    'wop+autoreply=no@ticket.noris.net',
904    "#23 GetParam(WHAT => 'To') UTF-7 not decoded",
905);
906
907# test #24
908@Array = ();
909open( $IN, "<", "$Home/scripts/test/sample/EmailParser/UTF-7.box" );    ## no critic
910while (<$IN>) {
911    push( @Array, $_ );
912}
913close($IN);
914
915$EmailParserObject = Kernel::System::EmailParser->new(
916    Email => \@Array,
917);
918
919$Self->Is(
920    $EmailParserObject->GetParam( WHAT => 'Envelope-To' ),
921    'wop+autoreply=no@ticket.noris.net',
922    "#24 GetParam(WHAT => 'Envelope-To') UTF-7 not decoded",
923);
924
925# test #25 (bug #12108)
926@Array = ();
927open( $IN, "<", "$Home/scripts/test/sample/EmailParser/UTF-7.box" );    ## no critic
928while (<$IN>) {
929    push( @Array, $_ );
930}
931close($IN);
932
933use MIME::Parser;
934my $Parser = MIME::Parser->new();
935
936# prevents writing to filesystem
937$Parser->output_to_core(1);
938my $Entity = $Parser->parse_data( \@Array );
939$EmailParserObject = Kernel::System::EmailParser->new(
940    Entity => $Entity,
941);
942
943$Self->Is(
944    $EmailParserObject->GetParam( WHAT => 'Envelope-To' ),
945    'wop+autoreply=no@ticket.noris.net',
946    "#25 GetParam(WHAT => 'Envelope-To') usage of EmailParser in Entity mode",
947);
948
9491;
950