Re: [PATCH] send-email: error out when relogin delay is missing

2018-02-07 Thread xiaoqiang zhao

> 在 2018年2月8日,上午7:43,Stefan Beller  写道:
> 
> +die __("When a batch size is given, the relogin delay must be set\n")
> +if defined $relogin_delay and not defined $batch_size;
> +
 
According the code, maybe you want to say “When relogin delay is given, a batch 
size must be set “ ?



[PATCH v5] send-email: --batch-size to work around some SMTP server limit

2017-05-21 Thread xiaoqiang zhao
Some email servers (e.g. smtp.163.com) limit the number emails to be
sent per session(connection) and this will lead to a faliure when
sending many messages.

Teach send-email to disconnect after sending a number of messages
(configurable via the --batch-size= option), wait for a few
seconds (configurable via the --relogin-delay= option) and
reconnect, to work around such a limit.

Also add this two configuration option.

Note:
   Re-authentication will happen every $ messages, so it
will be much more acceptable if you use some form of credential helper
(e.g. the 'sendemail.smtppass' config option), otherwise you will have
to retype password every time when asked.

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
---
 Documentation/config.txt   |  8 
 Documentation/git-send-email.txt   | 11 +++
 contrib/completion/git-completion.bash |  2 ++
 git-send-email.perl| 18 ++
 4 files changed, 39 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 96e9cf8b7..173ed63f6 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2917,6 +2917,14 @@ sendemail.xmailer::
 sendemail.signedoffcc (deprecated)::
Deprecated alias for `sendemail.signedoffbycc`.
 
+sendemail.smtpbatchsize::
+   Number of messages to be sent per connection, after that a relogin
+   will happen. if the value is 0 or undefined, send all messages in
+   one connection.
+
+sendemail.smtprelogindelay::
+   Seconds wait before reconnecting to smtp server.
+
 showbranch.default::
The default set of branches for linkgit:git-show-branch[1].
See linkgit:git-show-branch[1].
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 9d66166f6..5380d8c95 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -248,6 +248,17 @@ must be used for each option.
commands and replies will be printed. Useful to debug TLS
connection and authentication problems.
 
+--batch-size=::
+   Some email servers (e.g. smtp.163.com) limit the number emails to be
+   sent per session(connection) and this will lead to a faliure when
+   sending many messages.  With this option, send-email will disconnect 
after
+   sending $ messages and wait for a few seconds (see --relogin-delay)
+   and reconnect, to work around such a limit.
+
+--relogin-delay=::
+   Waiting $ seconds before reconnecting to smtp server. Used together
+   with --batch-size option.
+
 Automating
 ~~
 
diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index 1ed0a09fe..933e7badf 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2611,6 +2611,8 @@ _git_config ()
sendemail.thread
sendemail.to
sendemail.validate
+   sendemail.smtpbatchsize
+   sendemail.smtprelogindelay
showbranch.default
status.relativePaths
status.showUntrackedFiles
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..8a1ee0f0d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,10 @@ git send-email --dump-aliases
  This setting forces to use one of the 
listed mechanisms.
 --smtp-debug<0|1>  * Disable, enable Net::SMTP debug.
 
+--batch-size  * send max  message per connection.
+--relogin-delay   * delay  seconds between two 
successive login.
+ This option can only be used with 
--batch-size
+
   Automating:
 --identity* Use the sendemail. options.
 --to-cmd  * Email To: via ` \$patch_path`
@@ -153,6 +157,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
 my $have_mail_address = eval { require Mail::Address; 1 };
 my $smtp;
 my $auth;
