Skip to content

Commit

Permalink
git-send-email: introduce quote_subject()
Browse files Browse the repository at this point in the history
The quote_rfc2047() always adds RFC2047 quoting. To avoid
quoting ASCII subjects, before calling quote_rfc2047()
subject must be tested for non-ASCII characters. This patch
introduces a new quote_subject() function, which performs
the test and calls quote_rfc2047 only if necessary.

Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
Signed-off-by: Jeff King <peff@peff.net>
  • Loading branch information
Krzysztof Mazur authored and Jeff King committed Oct 25, 2012
1 parent 5637d85 commit ce54780
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,7 @@ sub get_patch_subject {
$initial_subject = $1;
my $subject = $initial_subject;
$_ = "Subject: " .
($subject =~ /[^[:ascii:]]/ ?
quote_rfc2047($subject, $compose_encoding) :
$subject) .
quote_subject($subject, $compose_encoding) .
"\n";
} elsif (/^In-Reply-To:\s*(.+)\s*$/i) {
$initial_reply_to = $1;
Expand Down Expand Up @@ -907,6 +905,22 @@ sub is_rfc2047_quoted {
$s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o;
}

sub subject_needs_rfc2047_quoting {
my $s = shift;

return ($s =~ /[^[:ascii:]]/);
}

sub quote_subject {
local $subject = shift;
my $encoding = shift || 'UTF-8';

if (subject_needs_rfc2047_quoting($subject)) {
return quote_rfc2047($subject, $encoding);
}
return $subject;
}

# use the simplest quoting being able to handle the recipient
sub sanitize_address {
my ($recipient) = @_;
Expand Down Expand Up @@ -1327,9 +1341,8 @@ sub send_message {
$body_encoding = $auto_8bit_encoding;
}

if ($broken_encoding{$t} && !is_rfc2047_quoted($subject) &&
($subject =~ /[^[:ascii:]]/)) {
$subject = quote_rfc2047($subject, $auto_8bit_encoding);
if ($broken_encoding{$t} && !is_rfc2047_quoted($subject)) {
$subject = quote_subject($subject, $auto_8bit_encoding);
}

if (defined $author and $author ne $sender) {
Expand Down

0 comments on commit ce54780

Please sign in to comment.