Initial class construction
This commit is contained in:
137
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Base64.pm
Normal file
137
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Base64.pm
Normal file
@ -0,0 +1,137 @@
|
||||
package MIME::Decoder::Base64;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::Base64 - encode/decode a "base64" stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A L<MIME::Decoder> subclass for the C<"base64"> encoding.
|
||||
The name was chosen to jibe with the pre-existing MIME::Base64
|
||||
utility package, which this class actually uses to translate each chunk.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
When B<decoding>, the input is read one line at a time.
|
||||
The input accumulates in an internal buffer, which is decoded in
|
||||
multiple-of-4-sized chunks (plus a possible "leftover" input chunk,
|
||||
of course).
|
||||
|
||||
=item *
|
||||
|
||||
When B<encoding>, the input is read 45 bytes at a time: this ensures
|
||||
that the output lines are not too long. We chose 45 since it is
|
||||
a multiple of 3 and produces lines under 76 characters, as RFC 2045
|
||||
specifies:
|
||||
The encoded output stream must be represented in lines of no more
|
||||
than 76 characters each.
|
||||
|
||||
=back
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
use vars qw(@ISA $VERSION);
|
||||
use MIME::Decoder;
|
||||
use MIME::Base64 2.04;
|
||||
use MIME::Tools qw(debug);
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
### The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
### How many bytes to encode at a time (must be a multiple of 3, and
|
||||
### less than (76 * 0.75)!
|
||||
my $EncodeChunkLength = 45;
|
||||
|
||||
### How many bytes to decode at a time?
|
||||
my $DecodeChunkLength = 32 * 1024;
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $len_4xN;
|
||||
|
||||
### Create a suitable buffer:
|
||||
my $buffer = ' ' x (120 + $DecodeChunkLength); $buffer = '';
|
||||
debug "in = $in; out = $out";
|
||||
|
||||
### Get chunks until done:
|
||||
local($_) = ' ' x $DecodeChunkLength;
|
||||
while ($in->read($_, $DecodeChunkLength)) {
|
||||
tr{A-Za-z0-9+/}{}cd; ### get rid of non-base64 chars
|
||||
|
||||
### Concat any new input onto any leftover from the last round:
|
||||
$buffer .= $_;
|
||||
length($buffer) >= $DecodeChunkLength or next;
|
||||
|
||||
### Extract substring with highest multiple of 4 bytes:
|
||||
### 0 means not enough to work with... get more data!
|
||||
$len_4xN = length($buffer) & ~3;
|
||||
|
||||
### Partition into largest-multiple-of-4 (which we decode),
|
||||
### and the remainder (which gets handled next time around):
|
||||
$out->print(decode_base64(substr($buffer, 0, $len_4xN)));
|
||||
$buffer = substr($buffer, $len_4xN);
|
||||
}
|
||||
|
||||
### No more input remains. Dispose of anything left in buffer:
|
||||
if (length($buffer)) {
|
||||
|
||||
### Pad to 4-byte multiple, and decode:
|
||||
$buffer .= "==="; ### need no more than 3 pad chars
|
||||
$len_4xN = length($buffer) & ~3;
|
||||
|
||||
### Decode it!
|
||||
$out->print(decode_base64(substr($buffer, 0, $len_4xN)));
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $encoded;
|
||||
|
||||
my $nread;
|
||||
my $buf = '';
|
||||
my $nl = $MIME::Entity::BOUNDARY_DELIMITER || "\n";
|
||||
while ($nread = $in->read($buf, $EncodeChunkLength)) {
|
||||
$encoded = encode_base64($buf, $nl);
|
||||
$encoded .= $nl unless ($encoded =~ /$nl\Z/); ### ensure newline!
|
||||
$out->print($encoded);
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
||||
|
183
Git/usr/share/perl5/vendor_perl/MIME/Decoder/BinHex.pm
Normal file
183
Git/usr/share/perl5/vendor_perl/MIME/Decoder/BinHex.pm
Normal file
@ -0,0 +1,183 @@
|
||||
package MIME::Decoder::BinHex;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::BinHex - decode a "binhex" stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
Also supports a preamble() method to recover text before
|
||||
the binhexed portion of the stream.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A MIME::Decoder subclass for a nonstandard encoding whereby
|
||||
data are binhex-encoded. Common non-standard MIME encodings for this:
|
||||
|
||||
x-uu
|
||||
x-uuencode
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Julian Field (F<mailscanner@ecs.soton.ac.uk>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
require 5.002;
|
||||
use vars qw(@ISA $VERSION);
|
||||
use MIME::Decoder;
|
||||
use MIME::Tools qw(whine);
|
||||
use Convert::BinHex;
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
# The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my ($mode, $file);
|
||||
my (@preamble, @data);
|
||||
my $H2B = Convert::BinHex->hex2bin;
|
||||
my $line;
|
||||
|
||||
$self->{MDU_Preamble} = \@preamble;
|
||||
$self->{MDU_Mode} = '600';
|
||||
$self->{MDU_File} = undef;
|
||||
|
||||
### Find beginning...
|
||||
local $_;
|
||||
while (defined($_ = $in->getline)) {
|
||||
if (/^\(This file must be converted/) {
|
||||
$_ = $in->getline;
|
||||
last if /^:/;
|
||||
}
|
||||
push @preamble, $_;
|
||||
}
|
||||
die("binhex decoding: fell off end of file\n") if !defined($_);
|
||||
|
||||
### Decode:
|
||||
my $data;
|
||||
$data = $H2B->next($_); # or whine("Next error is $@ $!\n");
|
||||
my $len = unpack("C", $data);
|
||||
while ($len > length($data)+21 && defined($line = $in->getline)) {
|
||||
$data .= $H2B->next($line);
|
||||
}
|
||||
if (length($data) >= 22+$len) {
|
||||
$data = substr($data, 22+$len);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
|
||||
$out->print($data);
|
||||
while (defined($_ = $in->getline)) {
|
||||
$line = $_;
|
||||
$data = $H2B->next($line);
|
||||
$out->print($data);
|
||||
last if $line =~ /:$/;
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $line;
|
||||
my $buf = '';
|
||||
my $fname = (($self->head &&
|
||||
$self->head->mime_attr('content-disposition.filename')) ||
|
||||
'');
|
||||
my $B2H = Convert::BinHex->bin2hex;
|
||||
$out->print("(This file must be converted with BinHex 4.0)\n");
|
||||
|
||||
# Sigh... get length of file
|
||||
$in->seek(0, 2);
|
||||
my $datalen = $in->tell();
|
||||
$in->seek(0, 0);
|
||||
|
||||
# Build header in core:
|
||||
my @hdrs;
|
||||
my $flen = length($fname);
|
||||
push @hdrs, pack("C", $flen);
|
||||
push @hdrs, pack("a$flen", $fname);
|
||||
push @hdrs, pack('C', 4);
|
||||
push @hdrs, pack('a4', '????');
|
||||
push @hdrs, pack('a4', '????');
|
||||
push @hdrs, pack('n', 0);
|
||||
push @hdrs, pack('N', $datalen);
|
||||
push @hdrs, pack('N', 0); # Resource length
|
||||
my $hdr = join '', @hdrs;
|
||||
|
||||
# Compute the header CRC:
|
||||
my $crc = Convert::BinHex::binhex_crc("\000\000",
|
||||
Convert::BinHex::binhex_crc($hdr, 0));
|
||||
|
||||
# Output the header (plus its CRC):
|
||||
$out->print($B2H->next($hdr . pack('n', $crc)));
|
||||
|
||||
while ($in->read($buf, 1000)) {
|
||||
$out->print($B2H->next($buf));
|
||||
}
|
||||
$out->print($B2H->done);
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_preamble
|
||||
#
|
||||
# Return the last preamble as ref to array of lines.
|
||||
# Gets reset by decode_it().
|
||||
#
|
||||
sub last_preamble {
|
||||
my $self = shift;
|
||||
return $self->{MDU_Preamble} || [];
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_mode
|
||||
#
|
||||
# Return the last mode.
|
||||
# Gets reset to undef by decode_it().
|
||||
#
|
||||
sub last_mode {
|
||||
shift->{MDU_Mode};
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_filename
|
||||
#
|
||||
# Return the last filename.
|
||||
# Gets reset by decode_it().
|
||||
#
|
||||
sub last_filename {
|
||||
shift->{MDU_File} || undef; #[];
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
86
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Binary.pm
Normal file
86
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Binary.pm
Normal file
@ -0,0 +1,86 @@
|
||||
package MIME::Decoder::Binary;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::Binary - perform no encoding/decoding
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A MIME::Decoder subclass for the C<"binary"> encoding (in other words,
|
||||
no encoding).
|
||||
|
||||
The C<"binary"> decoder is a special case, since it's ill-advised
|
||||
to read the input line-by-line: after all, an uncompressed image file might
|
||||
conceivably have loooooooooong stretches of bytes without a C<"\n"> among
|
||||
them, and we don't want to risk blowing out our core. So, we
|
||||
read-and-write fixed-size chunks.
|
||||
|
||||
Both the B<encoder> and B<decoder> do a simple pass-through of the data
|
||||
from input to output.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
use MIME::Decoder;
|
||||
use vars qw(@ISA $VERSION);
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
### The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
### Buffer length:
|
||||
my $BUFLEN = 8192;
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
|
||||
my ($buf, $nread) = ('', 0);
|
||||
while ($nread = $in->read($buf, $BUFLEN)) {
|
||||
$out->print($buf);
|
||||
}
|
||||
defined($nread) or return undef; ### check for error
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
|
||||
my ($buf, $nread) = ('', 0);
|
||||
while ($nread = $in->read($buf, $BUFLEN)) {
|
||||
$out->print($buf);
|
||||
}
|
||||
defined($nread) or return undef; ### check for error
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
111
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Gzip64.pm
Normal file
111
Git/usr/share/perl5/vendor_perl/MIME/Decoder/Gzip64.pm
Normal file
@ -0,0 +1,111 @@
|
||||
package MIME::Decoder::Gzip64;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::Gzip64 - decode a "base64" gzip stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A MIME::Decoder::Base64 subclass for a nonstandard encoding whereby
|
||||
data are gzipped, then the gzipped file is base64-encoded.
|
||||
Common non-standard MIME encodings for this:
|
||||
|
||||
x-gzip64
|
||||
|
||||
Since this class relies on external programs which may not
|
||||
exist on your machine, MIME-tools does not "install" it by default.
|
||||
To use it, you need to say in your main program:
|
||||
|
||||
install MIME::Decoder::Gzip64 'x-gzip64';
|
||||
|
||||
Note: if this class isn't working for you, you may need to change the
|
||||
commands it runs. In your main program, you can do so by setting up
|
||||
the two commands which handle the compression/decompression.
|
||||
|
||||
use MIME::Decoder::Gzip64;
|
||||
|
||||
$MIME::Decoder::Gzip64::GZIP = 'gzip -c';
|
||||
$MIME::Decoder::Gzip64::GUNZIP = 'gzip -d -c';
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
require 5.002;
|
||||
use strict;
|
||||
use vars qw(@ISA $VERSION $GZIP $GUNZIP);
|
||||
use MIME::Decoder;
|
||||
use MIME::Base64;
|
||||
use MIME::Decoder::Base64;
|
||||
use MIME::Tools qw(tmpopen whine);
|
||||
|
||||
# Inheritance:
|
||||
@ISA = qw(MIME::Decoder::Base64);
|
||||
|
||||
# The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
# How to compress stdin to stdout:
|
||||
$GZIP = "gzip -c";
|
||||
|
||||
# How to UNcompress stdin to stdout:
|
||||
$GUNZIP = "gzip -d -c";
|
||||
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
|
||||
# Open a temp file (assume the worst, that this is a big stream):
|
||||
my $tmp = tmpopen() || die "can't get temp file";
|
||||
|
||||
# Stage 1: decode the base64'd stream into zipped data:
|
||||
$self->SUPER::decode_it($in, $tmp) or die "base64 decoding failed!";
|
||||
|
||||
# Stage 2: un-zip the zipped data:
|
||||
$tmp->seek(0, 0);
|
||||
$self->filter($tmp, $out, $GUNZIP) or die "gzip decoding failed!";
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
whine "Encoding ", $self->encoding, " is not standard MIME!";
|
||||
|
||||
# Open a temp file (assume the worst, that this is a big stream):
|
||||
my $tmp = tmpopen() || die "can't get temp file";
|
||||
|
||||
# Stage 1: zip the raw data:
|
||||
$self->filter($in, $tmp, $GZIP) or die "gzip encoding failed!";
|
||||
|
||||
# Stage 2: encode the zipped data via base64:
|
||||
$tmp->seek(0, 0);
|
||||
$self->SUPER::encode_it($tmp, $out) or die "base64 encoding failed!";
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
160
Git/usr/share/perl5/vendor_perl/MIME/Decoder/NBit.pm
Normal file
160
Git/usr/share/perl5/vendor_perl/MIME/Decoder/NBit.pm
Normal file
@ -0,0 +1,160 @@
|
||||
package MIME::Decoder::NBit;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::NBit - encode/decode a "7bit" or "8bit" stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is a MIME::Decoder subclass for the C<7bit> and C<8bit> content
|
||||
transfer encodings. These are not "encodings" per se: rather, they
|
||||
are simply assertions of the content of the message.
|
||||
From RFC-2045 Section 6.2.:
|
||||
|
||||
Three transformations are currently defined: identity, the "quoted-
|
||||
printable" encoding, and the "base64" encoding. The domains are
|
||||
"binary", "8bit" and "7bit".
|
||||
|
||||
The Content-Transfer-Encoding values "7bit", "8bit", and "binary" all
|
||||
mean that the identity (i.e. NO) encoding transformation has been
|
||||
performed. As such, they serve simply as indicators of the domain of
|
||||
the body data, and provide useful information about the sort of
|
||||
encoding that might be needed for transmission in a given transport
|
||||
system.
|
||||
|
||||
In keeping with this: as of MIME-tools 4.x,
|
||||
I<this class does no modification of its input when encoding;>
|
||||
all it does is attempt to I<detect violations> of the 7bit/8bit assertion,
|
||||
and issue a warning (one per message) if any are found.
|
||||
|
||||
|
||||
=head2 Legal 7bit data
|
||||
|
||||
RFC-2045 Section 2.7 defines legal C<7bit> data:
|
||||
|
||||
"7bit data" refers to data that is all represented as relatively
|
||||
short lines with 998 octets or less between CRLF line separation
|
||||
sequences [RFC-821]. No octets with decimal values greater than 127
|
||||
are allowed and neither are NULs (octets with decimal value 0). CR
|
||||
(decimal value 13) and LF (decimal value 10) octets only occur as
|
||||
part of CRLF line separation sequences.
|
||||
|
||||
|
||||
=head2 Legal 8bit data
|
||||
|
||||
RFC-2045 Section 2.8 defines legal C<8bit> data:
|
||||
|
||||
"8bit data" refers to data that is all represented as relatively
|
||||
short lines with 998 octets or less between CRLF line separation
|
||||
sequences [RFC-821]), but octets with decimal values greater than 127
|
||||
may be used. As with "7bit data" CR and LF octets only occur as part
|
||||
of CRLF line separation sequences and no NULs are allowed.
|
||||
|
||||
|
||||
=head2 How decoding is done
|
||||
|
||||
The B<decoder> does a line-by-line pass-through from input to output,
|
||||
leaving the data unchanged I<except> that an end-of-line sequence of
|
||||
CRLF is converted to a newline "\n". Given the line-oriented nature
|
||||
of 7bit and 8bit, this seems relatively sensible.
|
||||
|
||||
|
||||
=head2 How encoding is done
|
||||
|
||||
The B<encoder> does a line-by-line pass-through from input to output,
|
||||
and simply attempts to I<detect> violations of the C<7bit>/C<8bit>
|
||||
domain. The default action is to warn once per encoding if violations
|
||||
are detected; the warnings may be silenced with the QUIET configuration
|
||||
of L<MIME::Tools>.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
use vars qw(@ISA $VERSION);
|
||||
|
||||
use MIME::Decoder;
|
||||
use MIME::Tools qw(:msgs);
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
### The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
### How many bytes to decode at a time?
|
||||
my $DecodeChunkLength = 8 * 1024;
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $and_also;
|
||||
|
||||
### Allocate a buffer suitable for a chunk and a line:
|
||||
local $_ = (' ' x ($DecodeChunkLength + 1024)); $_ = '';
|
||||
|
||||
### Get chunks until done:
|
||||
while ($in->read($_, $DecodeChunkLength)) {
|
||||
$and_also = $in->getline;
|
||||
$_ .= $and_also if defined($and_also);
|
||||
|
||||
### Just got a chunk ending in a line.
|
||||
s/\015\012$/\n/g;
|
||||
$out->print($_);
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $saw_8bit = 0; ### warn them ONCE PER ENCODING if 8-bit data exists
|
||||
my $saw_long = 0; ### warn them ONCE PER ENCODING if long lines exist
|
||||
my $seven_bit = ($self->encoding eq '7bit'); ### 7bit?
|
||||
|
||||
my $line;
|
||||
while (defined($line = $in->getline)) {
|
||||
|
||||
### Whine if encoding is 7bit and it has 8-bit data:
|
||||
if ($seven_bit && ($line =~ /[\200-\377]/)) { ### oops! saw 8-bit data!
|
||||
whine "saw 8-bit data while encoding 7bit" unless $saw_8bit++;
|
||||
}
|
||||
|
||||
### Whine if long lines detected:
|
||||
if (length($line) > 998) {
|
||||
whine "saw long line while encoding 7bit/8bit" unless $saw_long++;
|
||||
}
|
||||
|
||||
### Output!
|
||||
$out->print($line);
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
159
Git/usr/share/perl5/vendor_perl/MIME/Decoder/QuotedPrint.pm
Normal file
159
Git/usr/share/perl5/vendor_perl/MIME/Decoder/QuotedPrint.pm
Normal file
@ -0,0 +1,159 @@
|
||||
package MIME::Decoder::QuotedPrint;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::QuotedPrint - encode/decode a "quoted-printable" stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A MIME::Decoder subclass for the C<"quoted-printable"> encoding.
|
||||
The name was chosen to jibe with the pre-existing MIME::QuotedPrint
|
||||
utility package, which this class actually uses to translate each line.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
The B<decoder> does a line-by-line translation from input to output.
|
||||
|
||||
=item *
|
||||
|
||||
The B<encoder> does a line-by-line translation, breaking lines
|
||||
so that they fall under the standard 76-character limit for this
|
||||
encoding.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
B<Note:> just like MIME::QuotedPrint, we currently use the
|
||||
native C<"\n"> for line breaks, and not C<CRLF>. This may
|
||||
need to change in future versions.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
use vars qw(@ISA $VERSION);
|
||||
use MIME::Decoder;
|
||||
use MIME::QuotedPrint;
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
# The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
#------------------------------
|
||||
# If we have MIME::QuotedPrint 3.03 or later, use the three-argument
|
||||
# version. If we have an earlier version of MIME::QuotedPrint, we
|
||||
# may get the wrong results. However, on some systems (RH Linux,
|
||||
# for example), MIME::QuotedPrint is part of the Perl package and
|
||||
# upgrading it separately breaks their magic auto-update tools.
|
||||
# We are supporting older versions of MIME::QuotedPrint even though
|
||||
# they may give incorrect results simply because it's too painful
|
||||
# for many people to upgrade.
|
||||
|
||||
# The following code is horrible. I know. Beat me up. --dfs
|
||||
BEGIN {
|
||||
if (!defined(&encode_qp_threearg)) {
|
||||
if ($::MIME::QuotedPrint::VERSION >= 3.03) {
|
||||
eval 'sub encode_qp_threearg ( $$$ ) { encode_qp(shift, shift, shift); }';
|
||||
} else {
|
||||
eval 'sub encode_qp_threearg ( $$$ ) { encode_qp(shift); }';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_qp_really STRING TEXTUAL_TYPE_FLAG
|
||||
#
|
||||
# Encode QP, and then follow guideline 8 from RFC 2049 (thanks to Denis
|
||||
# N. Antonioli) whereby we make things a little safer for the transport
|
||||
# and storage of messages. WARNING: we can only do this if the line won't
|
||||
# grow beyond 76 characters!
|
||||
#
|
||||
sub encode_qp_really {
|
||||
my $enc = encode_qp_threearg(shift, undef, not shift);
|
||||
if (length($enc) < 74) {
|
||||
$enc =~ s/^\.\n/=2E\n/g; # force encoding of /^\.$/
|
||||
$enc =~ s/^From /=46rom /g; # force encoding of /^From /
|
||||
}
|
||||
$enc;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $init = 0;
|
||||
my $badpdf = 0;
|
||||
|
||||
local $_;
|
||||
while (defined($_ = $in->getline)) {
|
||||
#
|
||||
# Dirty hack to fix QP-Encoded PDFs from MS-Outlook.
|
||||
#
|
||||
# Check if we have a PDF file and if it has been encoded
|
||||
# on Windows. Unix encoded files are fine. If we have
|
||||
# one encoded CR after the PDF init string but are missing
|
||||
# an encoded CR before the newline this means the PDF is broken.
|
||||
#
|
||||
if (!$init) {
|
||||
$init = 1;
|
||||
if ($_ =~ /^%PDF-[0-9\.]+=0D/ && $_ !~ /=0D\n$/) {
|
||||
$badpdf = 1;
|
||||
}
|
||||
}
|
||||
#
|
||||
# Decode everything with decode_qp() except corrupted PDFs.
|
||||
#
|
||||
if ($badpdf) {
|
||||
my $output = $_;
|
||||
$output =~ s/[ \t]+?(\r?\n)/$1/g;
|
||||
$output =~ s/=\r?\n//g;
|
||||
$output =~ s/(^|[^\r])\n\Z/$1\r\n/;
|
||||
$output =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge;
|
||||
$out->print($output);
|
||||
} else {
|
||||
$out->print(decode_qp($_));
|
||||
}
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out, $textual_type) = @_;
|
||||
|
||||
local $_;
|
||||
while (defined($_ = $in->getline)) {
|
||||
$out->print(encode_qp_really($_, $textual_type));
|
||||
}
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
151
Git/usr/share/perl5/vendor_perl/MIME/Decoder/UU.pm
Normal file
151
Git/usr/share/perl5/vendor_perl/MIME/Decoder/UU.pm
Normal file
@ -0,0 +1,151 @@
|
||||
package MIME::Decoder::UU;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
MIME::Decoder::UU - decode a "uuencoded" stream
|
||||
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
A generic decoder object; see L<MIME::Decoder> for usage.
|
||||
|
||||
Also supports a preamble() method to recover text before
|
||||
the uuencoded portion of the stream.
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A MIME::Decoder subclass for a nonstandard encoding whereby
|
||||
data are uuencoded. Common non-standard MIME encodings for this:
|
||||
|
||||
x-uu
|
||||
x-uuencode
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<MIME::Decoder>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Eryq (F<eryq@zeegee.com>), ZeeGee Software Inc (F<http://www.zeegee.com>).
|
||||
|
||||
UU-decoding code lifted from "uuexplode", a Perl script by an
|
||||
unknown author...
|
||||
|
||||
All rights reserved. This program is free software; you can redistribute
|
||||
it and/or modify it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
require 5.002;
|
||||
use vars qw(@ISA $VERSION);
|
||||
use MIME::Decoder;
|
||||
use MIME::Tools qw(whine);
|
||||
|
||||
@ISA = qw(MIME::Decoder);
|
||||
|
||||
# The package version, both in 1.23 style *and* usable by MakeMaker:
|
||||
$VERSION = "5.509";
|
||||
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# decode_it IN, OUT
|
||||
#
|
||||
sub decode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my ($mode, $file);
|
||||
my @preamble;
|
||||
|
||||
### Init:
|
||||
$self->{MDU_Preamble} = \@preamble;
|
||||
$self->{MDU_Mode} = undef;
|
||||
$self->{MDU_File} = undef;
|
||||
|
||||
### Find beginning...
|
||||
local $_;
|
||||
while (defined($_ = $in->getline)) {
|
||||
if (/^begin(.*)/) { ### found it: now decode it...
|
||||
my $modefile = $1;
|
||||
if ($modefile =~ /^(\s+(\d+))?(\s+(.*?\S))?\s*\Z/) {
|
||||
($mode, $file) = ($2, $4);
|
||||
}
|
||||
last; ### decoded or not, we're done
|
||||
}
|
||||
push @preamble, $_;
|
||||
}
|
||||
die("uu decoding: no begin found\n") if !defined($_); # hit eof!
|
||||
|
||||
### Store info:
|
||||
$self->{MDU_Mode} = $mode;
|
||||
$self->{MDU_File} = $file;
|
||||
|
||||
### Decode:
|
||||
while (defined($_ = $in->getline)) {
|
||||
last if /^end/;
|
||||
next if /[a-z]/;
|
||||
next unless int((((ord() - 32) & 077) + 2) / 3) == int(length() / 4);
|
||||
$out->print(unpack('u', $_));
|
||||
}
|
||||
### chmod oct($mode), $file; # sheeyeah... right...
|
||||
whine "file incomplete, no end found\n" if !defined($_); # eof
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# encode_it IN, OUT
|
||||
#
|
||||
sub encode_it {
|
||||
my ($self, $in, $out) = @_;
|
||||
my $buf = '';
|
||||
|
||||
my $fname = (($self->head &&
|
||||
$self->head->mime_attr('content-disposition.filename')) ||
|
||||
'');
|
||||
my $nl = $MIME::Entity::BOUNDARY_DELIMITER || "\n";
|
||||
$out->print("begin 644 $fname$nl");
|
||||
while ($in->read($buf, 45)) { $out->print(pack('u', $buf)) }
|
||||
$out->print("end$nl");
|
||||
1;
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_preamble
|
||||
#
|
||||
# Return the last preamble as ref to array of lines.
|
||||
# Gets reset by decode_it().
|
||||
#
|
||||
sub last_preamble {
|
||||
my $self = shift;
|
||||
return $self->{MDU_Preamble} || [];
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_mode
|
||||
#
|
||||
# Return the last mode.
|
||||
# Gets reset to undef by decode_it().
|
||||
#
|
||||
sub last_mode {
|
||||
shift->{MDU_Mode};
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
#
|
||||
# last_filename
|
||||
#
|
||||
# Return the last filename.
|
||||
# Gets reset by decode_it().
|
||||
#
|
||||
sub last_filename {
|
||||
shift->{MDU_File} || [];
|
||||
}
|
||||
|
||||
#------------------------------
|
||||
1;
|
Reference in New Issue
Block a user