| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | use Test::More tests => 13; |
|---|
| 4 | use Test::Exception; |
|---|
| 5 | |
|---|
| 6 | BEGIN { use_ok(Lancelot::Message); } |
|---|
| 7 | |
|---|
| 8 | my $msg; |
|---|
| 9 | dies_ok { $msg = new Lancelot::Message } "new() for empty text"; |
|---|
| 10 | |
|---|
| 11 | # $msg = new Lancelot::Message(<<END); |
|---|
| 12 | # xyzzy |
|---|
| 13 | # foobar |
|---|
| 14 | # baz |
|---|
| 15 | # quux |
|---|
| 16 | # END |
|---|
| 17 | # It turns out that Email::Simple doesn't actually mind this. |
|---|
| 18 | # ok( defined $msg, "new() for non-RFC2822 text" ); |
|---|
| 19 | |
|---|
| 20 | $msg = new Lancelot::Message(<<'END'); |
|---|
| 21 | From: hugo@example.com |
|---|
| 22 | To: susi@example.net |
|---|
| 23 | Subject: Test |
|---|
| 24 | X-Test: blafasel |
|---|
| 25 | X-Multiline: bla |
|---|
| 26 | fasel |
|---|
| 27 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 28 | Content-Transfer-Encoding: quoted-printable |
|---|
| 29 | |
|---|
| 30 | Dies ist ein Test. |
|---|
| 31 | END |
|---|
| 32 | ok( defined $msg, "new() for RFC2822 message" ); |
|---|
| 33 | ok( $msg->isa('Lancelot::Message'), "correct class" ); |
|---|
| 34 | ok( $msg->isa('Email::MIME'), "correct superclass" ); |
|---|
| 35 | |
|---|
| 36 | $msg->set_flag('bla', 'fasel'); |
|---|
| 37 | is( $msg->get_flag('bla'), 'fasel', "set_flag/get_flag test"); |
|---|
| 38 | |
|---|
| 39 | is( $msg->header('X-Multiline'), 'bla fasel', "header folding" ); |
|---|
| 40 | |
|---|
| 41 | my $correct = 'From: hugo@example.com |
|---|
| 42 | To: susi@example.net |
|---|
| 43 | Subject: Test |
|---|
| 44 | X-Test: blafasel |
|---|
| 45 | X-Multiline: bla |
|---|
| 46 | fasel |
|---|
| 47 | Content-Type: text/plain; charset="iso-8859-1" |
|---|
| 48 | Content-Transfer-Encoding: quoted-printable |
|---|
| 49 | '; |
|---|
| 50 | is( $msg->headers_raw(), $correct, "raw headers"); |
|---|
| 51 | $msg->header_set('X-Bla', 'Fasel'); |
|---|
| 52 | is( $msg->header('X-Bla'), 'Fasel', "header_set check"); |
|---|
| 53 | $msg->header_set('X-Bla', 'Fasel', 'Blubb'); |
|---|
| 54 | my @h = $msg->header('X-Bla'); |
|---|
| 55 | is_deeply(\@h , ['Fasel','Blubb'], "header_set check (array)"); |
|---|
| 56 | |
|---|
| 57 | $msg->header_remove('X-Test'); |
|---|
| 58 | ok( !defined $msg->header('X-Test'), "header_remove check"); |
|---|
| 59 | |
|---|
| 60 | $msg->header_set('X-EncTest', 'Ein ÄÖÜäöüß-Test'); |
|---|
| 61 | is($msg->header('X-EncTest'), 'Ein ÄÖÜäöüß-Test', "header_encode test"); |
|---|
| 62 | $msg->header_encode('X-EncTest', 'quoted-printable'); |
|---|
| 63 | |
|---|
| 64 | # We can't test it simply like this because Email::MIME helpfully |
|---|
| 65 | # decodes the header for us. |
|---|
| 66 | # |
|---|
| 67 | # is($msg->header('X-EncTest'), 'Ein =?iso-8859-1?Q?=C4=D6=DC=E4=F6=FC=DF?=-Test', |
|---|
| 68 | # "header_encode test"); |
|---|
| 69 | |
|---|
| 70 | TODO: { |
|---|
| 71 | local $TODO = "header_encode isn't really testable"; |
|---|
| 72 | |
|---|
| 73 | my ($x) = $msg->__head->as_string =~ /^X-EncTest:\s+(.*)$/m; |
|---|
| 74 | is( $x, 'Ein =?iso-8859-1?Q?=C4=D6=DC=E4=F6=FC=DF-Test?=', |
|---|
| 75 | "header_encode check" ); |
|---|
| 76 | diag($msg->__head->as_string); |
|---|
| 77 | } |
|---|