+my $num_sent = 0;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -216,6 +221,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 ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -247,6 +253,8 @@ my %config_settings = (
 "smtppass" => \$smtp_authpass,
 "smtpdomain" => \$smtp_domain,
 "smtpauth" => \$smtp_auth,
+"smtpbatchsize" => \$batch_size,
+"smtprelogindelay" => \$relogin_delay,
 "to" => \@initial_to,
 "tocmd" => \$to_cmd,
 "cc" => \@initial_cc,
@@ -358,6 +366,8 @@ $rc = GetOptions(
 

[PATCH v4] send-email: --batch-size to work around some SMTP server limit

2017-05-12 Thread xiaoqiang zhao
Some email servers (e.g. smtp.163.com) limit the number emails to be
sent per session(connection) and this will lead to a faliure when
sending many messages.

Teach send-email to disconnect after sending a number of messages
(configurable via the --batch-size= option), wait for a few
seconds (configurable via the --relogin-delay= option) and
reconnect, to work around such a limit.

Also add this two configure option for git config command.

Note:
   Re-authentication will happen every $ messages, so it
will be much more acceptable if you use some form of credential helper
(e.g. the 'sendemail.smtppass' config option), otherwise you will have
to retype password every time when asked.

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
---
 contrib/completion/git-completion.bash |  2 ++
 git-send-email.perl| 18 ++
 2 files changed, 20 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index af658995d..29496353a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2608,6 +2608,8 @@ _git_config ()
sendemail.thread
sendemail.to
sendemail.validate
+   sendemail.smtpbatchsize
+   sendemail.smtprelogindelay
showbranch.default
status.relativePaths
status.showUntrackedFiles
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..071d1ab9d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,10 @@ git send-email --dump-aliases
  This setting forces to use one of the 
listed mechanisms.
 --smtp-debug<0|1>  * Disable, enable Net::SMTP debug.
 
+--batch-size  * send max  message per connection.
+--relogin-delay   * delay  seconds between two 
successive login, default to 1,
+ This option can only be used with 
--batch-size
+
   Automating:
 --identity* Use the sendemail. options.
 --to-cmd  * Email To: via ` \$patch_path`
@@ -153,6 +157,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
 my $have_mail_address = eval { require Mail::Address; 1 };
 my $smtp;
 my $auth;
+my $num_sent = 0;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -216,6 +221,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 ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -247,6 +253,8 @@ my %config_settings = (
 "smtppass" => \$smtp_authpass,
 "smtpdomain" => \$smtp_domain,
 "smtpauth" => \$smtp_auth,
+"smtpbatchsize" => \$batch_size,
+"smtprelogindelay" => \$relogin_delay,
 "to" => \@initial_to,
 "tocmd" => \$to_cmd,
 "cc" => \@initial_cc,
@@ -358,6 +366,8 @@ $rc = GetOptions(
"force" => \$force,
"xmailer!" => \$use_xmailer,
"no-xmailer" => sub {$use_xmailer = 0},
+   "batch-size=i" => \$batch_size,
+   "relogin-delay=i" => \$relogin_delay,
 );
 
 usage() if $help;
@@ -1664,6 +1674,14 @@ foreach my $t (@files) {
}
}
$message_id = undef;
+   $num_sent++;
+   if ($num_sent == $batch_size) {
+   $num_sent = 0;
+   $smtp->quit if defined $smtp;
+   undef $smtp;
+   undef $auth;
+   sleep($relogin_delay);
+   }
 }
 
 # Execute a command (e.g. $to_cmd) to get a list of email addresses
-- 
2.13.0.rc2.49.g12cd49e6e




[PATCH v3] send-email: --batch-size to work around some SMTP server limit

2017-05-07 Thread xiaoqiang zhao
Some email servers (e.g. smtp.163.com) limit the number emails to be
sent per session(connection) and this will lead to a faliure when
sending many messages.

Teach send-email to disconnect after sending a number of messages
(configurable via the --batch-size= option), wait for a few
seconds (configurable via the --relogin-delay= option) and
reconnect, to work around such a limit.

Also add this two configure option for git config command.

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
---
 contrib/completion/git-completion.bash |  2 ++
 git-send-email.perl| 18 ++
 2 files changed, 20 insertions(+)

diff --git a/contrib/completion/git-completion.bash 
b/contrib/completion/git-completion.bash
index af658995d..29496353a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2608,6 +2608,8 @@ _git_config ()
sendemail.thread
sendemail.to
sendemail.validate
+   sendemail.smtpbatchsize
+   sendemail.smtprelogindelay
showbranch.default
status.relativePaths
status.showUntrackedFiles
diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..5cbe97898 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,10 @@ git send-email --dump-aliases
  This setting forces to use one of the 
listed mechanisms.
 --smtp-debug<0|1>  * Disable, enable Net::SMTP debug.
 
+--batch-size  * send max  message per connection.
+--relogin-delay   * delay  seconds between two 
successive login, default to 1,
+ This option can only be used with 
--batch-size
+
   Automating:
 --identity* Use the sendemail. options.
 --to-cmd  * Email To: via ` \$patch_path`
@@ -153,6 +157,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
 my $have_mail_address = eval { require Mail::Address; 1 };
 my $smtp;
 my $auth;
+my $num_sent = 0;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -216,6 +221,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) = (0, 0);
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain, $smtp_auth);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -247,6 +253,8 @@ my %config_settings = (
 "smtppass" => \$smtp_authpass,
 "smtpdomain" => \$smtp_domain,
 "smtpauth" => \$smtp_auth,
+"smtpbatchsize" => \$batch_size,
+"smtprelogindelay" => \$relogin_delay,
 "to" => \@initial_to,
 "tocmd" => \$to_cmd,
 "cc" => \@initial_cc,
@@ -358,6 +366,8 @@ $rc = GetOptions(
"force" => \$force,
"xmailer!" => \$use_xmailer,
"no-xmailer" => sub {$use_xmailer = 0},
+   "batch-size=i" => \$batch_size,
+   "relogin-delay=i" => \$relogin_delay,
 );
 
 usage() if $help;
@@ -1664,6 +1674,14 @@ foreach my $t (@files) {
}
}
$message_id = undef;
+   $num_sent++;
+   if ($num_sent == $batch_size) {
+   $num_sent = 0;
+   $smtp->quit;
+   $smtp = undef;
+   $auth = 0;
+   sleep($relogin_delay);
+   }
 }
 
 # Execute a command (e.g. $to_cmd) to get a list of email addresses
