Mail-Pyzor
view release on metacpan or search on metacpan
lib/Mail/Pyzor/Digest/Pieces.pm view on Meta::CPAN
=cut
use constant _QUOTED_PRINTABLE_NAMES => (
"quopri-codec",
"quopri",
"quoted-printable",
"quotedprintable",
);
# Make Encode::decode() ignore anything that doesnât fit the
# given encoding.
use constant _encode_check_ignore => q<>;
sub parse_content_type {
my ($content_type) = @_;
my $ct_parse = Email::MIME::ContentType::parse_content_type(
$content_type,
);
my $main = $ct_parse->{'type'} || q<>;
my $sub = $ct_parse->{'subtype'} || q<>;
my $encoding = $ct_parse->{'attributes'}{'charset'};
my $checkval;
if ($encoding) {
# Lower-case everything, convert underscore to dash, and remove NUL.
$encoding =~ tr<A-Z_\0><a-z->d;
# Apparently pyzor accommodates messages that put the transfer
# encoding in the Content-Type.
if ( grep { $_ eq $encoding } _QUOTED_PRINTABLE_NAMES() ) {
$checkval = Encode::FB_CROAK();
}
}
else {
$encoding = 'ascii';
}
# Match Python .decode()âs 'ignore' behavior
$checkval ||= \&_encode_check_ignore;
return ( $main, $sub, $encoding, $checkval );
}
#----------------------------------------------------------------------
=head2 @lines = splitlines( $TEXT )
Imitates C<str.splitlines()>. (cf. C<pydoc str>)
Returns a plain list in list context. Returns the number of
items to be returned in scalar context.
=cut
sub splitlines {
return split m<\r\n?|\n>, $_[0];
}
1;
( run in 1.835 second using v1.01-cache-2.11-cpan-71847e10f99 )