Mail-SpamAssassin
view release on metacpan or search on metacpan
lib/Mail/SpamAssassin/Pyzor/Digest/Pieces.pm view on Meta::CPAN
sub parse_content_type {
my ($content_type) = @_;
# text/plain; charset=us-ascii
my $ct_parse;
if($content_type =~ /(\w+)\/(\w+); charset=(.*)/) {
$ct_parse->{type} = $1;
$ct_parse->{subtype} = $2;
$ct_parse->{'attributes'}{'charset'} = $3;
} elsif($content_type =~ /(\w+)\/(\w+)/) {
$ct_parse->{type} = $1;
$ct_parse->{subtype} = $2;
$ct_parse->{'attributes'}{'charset'} = 'us-ascii';
} else {
$ct_parse->{type} = 'text';
$ct_parse->{subtype} = 'plain';
$ct_parse->{'attributes'}{'charset'} = 'us-ascii';
}
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] if defined $_[0];
}
1;
( run in 1.587 second using v1.01-cache-2.11-cpan-71847e10f99 )