Skip to contentSkip to conversation

send-email: impose a delay while sending to appease GMail

PATCH Superseded Ævar Arnfjörð Bjarmason 6 participants 14 messages Mar 25, 2018 – Aug 14, 2018 Documentation

lore
Share & tools
lore
#0 lore raw

cover send-email: impose a delay while sending to appease GMail

GMail doesn't sort E-Mail by the "Date" header, but by when the E-Mail was received. As a result patches sent to the git ML and LKML (and friends) show up out of order in GMail.

This series works around that issue by sleeping for 1 second between sending E-Mails.

If you're on the LKML and wondering why you got this, I figured feedback from the other big user (that I know of) of send-email would be helpful.

Ævar Arnfjörð Bjarmason (2):
send-email: add an option to impose delay sent E-Mails
send-email: supply a --send-delay=1 by default

 Documentation/config.txt         | 17 ++++++++++
 Documentation/git-send-email.txt |  4 +++
 git-send-email.perl              | 15 +++++++--
 t/t9001-send-email.sh            | 55 ++++++++++++++++++++++++++++++++
 4 files changed, 89 insertions(+), 2 deletions(-)
Signature · 1 line
2.16.2.804.g6dcf76e118
#1 lore raw

PATCH 1/2 send-email: add an option to impose delay sent E-Mails

Add a --send-delay option with a corresponding sendemail.smtpSendDelay configuration variable. When set to e.g. 2, this causes send-email to sleep 2 seconds before sending the next E-Mail. We'll only sleep between sends, not before the first send, or after the last.

This option is useful because certain popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

Google's GMail is a good example of such a client. It ostensibly sorts by some approximation of received time (although not by any "Received" header). It's more usual than not to see patches showing out of order in GMail. To take a few examples of orders seen on recent patches on the Git mailing list:

    1 -> 3 -> 4 -> 2 -> 8 -> 7 (completion by Nguyễn Thái Ngọc Duy)
    2 -> 0 -> 1 -> 3 (pack search by Derrick Stolee)
    3 -> 2 -> 1 (fast-import by Jameson Miller)
    2 -> 3 -> 1 -> 5 -> 4 -> 6 (diff-highlight by Jeff King)

My own patches to Git are always in order because this bothers me enough that I never use the "all" option to send-email, instead I wait a second and manually type "y" for each one, so I have years of anecdotal data showing that this works with GMail. This new option will allow me to set a config to do what I've been doing manually.

I've also noticed that E-Mail from some other contributors tends to be in order, e.g. Michael Haggerty's usually are. When I asked him about he just uses the "all" option, but digging further revealed that the details of his mail routing were imposing a similar delay, so his mails similarly arrived at Google with some delay.

The reason to add the new "X-Mailer-Send-Delay" header is to make it easy to tell what the imposed delay was, if any. A subsequent change will seek to make this option the default, being able to see from the headers how long the sleep was.

The reason for why the getopt format is "send-delay=s" instead of "send-delay=d" is because we're doing manual validation of the value we get passed, which getopt would corrupt in cases of e.g. float values before we could show a sensible error message.

---
 Documentation/config.txt         |  6 ++++
 Documentation/git-send-email.txt |  4 +++
 git-send-email.perl              | 14 ++++++--
 t/t9001-send-email.sh            | 55 ++++++++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)
Documentation/config.txt +6 -0
index ce9102cea8..f155d349c0 100644
@@ -3068,6 +3068,12 @@ sendemail.smtpReloginDelay::
 	Seconds wait before reconnecting to smtp server.
 	See also the `--relogin-delay` option of linkgit:git-send-email[1].
 
+sendemail.smtpSendDelay::
+	Seconds wait in between message sending before sending another
+	message. Set it to 0 to impose no extra delay, defaults to 0.
++
+See also the `--send-delay` option of linkgit:git-send-email[1].
+
 showbranch.default::
 	The default set of branches for linkgit:git-show-branch[1].
 	See linkgit:git-show-branch[1].
Documentation/git-send-email.txt +4 -0
index 71ef97ba9b..169ad78a2b 100644
@@ -268,6 +268,10 @@ must be used for each option.
 	with --batch-size option.  Defaults to the `sendemail.smtpReloginDelay`
 	configuration variable.
 
+--send-delay=<int>::
+	Wait $<int> between sending emails. Defaults to the
+	`sendemail.smtpSendDelay` configuration variable.
+
 Automating
 ~~~~~~~~~~
 
