summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-12-22 20:26:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-12-22 20:26:54 (GMT)
commit2374f1dfd12542d171b60065dc139a96cb0efe29 (patch)
treec7127d33f2a05bfc90c6785bbcaa7f5a2c901fb7 /git-send-email.perl
parentfa7f51d53385ee64858a415f817d6b8485197405 (diff)
parent8d8140843501107c92e2f9a5acb60ee136352c1f (diff)
downloadgit-2374f1dfd12542d171b60065dc139a96cb0efe29.zip
git-2374f1dfd12542d171b60065dc139a96cb0efe29.tar.gz
git-2374f1dfd12542d171b60065dc139a96cb0efe29.tar.bz2
Merge branch 'pb/send-email-te'
"git send-email" learned "--transfer-encoding" option to force a non-fault Content-Transfer-Encoding header (e.g. base64). * pb/send-email-te: git-send-email: add --transfer-encoding option git-send-email: delay creation of MIME headers
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl61
1 files changed, 55 insertions, 6 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 9949db0..82c6fea 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -58,6 +58,7 @@ git send-email [options] <file | directory | rev-list options >
--compose * Open an editor for introduction.
--compose-encoding <str> * Encoding to assume for introduction.
--8bit-encoding <str> * Encoding to assume 8bit mails if undeclared
+ --transfer-encoding <str> * Transfer encoding to use (quoted-printable, 8bit, base64)
Sending:
--envelope-sender <str> * Email envelope sender.
@@ -206,6 +207,7 @@ my ($validate, $confirm);
my (@suppress_cc);
my ($auto_8bit_encoding);
my ($compose_encoding);
+my ($target_xfer_encoding);
my ($debug_net_smtp) = 0; # Net::SMTP, see send_message()
@@ -242,6 +244,7 @@ my %config_settings = (
"from" => \$sender,
"assume8bitencoding" => \$auto_8bit_encoding,
"composeencoding" => \$compose_encoding,
+ "transferencoding" => \$target_xfer_encoding,
);
my %config_path_settings = (
@@ -314,6 +317,7 @@ my $rc = GetOptions("h" => \$help,
"envelope-sender=s" => \$envelope_sender,
"thread!" => \$thread,
"validate!" => \$validate,
+ "transfer-encoding=s" => \$target_xfer_encoding,
"format-patch!" => \$format_patch,
"8bit-encoding=s" => \$auto_8bit_encoding,
"compose-encoding=s" => \$compose_encoding,
@@ -1324,6 +1328,8 @@ foreach my $t (@files) {
my $author_encoding;
my $has_content_type;
my $body_encoding;
+ my $xfer_encoding;
+ my $has_mime_version;
@to = ();
@cc = ();
@xh = ();
@@ -1394,9 +1400,16 @@ foreach my $t (@files) {
}
push @xh, $_;
}
+ elsif (/^MIME-Version/i) {
+ $has_mime_version = 1;
+ push @xh, $_;
+ }
elsif (/^Message-Id: (.*)/i) {
$message_id = $1;
}
+ elsif (/^Content-Transfer-Encoding: (.*)/i) {
+ $xfer_encoding = $1 if not defined $xfer_encoding;
+ }
elsif (!/^Date:\s/i && /^[-A-Za-z]+:\s+\S/) {
push @xh, $_;
}
@@ -1444,10 +1457,9 @@ foreach my $t (@files) {
if defined $cc_cmd && !$suppress_cc{'cccmd'};
if ($broken_encoding{$t} && !$has_content_type) {
+ $xfer_encoding = '8bit' if not defined $xfer_encoding;
$has_content_type = 1;
- push @xh, "MIME-Version: 1.0",
- "Content-Type: text/plain; charset=$auto_8bit_encoding",
- "Content-Transfer-Encoding: 8bit";
+ push @xh, "Content-Type: text/plain; charset=$auto_8bit_encoding";
$body_encoding = $auto_8bit_encoding;
}
@@ -1467,14 +1479,25 @@ foreach my $t (@files) {
}
}
else {
+ $xfer_encoding = '8bit' if not defined $xfer_encoding;
$has_content_type = 1;
push @xh,
- 'MIME-Version: 1.0',
- "Content-Type: text/plain; charset=$author_encoding",
- 'Content-Transfer-Encoding: 8bit';
+ "Content-Type: text/plain; charset=$author_encoding";
}
}
}
+ if (defined $target_xfer_encoding) {
+ $xfer_encoding = '8bit' if not defined $xfer_encoding;
+ $message = apply_transfer_encoding(
+ $message, $xfer_encoding, $target_xfer_encoding);
+ $xfer_encoding = $target_xfer_encoding;
+ }
+ if (defined $xfer_encoding) {
+ push @xh, "Content-Transfer-Encoding: $xfer_encoding";
+ }
+ if (defined $xfer_encoding or $has_content_type) {
+ unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
+ }
$needs_confirm = (
$confirm eq "always" or
@@ -1543,6 +1566,32 @@ sub cleanup_compose_files {
$smtp->quit if $smtp;
+sub apply_transfer_encoding {
+ my $message = shift;
+ my $from = shift;
+ my $to = shift;
+
+ return $message if ($from eq $to and $from ne '7bit');
+
+ require MIME::QuotedPrint;
+ require MIME::Base64;
+
+ $message = MIME::QuotedPrint::decode($message)
+ if ($from eq 'quoted-printable');
+ $message = MIME::Base64::decode($message)
+ if ($from eq 'base64');
+
+ die "cannot send message as 7bit"
+ if ($to eq '7bit' and $message =~ /[^[:ascii:]]/);
+ return $message
+ if ($to eq '7bit' or $to eq '8bit');
+ return MIME::QuotedPrint::encode($message, "\n", 0)
+ if ($to eq 'quoted-printable');
+ return MIME::Base64::encode($message, "\n")
+ if ($to eq 'base64');
+ die "invalid transfer encoding";
+}
+
sub unique_email_list {
my %seen;
my @emails;