-- 
2.13.0.rc2.1.gd46ef338b.dirty




[PATCH v2] send-email: new options to walkaround email server limits

2017-05-01 Thread xiaoqiang zhao
Some email server(e.g. smtp.163.com) limits a fixed number emails to
be send per session(connection) and this will lead to a send faliure.

With --batch-size= option, an auto reconnection will occur when
number of sent email reaches  and the problem is solved.

--relogin-delay option will make some delay between two successive
email server login.

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
---
 git-send-email.perl | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..cd9981cc6 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,10 @@ git send-email --dump-aliases
  This setting forces to use one of the 
listed mechanisms.
 --smtp-debug<0|1>  * Disable, enable Net::SMTP debug.
 
+--batch-size  * send max \$num message per connection.
+--relogin-delay   * delay \$num seconds between two 
successive login, default to 1,
+ This option can only be used with 
--batch-size
+
   Automating:
 --identity* Use the sendemail. options.
 --to-cmd  * Email To: via ` \$patch_path`
@@ -153,6 +157,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
 my $have_mail_address = eval { require Mail::Address; 1 };
 my $smtp;
 my $auth;
+my $num_sent = 0;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -186,6 +191,8 @@ my $format_patch;
 my $compose_filename;
 my $force = 0;
 my $dump_aliases = 0;
+my $batch_size = 0;
+my $relogin_delay = 1;
 
 # Handle interactive edition of files.
 my $multiedit;
@@ -358,6 +365,8 @@ $rc = GetOptions(
"force" => \$force,
"xmailer!" => \$use_xmailer,
"no-xmailer" => sub {$use_xmailer = 0},
+   "batch-size=i" => \$batch_size,
+   "relogin-delay=i" => \$relogin_delay,
 );
 
 usage() if $help;
@@ -1158,10 +1167,15 @@ sub smtp_host_string {
 # (smtp_user was not specified), and 0 otherwise.
 
 sub smtp_auth_maybe {
-   if (!defined $smtp_authuser || $auth) {
+   if (!defined $smtp_authuser || $num_sent != 0) {
return 1;
}
 
+   if ($auth && $num_sent == 0) {
+   print "Auth use saved password. \n";
+   return !!$smtp->auth($smtp_authuser, $smtp_authpass);
+   }
+
# Workaround AUTH PLAIN/LOGIN interaction defect
# with Authen::SASL::Cyrus
eval {
@@ -1187,6 +1201,7 @@ sub smtp_auth_maybe {
'password' => $smtp_authpass
}, sub {
my $cred = shift;
+   $smtp_authpass = $cred->{'password'};
 
if ($smtp_auth) {
my $sasl = Authen::SASL->new(
@@ -1442,6 +1457,15 @@ EOF
}
}
 
+   $num_sent++;
+   if ($num_sent == $batch_size) {
+   $smtp->quit;
+   $smtp = undef;
+   $num_sent = 0;
+   print "Reconnect SMTP server required. \n";
+   sleep($relogin_delay);
+   }
+
return 1;
 }
 
-- 
2.13.0.rc1.16.g49e904895




[PATCH] send-email: new option to walkaround email server limits

2017-04-29 Thread xiaoqiang zhao
Some email server(e.g. smtp.163.com) limits a fixed number emails to be send per
session(connection) and this will lead to a send faliure.
With --split  option, a auto reconnection will occur when number of sended
email reaches  and the problem is solved.

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
---
 git-send-email.perl | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index eea0a517f..0de9b7058 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -81,6 +81,8 @@ git send-email --dump-aliases
  This setting forces to use one of the 
listed mechanisms.
 --smtp-debug<0|1>  * Disable, enable Net::SMTP debug.
 
+--split   * send \$num message per connection.
+
   Automating:
 --identity* Use the sendemail. options.
 --to-cmd  * Email To: via ` \$patch_path`
@@ -153,6 +155,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
 my $have_mail_address = eval { require Mail::Address; 1 };
 my $smtp;
 my $auth;
+my $send_count = 0;
 
 # Regexes for RFC 2047 productions.
 my $re_token = qr/[^][()<>@,;:\\"\/?.= \000-\037\177-\377]+/;
@@ -186,6 +189,7 @@ my $format_patch;
 my $compose_filename;
 my $force = 0;
 my $dump_aliases = 0;
+my $split = 0;
 
 # Handle interactive edition of files.
 my $multiedit;
@@ -358,6 +362,7 @@ $rc = GetOptions(
"force" => \$force,
"xmailer!" => \$use_xmailer,
"no-xmailer" => sub {$use_xmailer = 0},
+   "split=i" => \$split,
 );
 
 usage() if $help;
@@ -1158,10 +1163,15 @@ sub smtp_host_string {
 # (smtp_user was not specified), and 0 otherwise.
 
 sub smtp_auth_maybe {
-   if (!defined $smtp_authuser || $auth) {
+   if (!defined $smtp_authuser || $send_count != 0) {
return 1;
}
 
+   if ($auth && $send_count == 0) {
+   print "Auth use saved password. \n";
+   return !!$smtp->auth($smtp_authuser, $smtp_authpass);
+   }
+
# Workaround AUTH PLAIN/LOGIN interaction defect
# with Authen::SASL::Cyrus
eval {
@@ -1187,6 +1197,7 @@ sub smtp_auth_maybe {
'password' => $smtp_authpass
}, sub {
my $cred = shift;
+   $smtp_authpass = $cred->{'password'};
 
if ($smtp_auth) {
my $sasl = Authen::SASL->new(
@@ -1442,6 +1453,15 @@ EOF
}
}
 
+   $send_count++;
+   if ($send_count == $split) {
+   $smtp->quit;
+   $smtp = undef;
+   $send_count = 0;
+   print "Reconnect SMTP server required. \n";
+
+   }
+
return 1;
 }
 
-- 
2.11.0