# This module is part of debbugs, and is released
# under the terms of the GPL version 2, or any later version. See the
# file README and COPYING for more information.
#
# [Other people have contributed to this file; their copyrights should
# be listed here too.]
# Copyright 2008 by Don Armstrong \n);
}
}
push @headers, qq(
".html_escape(decode_rfc1522($entity->head->stringify))."
\n";
}
print {$output} "[$printname } .
"($type, $disposition)]
\n";
}
}
return 0 if not $param{outer} and $disposition eq 'attachment' and not exists $param{att};
return 0 unless (($type =~ m[^text/?] and
$type !~ m[^text/(?:html|enriched)(?:;|$)]) or
$type =~ m[^application/pgp(?:;|$)] or
$entity->parts);
if ($entity->is_multipart) {
my @parts = $entity->parts;
foreach my $part (@parts) {
my $raw_output =
display_entity(entity => $part,
bug_num => $ref,
outer => 0,
msg_num => $xmessage,
output => $output,
attachments => $attachments,
terse => $param{terse},
exists $param{msg}?(msg=>$param{msg}):(),
exists $param{att}?(att=>$param{att}):(),
exists $param{avatars}?(avatars=>$param{avatars}):(),
);
if ($raw_output) {
return $raw_output;
}
# print {$output} "\n";
}
} elsif ($entity->parts) {
# We must be dealing with a nested message.
if (not exists $param{att}) {
print {$output} "\n";
}
my @parts = $entity->parts;
foreach my $part (@parts) {
display_entity(entity => $part,
bug_num => $ref,
outer => 1,
msg_num => $xmessage,
output => $output,
attachments => $attachments,
terse => $param{terse},
exists $param{msg}?(msg=>$param{msg}):(),
exists $param{att}?(att=>$param{att}):(),
exists $param{avatars}?(avatars=>$param{avatars}):(),
);
# print {$output} "\n";
}
if (not exists $param{att}) {
print {$output} "
\n";
}
} elsif (not $param{terse}) {
my $content_type = $entity->head->get('Content-Type:') || "text/html";
my ($charset) = $content_type =~ m/charset\s*=\s*\"?([\w-]+)\"?/i;
my $body = $entity->bodyhandle->as_string;
$body = convert_to_utf8($body,$charset//'utf8');
$body = html_escape($body);
my $css_class = "message";
# Attempt to deal with format=flowed
if ($content_type =~ m/format\s*=\s*\"?flowed\"?/i) {
$body =~ s{^\ }{}mgo;
# we ignore the other things that you can do with
# flowed e-mails cause they don't really matter.
$css_class .= " flowed";
}
# if the message is composed entirely of lines which are separated by
# newlines, wrap it. [Allow the signature to have special formatting.]
if ($body =~ /^([^\n]+\n\n)*[^\n]*\n?(-- \n.+)*$/s or
# if the first 20 lines in the message which have any non-space
# characters are larger than 100 characters more often than they
# are not, then use CSS to try to impose sensible wrapping
sum(0,map {length ($_) > 100?1:-1} grep {/\S/} split /\n/,$body,20) > 0
) {
$css_class .= " wrapping";
}
# Add links to URLs
# We don't html escape here because we escape above;
# wierd terminators are because of that
$body =~ s{((?:ftp|http|https|svn|ftps|rsync)://[\S~-]+?/?) # Url
((?:\>\;)?[)]?(?:'|\&\#39\;|\"\;)?[:.\,;]?(?:\s|$)) # terminators
}{$1$2}gox;
# Add links to bug closures
$body =~ s[((?:closes|see):\s* # start of closed/referenced bugs
(?:bug)?\#?\s?\d+\s? # first bug
(?:,?\s*(?:bug)?\#?\s?\d+)* # additional bugs
(?:\s|\n|\)|\]|\}|\.|\,|$)) # ends with a space, newline, end of string, or ); fixes #747267
]
[my $temp = $1;
$temp =~ s{(\d+)}
{bug_links(bug=>$1)}ge;
$temp;]gxie;
if (defined $config{cve_tracker} and
length $config{cve_tracker}
) {
# Add links to CVE vulnerabilities (closes #568464)
$body =~ s{(^|\s|[\(\[])(CVE-\d{4}-\d{4,})(\s|[,.-\[\]\)]|$)}
{$1$2$3}gxm;
}
if (not exists $param{att}) {
print {$output} qq($body
\n);
}
}
return 0;
}
=head2 handle_email_message
handle_email_message($record->{text},
ref => $bug_number,
msg_num => $msg_number,
);
Returns a decoded e-mail message and displays entities/attachments as
appropriate.
=cut
sub handle_email_message{
my ($record,%param) = @_;
my $output;
my $output_fh = globify_scalar(\$output);
my $entity;
my $tempdir;
if (not blessed $record) {
my $parser = MIME::Parser->new();
# this will be cleaned up once it goes out of scope
$tempdir = File::Temp->newdir();
$parser->output_under($tempdir->dirname());
if ($record->{inner_file}) {
$entity = $parser->parse($record->{fh}) or
die "Unable to parse entity";
} else {
$entity = $parser->parse_data($record->{text}) or
die "Unable to parse entity";
}
} else {
$entity = $record;
}
my @attachments = ();
my $raw_output =
display_entity(entity => $entity,
bug_num => $param{ref},
outer => 1,
msg_num => $param{msg_num},
output => $output_fh,
attachments => \@attachments,
terse => $param{terse},
exists $param{msg}?(msg=>$param{msg}):(),
exists $param{att}?(att=>$param{att}):(),
exists $param{trim_headers}?(trim_headers=>$param{trim_headers}):(),
exists $param{avatars}?(avatars=>$param{avatars}):(),
);
return $raw_output?$output:decode_utf8($output);
}
=head2 handle_record
push @log, handle_record($record,$ref,$msg_num);
Deals with a record in a bug log as returned by
L
🔗\n); $output .= 'View this message in rfc822 format
'; $output .= handle_email_message($record, ref => $bug_number, msg_num => $msg_number, %param, ); } elsif (/autocheck/) { # Do nothing } elsif (/incoming-recv/) { my ($msg_id) = record_regex($record,qr/^Message-Id:\s+<(.+)>/i); if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) { return (); } elsif (defined $msg_id) { $$seen_msg_ids{$msg_id} = 1; } return () if defined $param{spam} and $param{spam}->is_spam($msg_id); # Incomming Mail Message my ($received,$hostname) = record_regex($record,qr/Received: \(at (\S+)\) by (\S+)\;/o); $output .= qq|Message #$msg_number received at |. html_escape("$received\@$hostname") . q| (full text'. q|, mbox, '; my $parser = MIME::Parser->new(); # this will be cleaned up once it goes out of scope my $tempdir = File::Temp->newdir(); $parser->output_under($tempdir->dirname()); $parser->filer->ignore_filename(1); my $entity; if ($record->{inner_file}) { $entity = $parser->parse($record->{fh}); } else { $entity = $parser->parse_data($record->{text}); } my $r_l = reply_headers($entity); $output .= q(reply); $output .= ')'.":
\n"; $output .= handle_email_message($entity, ref => $bug_number, msg_num => $msg_number, %param, ); } else { die "Unknown record type $_"; } return $output; } sub __libravatar_url { my ($email) = @_; if (not defined $config{libravatar_uri} or not length $config{libravatar_uri}) { return undef; } ($email) = grep {/\@/} get_addresses($email); return $config{libravatar_uri}.uri_escape_utf8($email.($config{libravatar_uri_options}//'')); } 1; __END__ # Local Variables: # cperl-indent-level: 4 # indent-tabs-mode: nil # End: