Courriel

 view release on metacpan or  search on metacpan

t/Courriel.t  view on Meta::CPAN


foo
EOF

    is(
        exception {
            Courriel->parse( text => \$text );
        },
        undef,
        'mbox separator which contains a newline is parser correctly'
    );
}

{
    my $text = <<'EOF';
From autarch@gmail.com Sun May 29 11:22:29 2011
MIME-Version: 1.0
Date: Sun, 29 May 2011 11:22:22 -0500
Message-ID: <BANLkTimjF2BDbOKO_2jFJsp6t+0KvqxCwQ@mail.gmail.com>
Subject: Testing
From: Dave Rolsky <autarch@gmail.com>
To: Dave Rolsky <autarch@urth.org>
Content-Type: multipart/alternative; boundary=20cf3071cfd06272ae04a46c9306

WTF, just a single part.
EOF

    my $email;
    is(
        exception {
            $email = Courriel->parse( text => \$text );
        },
        undef,
        'multipart mime type with single part body still parses'
    );

    is(
        $email->part_count,
        1,
        'email has one part'
    );
}

{
    my $text = <<"EOF";
Subject: Foo
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
Content-Transfer-Encoding: 8bit

Vel\x{00E1}zquez
EOF

    my $email = Courriel->parse( text => \$text, is_character => 1 );

    my $content = $email->plain_body_part->content;
    $content =~ s/[\r\n]//g;

    is(
        $content,
        "Vel\x{00E1}zquez",
        '8bit encoded body (marked as utf8) ends up decoded properly'
    );

    ok(
        is_utf8($content),
        'content ends up marked as is_utf8'
    );
}

{
    my $text = <<"EOF";
Subject: Foo
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
Content-Transfer-Encoding: 8bit

Vel\x{00E1}zquez
EOF

    $text = encode( 'utf-8', $text );

    my $email = Courriel->parse( text => \$text, is_character => 0 );

    my $content = $email->plain_body_part->content;
    $content =~ s/[\r\n]//g;

    is(
        $content,
        "Vel\x{00E1}zquez",
        '8bit encoded body (marked as binary) ends up decoded properly'
    );

    ok(
        is_utf8($content),
        'content ends up marked as is_utf8'
    );
}

{
    my $text = <<'EOF';
From autarch@gmail.com Sun May 29 11:22:29 2011
MIME-Version: 1.0
Date: Sun, 29 May 2011 11:22:22 -0500
Message-ID: <BANLkTimjF2BDbOKO_2jFJsp6t+0KvqxCwQ@mail.gmail.com>
Subject: Testing
From: Dave Rolsky <autarch@gmail.com>
To: Dave Rolsky <autarch@urth.org>
Content-Type: MULTIPART/ALTERNATIVE; BOUNDARY=20cf3071cfd06272ae04a46c9306


--20cf3071cfd06272ae04a46c9306
Content-Type: text/plain; charset=ISO-8859-1
Content-Disposition: inline

This is a test email.

It has some *bold* text.

--20cf3071cfd06272ae04a46c9306
Content-Type: text/html; charset=ISO-8859-1
Content-Disposition: inline

This is a test email.<br><br>It has some <b>bold</b> text.<br><br>

--20cf3071cfd06272ae04a46c9306--
EOF

    my $email = Courriel->parse( text => \$text );

    is(
        $email->content_type->attribute_value('boundary'),
        '20cf3071cfd06272ae04a46c9306',
        'attribute name is case insensitive on lookup'
    );

    is(
        $email->content_type->attribute_value('BOUNDARY'),
        '20cf3071cfd06272ae04a46c9306',
        'attribute name is case insensitive on lookup'
    );

    is(
        $email->content_type->attribute('boundary')->name,
        'BOUNDARY',
        'HeaderAttribute object name preserves original casing'
    );
}

{
    my $email = build_email(



( run in 1.057 second using v1.01-cache-2.11-cpan-39bf76dae61 )