Data-JSEmail
view release on metacpan or search on metacpan
lib/Data/JSEmail.pm view on Meta::CPAN
}
else {
my $disposition = {};
if (my $val = $eml->header('Content-Disposition')) {
my $orig = $val;
$val =~ s{^(.*filename=\s*)([^\s"][^;]+)}{$1"$2"};
$disposition = parse_content_disposition($val);
}
$partno ||= '1';
my $body = $eml->body();
my $raw_size = length($body); # size in octets of decoded content
if ($type->{type} eq 'text') {
# Decode charset to Perl character string
my $decoded = eval { $eml->body_str() };
if (defined $decoded) {
$body = $decoded;
} else {
# Fallback: try UTF-8 decode
$body = eval { Encode::decode('UTF-8', $body) } // $body;
}
# RFC 8621: line endings in bodyValues MUST be \n not \r\n
my $text_body = $body;
$text_body =~ s/\r\n/\n/g;
$values->{$partno} = {
value => $text_body,
isEncodingProblem => (defined $decoded ? $JSON::false : $JSON::true),
isTruncated => $JSON::false,
};
}
my $charset = $type->{attributes}{charset};
if ($type->{type} eq 'text' and not $charset) {
$charset = 'us-ascii';
}
return {
partId => "$partno",
blobId => "m-$id-$partno",
lib/Data/JSEmail.pm view on Meta::CPAN
sub asOneURL {
my $val = shift;
my $list = asURLs($val) || [];
return $list->[-1];
}
sub asText {
my $val = shift;
return undef unless defined $val;
# Decode MIME-Header encoded words, then NFC normalize
my $decoded = eval { decode('MIME-Header', $val) };
$decoded = $val unless defined $decoded;
# If still raw bytes (not flagged as UTF-8), try UTF-8 decode
if (!Encode::is_utf8($decoded) && $decoded =~ /[\x80-\xff]/) {
$decoded = eval { Encode::decode('UTF-8', $decoded) } // $decoded;
}
my $res = NFC($decoded);
$res =~ s/^\s*//;
$res =~ s/\s*$//;
return $res;
}
sub asAddresses {
my $emails = shift;
my $res = asGroupAddresses($emails);
return undef unless $res;
( run in 0.451 second using v1.01-cache-2.11-cpan-2398b32b56e )