| 1 | package MIME::Decoder::QuotedPrint; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | MIME::Decoder::QuotedPrint - encode/decode a "quoted-printable" stream | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | A generic decoder object; see L<MIME::Decoder> for usage. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | A MIME::Decoder subclass for the C<"quoted-printable"> encoding. | ||||||||||||||||||||||||||||
| 19 | The name was chosen to jibe with the pre-existing MIME::QuotedPrint | ||||||||||||||||||||||||||||
| 20 | utility package, which this class actually uses to translate each line. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =over 4 | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =item * | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | The B<decoder> does a line-by-line translation from input to output. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item * | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | The B<encoder> does a line-by-line translation, breaking lines | ||||||||||||||||||||||||||||
| 31 | so that they fall under the standard 76-character limit for this | ||||||||||||||||||||||||||||
| 32 | encoding. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =back | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | B<Note:> just like MIME::QuotedPrint, we currently use the | ||||||||||||||||||||||||||||
| 38 | native C<"\n"> for line breaks, and not C<CRLF>. This may | ||||||||||||||||||||||||||||
| 39 | need to change in future versions. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | L<MIME::Decoder> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>). | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | All rights reserved. This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 50 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 9 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 9 | ▶ | use MIME::Decoder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 9 | ▶ | use MIME::QuotedPrint; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 9 | @ISA = qw(MIME::Decoder); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # The package version, both in 1.23 style *and* usable by MakeMaker: | ||||||||||||||||||||||||||||
| 61 | 9 | $VERSION = "5.522"; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #------------------------------ | ||||||||||||||||||||||||||||
| 64 | # If we have MIME::QuotedPrint 3.03 or later, use the three-argument | ||||||||||||||||||||||||||||
| 65 | # version. If we have an earlier version of MIME::QuotedPrint, we | ||||||||||||||||||||||||||||
| 66 | # may get the wrong results. However, on some systems (RH Linux, | ||||||||||||||||||||||||||||
| 67 | # for example), MIME::QuotedPrint is part of the Perl package and | ||||||||||||||||||||||||||||
| 68 | # upgrading it separately breaks their magic auto-update tools. | ||||||||||||||||||||||||||||
| 69 | # We are supporting older versions of MIME::QuotedPrint even though | ||||||||||||||||||||||||||||
| 70 | # they may give incorrect results simply because it's too painful | ||||||||||||||||||||||||||||
| 71 | # for many people to upgrade. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # The following code is horrible. I know. Beat me up. --dfs | ||||||||||||||||||||||||||||
| 74 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 75 | 9 | ▶ | if (!defined(&encode_qp_threearg)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 9 | my $ver = version->parse($::MIME::QuotedPrint::VERSION); | |||||||||||||||||||||||||||
| 77 | 9 | ▶ | if ($ver >= version->parse(3.03)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 9 | ▶ | eval 'sub encode_qp_threearg ( $$$ ) { encode_qp(shift, shift, shift); }'; | ||||||||||||||||||||||||||
|
Subroutine
encode_qp_threearg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||
| 80 | 0 | eval 'sub encode_qp_threearg ( $$$ ) { encode_qp(shift); }'; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | #------------------------------ | ||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||
| 87 | # encode_qp_really STRING TEXTUAL_TYPE_FLAG | ||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||
| 89 | # Encode QP, and then follow guideline 8 from RFC 2049 (thanks to Denis | ||||||||||||||||||||||||||||
| 90 | # N. Antonioli) whereby we make things a little safer for the transport | ||||||||||||||||||||||||||||
| 91 | # and storage of messages. WARNING: we can only do this if the line won't | ||||||||||||||||||||||||||||
| 92 | # grow beyond 76 characters! | ||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||
| 94 | 65 | ▶ | sub encode_qp_really { | ||||||||||||||||||||||||||
|
Subroutine
encode_qp_really: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 65 | my $enc = encode_qp_threearg(shift, undef, not shift); | |||||||||||||||||||||||||||
| 96 | 65 | ▶ | if (length($enc) < 74) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 59 | $enc =~ s/^\.\n/=2E\n/g; # force encoding of /^\.$/ | |||||||||||||||||||||||||||
| 98 | 59 | $enc =~ s/^From /=46rom /g; # force encoding of /^From / | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 65 | $enc; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #------------------------------ | ||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||
| 105 | # decode_it IN, OUT | ||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||
| 107 | 15 | ▶ | sub decode_it { | ||||||||||||||||||||||||||
|
Subroutine
decode_it: called CC=6 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 15 | my ($self, $in, $out) = @_; | |||||||||||||||||||||||||||
| 109 | 15 | my $init = 0; | |||||||||||||||||||||||||||
| 110 | 15 | my $badpdf = 0; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 15 | local $_; | |||||||||||||||||||||||||||
| 113 | 15 | ▶ | while (defined($_ = $in->getline)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||
| 115 | # Dirty hack to fix QP-Encoded PDFs from MS-Outlook. | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | # Check if we have a PDF file and if it has been encoded | ||||||||||||||||||||||||||||
| 118 | # on Windows. Unix encoded files are fine. If we have | ||||||||||||||||||||||||||||
| 119 | # one encoded CR after the PDF init string but are missing | ||||||||||||||||||||||||||||
| 120 | # an encoded CR before the newline this means the PDF is broken. | ||||||||||||||||||||||||||||
| 121 | # | ||||||||||||||||||||||||||||
| 122 | 329 | ▶ | if (!$init) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 15 | $init = 1; | |||||||||||||||||||||||||||
| 124 | 15 | ▶ | if ($_ =~ /^%PDF-[0-9\.]+=0D/ && $_ !~ /=0D\n$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_ =~ /^%PDF-[0-9\.]+=0D/ and not $_ =~ /=0D\n$/
MC/DC0%0/2
$_ =~ /^%PDF-[0-9\.]+=0D/ and not $_ =~ /=0D\n$/
$_ =~ /^%PDF-[0-9\.]+=0D/
not $_ =~ /=0D\n$/
Truth table33%1/3
A and not(B)
A= $_ =~ /^%PDF-[0-9\.]+=0D/B= not $_ =~ /=0D\n$/
| |||||||||||||||||||||||||||||
| 125 | 0 | $badpdf = 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | # | ||||||||||||||||||||||||||||
| 129 | # Decode everything with decode_qp() except corrupted PDFs. | ||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||
| 131 | 329 | ▶ | if ($badpdf) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | my $output = $_; | |||||||||||||||||||||||||||
| 133 | 0 | $output =~ s/[ \t]+?(\r?\n)/$1/g; | |||||||||||||||||||||||||||
| 134 | 0 | $output =~ s/=\r?\n//g; | |||||||||||||||||||||||||||
| 135 | 0 | $output =~ s/(^|[^\r])\n\Z/$1\r\n/; | |||||||||||||||||||||||||||
| 136 | 0 | $output =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge; | |||||||||||||||||||||||||||
| 137 | 0 | $out->print($output); | |||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||
| 139 | 329 | $out->print(decode_qp($_)); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 15 | 1; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | #------------------------------ | ||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||
| 147 | # encode_it IN, OUT | ||||||||||||||||||||||||||||
| 148 | # | ||||||||||||||||||||||||||||
| 149 | 8 | ▶ | sub encode_it { | ||||||||||||||||||||||||||
|
Subroutine
encode_it: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 8 | my ($self, $in, $out, $textual_type) = @_; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 8 | local $_; | |||||||||||||||||||||||||||
| 153 | 8 | ▶ | while (defined($_ = $in->getline)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 57 | $out->print(encode_qp_really($_, $textual_type)); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 8 | 1; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | #------------------------------ | ||||||||||||||||||||||||||||
| 160 | 9 | 1; | |||||||||||||||||||||||||||