package Debbugs::MIME;
+=head1 NAME
+
+Debbugs::MIME -- Mime handling routines for debbugs
+
+=head1 SYNOPSIS
+
+ use Debbugs::MIME qw(parse decode_rfc1522);
+
+=head1 DESCRIPTION
+
+
+=head1 BUGS
+
+None known.
+
+=cut
+
+use warnings;
use strict;
use base qw(Exporter);
}
use File::Path;
+use File::Temp qw();
use MIME::Parser;
use POSIX qw(strftime);
my $entity = shift;
my $type = $entity->effective_type;
if ($type eq 'text/plain' or
- ($type =~ m#text/# and $type ne 'text/html') or
+ ($type =~ m#text/?# and $type ne 'text/html') or
$type eq 'application/pgp') {
return $entity->bodyhandle;
} elsif ($type eq 'multipart/alternative') {
my (@headerlines, @bodylines);
my $parser = MIME::Parser->new();
- mkdir "mime.tmp.$$", 0777;
- $parser->output_under("mime.tmp.$$");
+ my $tempdir = File::Temp::tempdir();
+ $parser->output_under($tempdir);
my $entity = eval { $parser->parse_data($_[0]) };
if ($entity and $entity->head->tags) {
@bodylines = @msg[$i .. $#msg];
}
- rmtree "mime.tmp.$$", 0, 1;
+ rmtree $tempdir, 0, 1;
# Remove blank lines.
shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
# Strip off RFC2440-style PGP clearsigning.
if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
- shift @bodylines while @bodylines and length $bodylines[0];
+ shift @bodylines while @bodylines and
+ length $bodylines[0] and
+ # we currently don't strip \r; handle this for the
+ # time being, though eventually it should be stripped
+ # too, I think. [See #565981]
+ $bodylines[0] ne "\r";
shift @bodylines while @bodylines and $bodylines[0] !~ /\S/;
for my $findsig (0 .. $#bodylines) {
if ($bodylines[$findsig] =~ /^-----BEGIN PGP SIGNATURE/) {
# handle being passed undef properly
return undef if not defined $rawstr;
+ if (is_utf8($rawstr)) {
+ $rawstr= encode_utf8($rawstr);
+ }
# We process words in reverse so we can preserve spacing between
# encoded words. This regex splits on word|nonword boundaries and
- # nonword|nonword boundaries.
- my @words = reverse split /(?:(?<=[\s\n])|(?=[\s\n]))/m, $rawstr;
+ # nonword|nonword boundaries. We also consider parenthesis and "
+ # to be nonwords to avoid escaping them in comments in violation
+ # of RFC1522
+ my @words = reverse split /(?:(?<=[\s\n\)\(\"])|(?=[\s\n\)\(\"]))/m, $rawstr;
my $previous_word_encoded = 0;
my $string = '';