Skip to content

Commit ce54780

Browse files
Krzysztof Mazurpeff
authored andcommitted
git-send-email: introduce quote_subject()
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 <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 5637d85 commit ce54780

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

git-send-email.perl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,7 @@ sub get_patch_subject {
657657
$initial_subject = $1;
658658
my $subject = $initial_subject;
659659
$_ = "Subject: " .
660-
($subject =~ /[^[:ascii:]]/ ?
661-
quote_rfc2047($subject, $compose_encoding) :
662-
$subject) .
660+
quote_subject($subject, $compose_encoding) .
663661
"\n";
664662
} elsif (/^In-Reply-To:\s*(.+)\s*$/i) {
665663
$initial_reply_to = $1;
@@ -907,6 +905,22 @@ sub is_rfc2047_quoted {
907905
$s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o;
908906
}
909907

908+
sub subject_needs_rfc2047_quoting {
909+
my $s = shift;
910+
911+
return ($s =~ /[^[:ascii:]]/);
912+
}
913+
914+
sub quote_subject {
915+
local $subject = shift;
916+
my $encoding = shift || 'UTF-8';
917+
918+
if (subject_needs_rfc2047_quoting($subject)) {
919+
return quote_rfc2047($subject, $encoding);
920+
}
921+
return $subject;
922+
}
923+
910924
# use the simplest quoting being able to handle the recipient
911925
sub sanitize_address {
912926
my ($recipient) = @_;
@@ -1327,9 +1341,8 @@ sub send_message {
13271341
$body_encoding = $auto_8bit_encoding;
13281342
}
13291343

1330-
if ($broken_encoding{$t} && !is_rfc2047_quoted($subject) &&
1331-
($subject =~ /[^[:ascii:]]/)) {
1332-
$subject = quote_rfc2047($subject, $auto_8bit_encoding);
1344+
if ($broken_encoding{$t} && !is_rfc2047_quoted($subject)) {
1345+
$subject = quote_subject($subject, $auto_8bit_encoding);
13331346
}
13341347

13351348
if (defined $author and $author ne $sender) {

0 commit comments

Comments
 (0)