RT 4.0.22
[freeside.git] / rt / t / api / attachment.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test tests => 7;
6
7
8 {
9
10 ok (require RT::Attachment);
11
12
13 }
14
15 {
16
17 my $test1 = "From: jesse";
18 my @headers = RT::Attachment->_SplitHeaders($test1);
19 is ($#headers, 0, $test1 );
20
21 my $test2 = qq{From: jesse
22 To: bobby
23 Subject: foo
24 };
25
26 @headers = RT::Attachment->_SplitHeaders($test2);
27 is ($#headers, 2, "testing a bunch of singline multiple headers" );
28
29
30 my $test3 = qq{From: jesse
31 To: bobby,
32  Suzie,
33     Sally,
34     Joey: bizzy,
35 Subject: foo
36 };
37
38 @headers = RT::Attachment->_SplitHeaders($test3);
39 is ($#headers, 2, "testing a bunch of singline multiple headers" );
40
41
42
43 }
44
45
46 {
47     my $iso_8859_1_ticket_email =
48       RT::Test::get_relocatable_file( 'new-ticket-from-iso-8859-1',
49         ( File::Spec->updir(), 'data', 'emails' ) );
50     my $content = RT::Test->file_content($iso_8859_1_ticket_email);
51
52     my $parser = RT::EmailParser->new;
53     $parser->ParseMIMEEntityFromScalar($content);
54     my $attachment = RT::Attachment->new( $RT::SystemUser );
55     my ( $id, $msg ) =
56       $attachment->Create( TransactionId => 1, Attachment => $parser->Entity );
57     ok( $id, $msg );
58     my $mime = $attachment->ContentAsMIME;
59     like( $mime->head->get('Content-Type'),
60         qr/charset="iso-8859-1"/, 'content type of ContentAsMIME is original' );
61     is(
62         Encode::decode( 'iso-8859-1', $mime->stringify_body ),
63         Encode::decode( 'UTF-8',      "HÃ¥vard\n" ),
64         'body of ContentAsMIME is original'
65     );
66 }