* Fix unescaped From (closes: #983847)
* Actually return message/rfc822 when there is a single message instead
of mbox (closes: #1009181)
+ * Fix missing escaping of comma in address fields (closes: #1041638)
-- Don Armstrong <don@debian.org> Fri, 09 Mar 2018 11:17:10 -0800
%EXPORT_TAGS = (mime => [qw(parse create_mime_message getmailbody),
qw(parse_to_mime_entity),
],
- rfc1522 => [qw(decode_rfc1522 encode_rfc1522)],
+ rfc1522 => [qw(decode_rfc1522 encode_rfc1522 handle_escaped_commas)],
);
@EXPORT_OK=();
Exporter::export_ok_tags(keys %EXPORT_TAGS);
use File::Path qw(remove_tree);
use File::Temp qw(tempdir);
use MIME::Parser;
+use Mail::Message::Field;
use POSIX qw(strftime);
use List::AllUtils qw(apply);
return $string;
}
+=head2
+
+ $header = handle_escaped_commas('','From: ')
+
+Handle commas in addresses which have been RFC1522 escaped and now need to be
+quoted to avoid parsing as a record separator.
+
+=cut
+
+sub handle_escaped_commas {
+ my ($modified_hdr, $orig_hdr) = @_;
+
+ my $field = Mail::Message::Field->new($orig_hdr);
+ # if the header isn't structured, it can't contain an address
+ if (not $field->isStructured()) {
+ return $modified_hdr
+ }
+ if ($field->name() !~ m/^(?:to|from|reply-to)$/) {
+ return $modified_hdr
+ }
+ my @addresses = $field->addresses();
+ if (not @addresses) {
+ return $modified_hdr
+ }
+ my @return_addresses;
+ for my $address (@addresses) {
+ $address->phrase(decode_rfc1522($address->phrase()));
+ push @return_addresses, $address->format();
+ }
+ return join(', ',@return_addresses)
+}
+
1;
mail-followup-to|
references):
|From\s|X-Debbugs-)/xi;
- $fwd .= encode_utf8($hdr)."\n" if $ins;
+ $fwd .= $orig_hdr."\n" if $ins;
# print {$debugfh} ">$_<\n";
if (s/^(\S+):\s*//) {
my $v = lc $1;
push @common_headers, 'X-Loop',$_;
}
print {$debugfh} ">$v=$_<\n";
- $header{$v} = $_;
+ # Handle a comma which is escaped being passed through un-escaped. See
+ # https://bugs.debian.org/1041638
+ if ($_ =~ m/,/ and not $orig_hdr =~ m/,/) {
+ $header{$v} = handle_escaped_commas($_,$orig_hdr);
+ } else {
+ $header{$v} = $_;
+ }
} else {
print {$debugfh} "!>$_<\n";
}
);
}
}
- if ($name eq 'usertags'){
+ if ($name eq 'usertags' and defined $current_user){
my %user_tags;
read_usertags(\%user_tags, $current_user);
$value =~ s/(?:^\s+|\s+$)//g;
# -*- mode: cperl;-*-
# $Id: 01_mime.t,v 1.1 2005/08/17 21:46:17 don Exp $
-use Test::More tests => 6;
+use Test::More tests => 7;
use warnings;
use strict;
"encode_rfc1522 encodes strings that decode_rfc1522 can decode");
ok(Debbugs::MIME::decode_rfc1522(Debbugs::MIME::encode_rfc1522(encode_utf8($test_str3))) eq $test_str3,
"encode_rfc1522 properly handles parenthesis and \"");
-
+ok(Debbugs::MIME::handle_escaped_commas(q(),q(From: =?UTF-8?Q?Armstrong=2C?= Don <don@donarmstrong.com>)) eq q("Armstrong, Don" <don@donarmstrong.com>),
+ "handle_escaped_commas properly handles commas in RFC1522 encoded strings");
# Make sure that create_mime_message has encoded headers and doesn't enclude any 8-bit characters