1#!/usr/bin/env perl 2# 3# Encoding and Decoding quoted-print bodies 4# 5 6use strict; 7use warnings; 8 9use Mail::Message::Test; 10use Mail::Message::Body::Lines; 11use Mail::Message::TransferEnc::QuotedPrint; 12 13use Test::More tests => 10; 14 15my $src = <<SRC; 16In the source text, there are a few \010\r strange characters, 17which \200\201 must become encoded. There is also a \010== long line, which must be broken into pieces, and 18there are = confusing constructions like this one: =0D, which looks 19encoded, but is not. 20SRC 21 22my $encoded = <<ENCODED; 23In the source text, there are a few =08=0D strange characters, 24which =80=81 must become encoded. There is also a =08=3D=3D long line, whi= 25ch must be broken into pieces, and 26there are =3D confusing constructions like this one: =3D0D, which looks 27encoded, but is not. 28ENCODED 29 30my $codec = Mail::Message::TransferEnc::QuotedPrint->new; 31ok(defined $codec); 32is($codec->name, 'quoted-printable'); 33 34# Test encoding 35 36my $body = Mail::Message::Body::Lines->new 37 ( mime_type => 'text/html' 38 , data => $src 39 ); 40 41my $enc = $codec->encode($body); 42ok($body!=$enc); 43is($enc->mimeType, 'text/html'); 44is($enc->transferEncoding, 'quoted-printable'); 45is($enc->string, $encoded); 46 47# Test decoding 48 49$body = Mail::Message::Body::Lines->new 50 ( transfer_encoding => 'quoted-printable' 51 , mime_type => 'text/html' 52 , data => $encoded 53 ); 54 55my $dec = $codec->decode($body); 56ok($dec!=$body); 57is($enc->mimeType, 'text/html'); 58is($dec->transferEncoding, 'none'); 59is($dec->string, $src); 60 61