git-send-email.perl +12 -2
index 2fa7818ca9..013277ede2 100755
@@ -89,6 +89,7 @@ git send-email --dump-aliases
     --batch-size            <int>  * send max <int> message per connection.
     --relogin-delay         <int>  * delay <int> seconds between two successive login.
                                      This option can only be used with --batch-size
+    --send-delay            <int>  * ensure that <int> seconds pass between two successive sends.
 
   Automating:
     --identity              <str>  * Use the sendemail.<id> options.
@@ -225,7 +226,7 @@ my ($cover_cc, $cover_to);
 my ($to_cmd, $cc_cmd);
 my ($smtp_server, $smtp_server_port, @smtp_server_options);
 my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
-my ($batch_size, $relogin_delay);
+my ($batch_size, $relogin_delay, $send_delay);
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -259,6 +260,7 @@ my %config_settings = (
     "smtpauth" => \$smtp_auth,
     "smtpbatchsize" => \$batch_size,
     "smtprelogindelay" => \$relogin_delay,
+    "smtpsenddelay" => \$send_delay,
     "to" => \@initial_to,
     "tocmd" => \$to_cmd,
     "cc" => \@initial_cc,
@@ -373,6 +375,7 @@ $rc = GetOptions(
 		    "no-xmailer" => sub {$use_xmailer = 0},
 		    "batch-size=i" => \$batch_size,
 		    "relogin-delay=i" => \$relogin_delay,
+		    "send-delay=s" => \$send_delay,
 	 );
 
 usage() if $help;
@@ -484,6 +487,8 @@ if ($confirm_unconfigured) {
 };
 die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
 	unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
+die sprintf(__("Invalid --send-delay setting: '%s'\n"), $send_delay)
+	if defined $send_delay and $send_delay !~ /^[0-9]+$/s;
 
 # Debugging, print out the suppressions.
 if (0) {
@@ -1552,7 +1557,8 @@ $references = $initial_in_reply_to || '';
 $subject = $initial_subject;
 $message_num = 0;
 
-foreach my $t (@files) {
+foreach my $i (0 .. $#files) {
+	my $t = $files[$i];
 	open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
 
 	my $author = undef;
@@ -1732,6 +1738,10 @@ foreach my $t (@files) {
 	if (defined $xfer_encoding or $has_content_type) {
 		unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
 	}
+	if ($send_delay && $i > 0) {
+		push @xh, "X-Mailer-Send-Delay: $send_delay";
+		sleep $send_delay;
+	}
 
 	$needs_confirm = (
 		$confirm eq "always" or
t/t9001-send-email.sh +55 -0

61 lines not on this page · raw message

Signature · 1 line
2.16.2.804.g6dcf76e118
#2 lore raw

PATCH 2/2 send-email: supply a --send-delay=1 by default

In reply to Ævar Arnfjörð Bjarmason

The earlier change to add this option described the problem this option is trying to solve.

This turns it on by default with a value of 1 second, which'll hopefully solve it, and if not user reports as well as the X-Mailer-Send-Delay header should help debug it.

I think the trade-off of slowing down E-Mail sending to turn this on makes sense because:

* GMail is a really common client, git.git's own unique authors by %aE are ~30% @gmail.com, ~20% for linux.git. That's just patch submitters, my guess is this it's much more common among those who mostly read the list, and those users who aren't using mu4e / mutt etc. anyway.

* There's really no point in having this feature at all if it's not made the default, since the entire point is to be able to read a list like the git ML or the LKML and have patches from others show up in order.

* I don't think anyone's really sensitive to the sending part of send-email taking longer. You just choose "all" and then switch to another terminal while it does its thing if you have a huge series, and for 1-3 patches I doubt anyone would notice this anyway.

---
 Documentation/config.txt | 13 ++++++++++++-
 git-send-email.perl      |  1 +
 t/t9001-send-email.sh    |  4 ++--
 3 files changed, 15 insertions(+), 3 deletions(-)
Documentation/config.txt +12 -1
index f155d349c0..bd578642c1 100644
@@ -3070,7 +3070,18 @@ sendemail.smtpReloginDelay::
 
 sendemail.smtpSendDelay::
 	Seconds wait in between message sending before sending another
-	message. Set it to 0 to impose no extra delay, defaults to 0.
+	message. Set it to 0 to impose no extra delay, defaults to 1
+	to wait 1 second.
++
+The reason for imposing a default delay is because certain popular
+E-Mail clients such as Google's GMail completely ignore the "Date"
+header, which format-patch is careful to set such that the patches
+will be displayed in order, and instead sort by the time the E-mail
+was received.
++
+This causes sent E-Mail to be shown completely out of order in such
+clients, imposing the delay is a workaround that should usually work
+(although it's by no means guaranteed).
 +
 See also the `--send-delay` option of linkgit:git-send-email[1].
 
git-send-email.perl +1 -0
index 013277ede2..ddbc44f1c9 100755
@@ -489,6 +489,7 @@ die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
 	unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
 die sprintf(__("Invalid --send-delay setting: '%s'\n"), $send_delay)
 	if defined $send_delay and $send_delay !~ /^[0-9]+$/s;
+$send_delay = 1 unless defined $send_delay;
 
 # Debugging, print out the suppressions.
 if (0) {
t/t9001-send-email.sh +2 -2
index fafa61c5d6..1580e00fce 100755
@@ -1713,7 +1713,7 @@ test_expect_success '--send-delay expects whole non-negative seconds' '
 	test_i18ngrep "Invalid --send-delay setting" errors
 '
 
-test_expect_success $PREREQ "there is no default --send-delay" '
+test_expect_success $PREREQ "there is a default --send-delay" '
 	clean_fake_sendmail &&
 	rm -fr outdir &&
 	git format-patch -3 -o outdir &&
@@ -1724,7 +1724,7 @@ test_expect_success $PREREQ "there is no default --send-delay" '
 		outdir/*.patch \
 		2>stderr >stdout &&
 	test $(grep -c "X-Mailer:" stdout) = 3 &&
-	test $(grep -c "X-Mailer-Send-Delay:" stdout) = 0
+	test $(grep -c "X-Mailer-Send-Delay:" stdout) = 2
 '
 
 test_expect_success $PREREQ '--send-delay adds a X-Mailer-Send-Delay header to affected E-Mails' '
Signature · 1 line
2.16.2.804.g6dcf76e118
#3 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

Quoted 21 lines · Ævar Arnfjörð Bjarmason

The earlier change to add this option described the problem this option is trying to solve.

This turns it on by default with a value of 1 second, which'll hopefully solve it, and if not user reports as well as the X-Mailer-Send-Delay header should help debug it.

I think the trade-off of slowing down E-Mail sending to turn this on makes sense because:

* GMail is a really common client, git.git's own unique authors by %aE are ~30% @gmail.com, ~20% for linux.git. That's just patch submitters, my guess is this it's much more common among those who mostly read the list, and those users who aren't using mu4e / mutt etc. anyway.

* There's really no point in having this feature at all if it's not made the default, since the entire point is to be able to read a list like the git ML or the LKML and have patches from others show up in order.

Quoted 4 lines

* I don't think anyone's really sensitive to the sending part of send-email taking longer. You just choose "all" and then switch to another terminal while it does its thing if you have a huge series, and for 1-3 patches I doubt anyone would notice this anyway.

I'm not sure that this is going to have the effect you want it to have. Let me give an example to demonstrate why.

If I send a series to the list, in order for this to work, you need my SMTP server (Postfix) to essentially send mails slowly enough to vger.kernel.org (ZMailer) that it doesn't batch them when it sends them to GMail. The problem is that with my mail server, due to filtering and such, already takes at least a second to accept, process, and relay submitted messages. vger still batched them and delivered them back to me out of order. This will be even worse with large series.

You are also assuming that my mail server will not have batched them and delivered them out of order, which it might well do, since Postfix uses a connection cache to machines that don't do STARTTLS (which, much to my annoyance, vger doesn't offer).

In short, I don't think this is going to be especially helpful because it won't change the status quo for a lot of senders. You'd have to insert some significant delay in order to get the effect you desire, and even then things could still be delivered out of order.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
#4 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

Quoted 43 lines · brian m. carlson
Quoted 21 lines · Ævar Arnfjörð Bjarmason

The earlier change to add this option described the problem this option is trying to solve.

This turns it on by default with a value of 1 second, which'll hopefully solve it, and if not user reports as well as the X-Mailer-Send-Delay header should help debug it.

I think the trade-off of slowing down E-Mail sending to turn this on makes sense because:

* GMail is a really common client, git.git's own unique authors by %aE are ~30% @gmail.com, ~20% for linux.git. That's just patch submitters, my guess is this it's much more common among those who mostly read the list, and those users who aren't using mu4e / mutt etc. anyway.

* There's really no point in having this feature at all if it's not made the default, since the entire point is to be able to read a list like the git ML or the LKML and have patches from others show up in order.

Quoted 4 lines

* I don't think anyone's really sensitive to the sending part of send-email taking longer. You just choose "all" and then switch to another terminal while it does its thing if you have a huge series, and for 1-3 patches I doubt anyone would notice this anyway.

I'm not sure that this is going to have the effect you want it to have. Let me give an example to demonstrate why.

If I send a series to the list, in order for this to work, you need my SMTP server (Postfix) to essentially send mails slowly enough to vger.kernel.org (ZMailer) that it doesn't batch them when it sends them to GMail. The problem is that with my mail server, due to filtering and such, already takes at least a second to accept, process, and relay submitted messages. vger still batched them and delivered them back to me out of order. This will be even worse with large series.

You are also assuming that my mail server will not have batched them and delivered them out of order, which it might well do, since Postfix uses a connection cache to machines that don't do STARTTLS (which, much to my annoyance, vger doesn't offer).

Quoted 4 lines

In short, I don't think this is going to be especially helpful because it won't change the status quo for a lot of senders. You'd have to insert some significant delay in order to get the effect you desire, and even then things could still be delivered out of order.

Good point. I also see that (via git log --author=Ævar --grep='^\[PATCH ') that this series itself arrived out of order (0 -> 2 -> 1), but I don't know to what extent public-inbox itself might be batching things.

It would be interesting to get reports from other GMail users as to what order these mails were shown in, but I think as soon as they're replied to that info's gone, at least for 2/2, which is the potentially out of order one in this case.

In general I realize that this won't be a general solution that'll work in all cases. E.g. I have a local SMTP on my laptop, if I'm on a plane it wouldn't matter if the delay was 2 hours, it would be batched up locally and sent all at once.

I was hoping we could find some sweet spot where the systems along the way (common smtpd's, majordomo, public-inbox's git repo) would as a result get this right most of the time for the purposes of appeasing this really common mail client, but maybe that's not going to work out.

#5 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

Quoted 3 lines · Ævar Arnfjörð Bjarmason

Good point. I also see that (via git log --author=Ævar --grep='^\[PATCH ') that this series itself arrived out of order (0 -> 2 -> 1), but I don't know to what extent public-inbox itself might be batching things.

public-inbox doesn't batch, aside from when the public-inbox-watch process gets restarted and needs to catch up using readdir. Once it's done catching up with readdir, it gets into an inotify loop which injects messages in the order the MTA (or offlineimap) puts them in a Maildir.

Right now, public-inbox only sorts by Date: header in the mail.

The next Xapian schema revision of public-inbox will use internally sorts search results(*) by the date in the newest
Received: header. That is analogous to git committer date. The displayed message date will still be sorted by the Date: header (analogous to git author date); since git-send-email already alters the Date: in a series for sorting.

This allow messages/threads which are actually new get bumped to the top of the homepage; regardless of how wrong the original sender's clock was.

It should help prevent kernel developers from crafting message dates with optimization for classic^Wextra reviews in mind :)

(*) all the look-at-a-bunch-of-messages operations, including
the landing page (e.g. https://public-inbox.org/git/)
is a Xapian search query, nowadays; but "git log"

#6 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

In reply to brian m. carlson
Quoted 7 lines · brian m. carlson

I'm not sure that this is going to have the effect you want it to have. Let me give an example to demonstrate why.
...
In short, I don't think this is going to be especially helpful because it won't change the status quo for a lot of senders. You'd have to insert some significant delay in order to get the effect you desire, and even then things could still be delivered out of order.

Thanks for explaining it clearly.

In the past on this list those who do not get the store-and-forward nature of e-mail transport have brought this up a few times, but this approach fundamentally do not work, at least for the purpose of forcing ordering of messages at the receiving end.

#7 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

In reply to Ævar Arnfjörð Bjarmason
Quoted 12 lines · Ævar Arnfjörð Bjarmason

The earlier change to add this option described the problem this option is trying to solve.

This turns it on by default with a value of 1 second, which'll hopefully solve it, and if not user reports as well as the X-Mailer-Send-Delay header should help debug it.

---

Documentation/config.txt +0 -0
@@ -3070,7 +3070,18 @@ sendemail.smtpReloginDelay::
 sendemail.smtpSendDelay::

Documentation/config.txt sendemail.smtpReloginDelay:: · line 3079

Quoted 10 lines
Documentation/config.txt +8 -1
        Seconds wait in between message sending before sending another
-       message. Set it to 0 to impose no extra delay, defaults to 0.
+       message. Set it to 0 to impose no extra delay, defaults to 1
+       to wait 1 second.
++
+The reason for imposing a default delay is because certain popular
+E-Mail clients such as Google's GMail completely ignore the "Date"
+header, which format-patch is careful to set such that the patches
+will be displayed in order, and instead sort by the time the E-mail
+was received.

A minor point: Are you sure that it's git-format-patch that's being careful about arranging Date: to display in the desired order, and not git-send-email? Looking at old patches I still have hanging around which were created with git-format-patch, I see the Date: headers are wildly out of order, presumably because the date is taken from
Author-Date: and the patches were heavily rebased.

#8 lore raw

Re: [PATCH 2/2] send-email: supply a --send-delay=1 by default

Quoted 6 lines · Eric Sunshine

A minor point: Are you sure that it's git-format-patch that's being careful about arranging Date: to display in the desired order, and not git-send-email? Looking at old patches I still have hanging around which were created with git-format-patch, I see the Date: headers are wildly out of order, presumably because the date is taken from
Author-Date: and the patches were heavily rebased.

send-email uses the current time as the timestamp it lets MTA to see (and for a N-patch series, the first patch gets current time minus N, and later patches get newer timestamps with 1 second increment).

The Date: field in the input file to the command has nothing to participate in this process; sending a series that has patches that have been shuffled with "rebase -i" would still give older timestamp to the earlier message while sending the series out.

That is sufficient for any MUA that is capable of sorting the messages in the sender's timestamp order; even though there is no way to force the actual order in which an MTA on the receiving end sees the messages, it is not necessary and it would not help X-<.

#9 lore raw

PATCH v2 1/1 send-email: add an option to impose delay sent E-Mails

In reply to Ævar Arnfjörð Bjarmason

Add a --send-delay option with a corresponding sendemail.smtpSendDelay configuration variable. When set to e.g. 2, this causes send-email to sleep 2 seconds before sending the next E-Mail. We'll only sleep between sends, not before the first send, or after the last.

This option has two uses. Firstly, to be able to Ctrl+C a long send with "all" if you have a change of heart. Secondly, as a hack in some mail setups to, with a sufficiently high delay, force the receiving client to sort the E-Mails correctly.

Some popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

Google's GMail is a good example of such a client. It ostensibly sorts by some approximation of received time (although not by any "Received" header). It's more usual than not to see patches showing out of order in GMail. To take a few examples of orders seen on patches on the Git mailing list:

    1 -> 3 -> 4 -> 2 -> 8 -> 7 (completion by Nguyễn Thái Ngọc Duy)
    2 -> 0 -> 1 -> 3 (pack search by Derrick Stolee)
    3 -> 2 -> 1 (fast-import by Jameson Miller)
    2 -> 3 -> 1 -> 5 -> 4 -> 6 (diff-highlight by Jeff King)

The reason to add the new "X-Mailer-Send-Delay" header is to make it easy to tell what the imposed delay was, if any. This allows for gathering some data on how the transfer of E-Mails with & without this option behaves. This may not be workable without really long delays, see [1] and [2].

The reason for why the getopt format is "send-delay=s" instead of "send-delay=d" is because we're doing manual validation of the value we get passed, which getopt would corrupt in cases of e.g. float values before we could show a sensible error message.

1. https://public-inbox.org/git/[email protected]/
2. https://public-inbox.org/git/[email protected]/

---

I submitted this back in March hoping it would solve mail ordering problems, but the other motive I had for this is that I'm paranoid that I'm sending out bad E-Mails, and tend to "y" to each one because "a" is too fast.

So I'm re-sending this with an updated commit message & rationale, and not sending 2/2 to toggle this on by default. I'd still like to have this feature.

 Documentation/config.txt         |  6 ++++
 Documentation/git-send-email.txt |  4 +++
 git-send-email.perl              | 18 ++++++++---
 t/t9001-send-email.sh            | 55 ++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
Documentation/config.txt +6 -0
index 63365dcf3d..5eb81b64a7 100644
@@ -3216,6 +3216,12 @@ sendemail.smtpReloginDelay::
 	Seconds wait before reconnecting to smtp server.
 	See also the `--relogin-delay` option of linkgit:git-send-email[1].
 
+sendemail.smtpSendDelay::
+	Seconds wait in between message sending before sending another
+	message. Set it to 0 to impose no extra delay, defaults to 0.
++
+See also the `--send-delay` option of linkgit:git-send-email[1].
+
 showbranch.default::
 	The default set of branches for linkgit:git-show-branch[1].
 	See linkgit:git-show-branch[1].
Documentation/git-send-email.txt +4 -0
index 465a4ecbed..98fdd9b803 100644
@@ -270,6 +270,10 @@ must be used for each option.
 	with --batch-size option.  Defaults to the `sendemail.smtpReloginDelay`
 	configuration variable.
 
+--send-delay=<int>::
+	Wait $<int> between sending emails. Defaults to the
+	`sendemail.smtpSendDelay` configuration variable.
+
 Automating
 ~~~~~~~~~~
 
git-send-email.perl +14 -4
index 2be5dac337..65b53ee9f1 100755
@@ -89,6 +89,7 @@ sub usage {
     --batch-size            <int>  * send max <int> message per connection.
     --relogin-delay         <int>  * delay <int> seconds between two successive login.
                                      This option can only be used with --batch-size
+    --send-delay            <int>  * ensure that <int> seconds pass between two successive sends.
 
   Automating:
     --identity              <str>  * Use the sendemail.<id> options.
@@ -225,7 +226,7 @@ sub do_edit {
 my ($to_cmd, $cc_cmd);
 my ($smtp_server, $smtp_server_port, @smtp_server_options);
 my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path);
-my ($batch_size, $relogin_delay);
+my ($batch_size, $relogin_delay, $send_delay);
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -259,6 +260,7 @@ sub do_edit {
     "smtpauth" => \$smtp_auth,
     "smtpbatchsize" => \$batch_size,
     "smtprelogindelay" => \$relogin_delay,
+    "smtpsenddelay" => \$send_delay,
     "to" => \@initial_to,
     "tocmd" => \$to_cmd,
     "cc" => \@initial_cc,
@@ -373,6 +375,7 @@ sub signal_handler {
 		    "no-xmailer" => sub {$use_xmailer = 0},
 		    "batch-size=i" => \$batch_size,
 		    "relogin-delay=i" => \$relogin_delay,
+		    "send-delay=s" => \$send_delay,
 	 );
 
 usage() if $help;
@@ -484,6 +487,8 @@ sub read_config {
 };
 die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
 	unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
+die sprintf(__("Invalid --send-delay setting: '%s'\n"), $send_delay)
+	if defined $send_delay and $send_delay !~ /^[0-9]+$/s;
 
 # Debugging, print out the suppressions.
 if (0) {
@@ -1562,7 +1567,8 @@ sub send_message {
 # Returns 0 if an edit was done and the function should be called again, or 1
 # otherwise.
 sub process_file {
-	my ($t) = @_;
+	my ($i) = @_;
+	my $t = $files[$i];
 
 	open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
 
@@ -1741,6 +1747,10 @@ sub process_file {
 		$message, $xfer_encoding, $target_xfer_encoding);
 	push @xh, "Content-Transfer-Encoding: $xfer_encoding";
 	unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
+	if ($send_delay && $i > 0) {
+		push @xh, "X-Mailer-Send-Delay: $send_delay";
+		sleep $send_delay;
+	}
 
 	$needs_confirm = (
 		$confirm eq "always" or
@@ -1793,8 +1803,8 @@ sub process_file {
 	return 1;
 }
 
-foreach my $t (@files) {
-	while (!process_file($t)) {
+foreach my $i (0 .. $#files) {
+	while (!process_file($i)) {
 		# user edited the file
 	}
 }
t/t9001-send-email.sh +55 -0

61 lines not on this page · raw message

Signature · 1 line
2.18.0.865.gffc8e1a3cd6
#10 lore raw

Re: [PATCH v2] send-email: add an option to impose delay sent E-Mails

Quoted 40 lines · Ævar Arnfjörð Bjarmason

Add a --send-delay option with a corresponding sendemail.smtpSendDelay configuration variable. When set to e.g. 2, this causes send-email to sleep 2 seconds before sending the next E-Mail. We'll only sleep between sends, not before the first send, or after the last.

This option has two uses. Firstly, to be able to Ctrl+C a long send with "all" if you have a change of heart. Secondly, as a hack in some mail setups to, with a sufficiently high delay, force the receiving client to sort the E-Mails correctly.

Some popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

Google's GMail is a good example of such a client. It ostensibly sorts by some approximation of received time (although not by any "Received" header). It's more usual than not to see patches showing out of order in GMail. To take a few examples of orders seen on patches on the Git mailing list:

    1 -> 3 -> 4 -> 2 -> 8 -> 7 (completion by Nguyễn Thái Ngọc Duy)
    2 -> 0 -> 1 -> 3 (pack search by Derrick Stolee)
    3 -> 2 -> 1 (fast-import by Jameson Miller)
    2 -> 3 -> 1 -> 5 -> 4 -> 6 (diff-highlight by Jeff King)

The reason to add the new "X-Mailer-Send-Delay" header is to make it easy to tell what the imposed delay was, if any. This allows for gathering some data on how the transfer of E-Mails with & without this option behaves. This may not be workable without really long delays, see [1] and [2].

The reason for why the getopt format is "send-delay=s" instead of "send-delay=d" is because we're doing manual validation of the value we get passed, which getopt would corrupt in cases of e.g. float values before we could show a sensible error message.

1. https://public-inbox.org/git/[email protected]/
2. https://public-inbox.org/git/[email protected]/

Quoted 7 lines

---

I submitted this back in March hoping it would solve mail ordering problems, but the other motive I had for this is that I'm paranoid that I'm sending out bad E-Mails, and tend to "y" to each one because "a" is too fast.'

Heh. GMail seems to have added an Undo button in their UI, which would be the same feature as this one. (Hit Ctrl+C in time to "undo" the sending command)

I have been bitten quite a few times by using "a" as I had old series still laying around, such that it would send a new series and parts of the old series (or when you changed subjects and resend another iteration of a series, you may end up with two "patch 1"s).
So I learned to be careful before pressing "a" on sending.

Maybe the underlying issue is that you really only want to send a series and not "all" as send-email asks for.
So maybe that dialog could learn a [s]eries switch, which would check either filenames to count up, or if the base that is recorded (base-commit for first and prerequisite-patch-id for followups) is consistent.

    Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll|[s]eries):

Another note:
I personally never use no/quit, but Ctrl+C for both cases.

This is also different than the feature of 5453b83bdf9 (send-email --batch-size to work around some SMTP server limit, 2017-05-21) which introduced sendemail.smtpReloginDelay, which would offer the same functionality when the batch-size is set to 1. (Although this would keep you connected to the server as well as add the X-Mailer-Send-Delay header, which is nothing from the official email RFC, but your own invention?)

Having sorted mails in GMail would be nice!

Thanks,
Stefan

#11 lore raw

Re: [PATCH v2] send-email: add an option to impose delay sent E-Mails

In reply to Ævar Arnfjörð Bjarmason
Quoted 25 lines · Ævar Arnfjörð Bjarmason

Add a --send-delay option with a corresponding sendemail.smtpSendDelay configuration variable. When set to e.g. 2, this causes send-email to sleep 2 seconds before sending the next E-Mail. We'll only sleep between sends, not before the first send, or after the last.

This option has two uses. Firstly, to be able to Ctrl+C a long send with "all" if you have a change of heart. Secondly, as a hack in some mail setups to, with a sufficiently high delay, force the receiving client to sort the E-Mails correctly.

Some popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

Google's GMail is a good example of such a client. It ostensibly sorts by some approximation of received time (although not by any "Received" header). It's more usual than not to see patches showing out of order in GMail. To take a few examples of orders seen on patches on the Git mailing list:

    1 -> 3 -> 4 -> 2 -> 8 -> 7 (completion by Nguyễn Thái Ngọc Duy)
    2 -> 0 -> 1 -> 3 (pack search by Derrick Stolee)
    3 -> 2 -> 1 (fast-import by Jameson Miller)
    2 -> 3 -> 1 -> 5 -> 4 -> 6 (diff-highlight by Jeff King)
Quoted 5 lines

The reason to add the new "X-Mailer-Send-Delay" header is to make it easy to tell what the imposed delay was, if any. This allows for gathering some data on how the transfer of E-Mails with & without this option behaves. This may not be workable without really long delays, see [1] and [2].

Aside from the new header, I think this is better implemented using the existing $relogin_delay and $batch_size=1.

Disconnecting during the delay might be more sympathetic to existing mail servers (which aren't C10K-optimized). If the client sleeps, the server may disconnect the client anyways to save resources.

git-send-email.perl sub process_file { · line 1753

Quoted 8 lines
git-send-email.perl +4 -0
@@ -1741,6 +1747,10 @@ sub process_file {
 		$message, $xfer_encoding, $target_xfer_encoding);
 	push @xh, "Content-Transfer-Encoding: $xfer_encoding";
 	unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
+	if ($send_delay && $i > 0) {
+		push @xh, "X-Mailer-Send-Delay: $send_delay";
+		sleep $send_delay;
+	}

We can add this header for relogin_delay + batch_size

But maybe --send-delay can be a shortcut for
--relogin-delay and --batch-size=1

#12 lore raw

Re: [PATCH v2] send-email: add an option to impose delay sent E-Mails

Quoted 3 lines · Eric Wong
Quoted 3 lines

Some popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

It is send-email that carefully shows monotonically increasing timestamps so that the sender's datestamp can be used for sorting by the recipient, not format-patch, which records author-date, primarily meant for local replaying, in the generated messages but discarded by send-email.

Quoted 7 lines

Disconnecting during the delay might be more sympathetic to existing mail servers (which aren't C10K-optimized). If the client sleeps, the server may disconnect the client anyways to save resources.

But maybe --send-delay can be a shortcut for
--relogin-delay and --batch-size=1

Both good points to point at a simpler and better solution, I guess.

#13 lore raw

Re: [PATCH v2] send-email: add an option to impose delay sent E-Mails

In reply to Eric Wong
Quoted 32 lines · Eric Wong
Quoted 25 lines · Ævar Arnfjörð Bjarmason

Add a --send-delay option with a corresponding sendemail.smtpSendDelay configuration variable. When set to e.g. 2, this causes send-email to sleep 2 seconds before sending the next E-Mail. We'll only sleep between sends, not before the first send, or after the last.

This option has two uses. Firstly, to be able to Ctrl+C a long send with "all" if you have a change of heart. Secondly, as a hack in some mail setups to, with a sufficiently high delay, force the receiving client to sort the E-Mails correctly.

Some popular E-Mail clients completely ignore the "Date" header, which format-patch is careful to set such that the patches will be displayed in order, and instead sort by the time the E-mail was received.

Google's GMail is a good example of such a client. It ostensibly sorts by some approximation of received time (although not by any "Received" header). It's more usual than not to see patches showing out of order in GMail. To take a few examples of orders seen on patches on the Git mailing list:

    1 -> 3 -> 4 -> 2 -> 8 -> 7 (completion by Nguyễn Thái Ngọc Duy)
    2 -> 0 -> 1 -> 3 (pack search by Derrick Stolee)
    3 -> 2 -> 1 (fast-import by Jameson Miller)
    2 -> 3 -> 1 -> 5 -> 4 -> 6 (diff-highlight by Jeff King)
Quoted 5 lines

The reason to add the new "X-Mailer-Send-Delay" header is to make it easy to tell what the imposed delay was, if any. This allows for gathering some data on how the transfer of E-Mails with & without this option behaves. This may not be workable without really long delays, see [1] and [2].

Quoted 5 lines

Aside from the new header, I think this is better implemented using the existing $relogin_delay and $batch_size=1.

Disconnecting during the delay might be more sympathetic to existing mail servers (which aren't C10K-optimized).

Yeah that's a good point, maybe we're being wasteful on remote resources here.

Quoted 2 lines

If the client sleeps, the server may disconnect the client anyways to save resources.

Seems like something we'd need to deal with anyway, do we?

Quoted 11 lines

git-send-email.perl sub process_file { · line 1753

Quoted 8 lines
git-send-email.perl +4 -0
@@ -1741,6 +1747,10 @@ sub process_file {
 		$message, $xfer_encoding, $target_xfer_encoding);
 	push @xh, "Content-Transfer-Encoding: $xfer_encoding";
 	unshift @xh, 'MIME-Version: 1.0' unless $has_mime_version;
+	if ($send_delay && $i > 0) {
+		push @xh, "X-Mailer-Send-Delay: $send_delay";
+		sleep $send_delay;
+	}

We can add this header for relogin_delay + batch_size

Quoted 2 lines

But maybe --send-delay can be a shortcut for
--relogin-delay and --batch-size=1

I need to enter a password when sending a batch with my SMTP server now, once. With relogin I'd need to enter this N times unless I use whatever auth save facility there is in git-send-email (which I don't use now).

I don't think it makes sense to conflate these two modes.