Skip to contentSkip to conversation

Add support for SMTP server options

PATCH Superseded Pascal Obry 4 participants 10 messages Jun 15, 2016 Documentation

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for SMTP server options

I'm not familiar at all with Perl so comments on style or usage most welcomed. This patch is to introduce a way to pass specific options to the SMTP server used by git-send-email.

I need that to be able to use different SMTP account (wanadoo, gmail...) on some Git repositories to send over proper identity.

This is v3 of the patch thanks to Junio and AEvar for the review and help.

The two first patches are really code clean-up found while working on this new feature. The last patch is the actual implementation of this new feature.

Pascal Obry (3):
Minor indentation fix.
Remove @smtp_host_parts variable as not used.
New send-email option smtpserveroption.

 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |   12 +++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.2.2.277.gb49c4
#1 lore raw

PATCH v3 1/3 Minor indentation fix.

---
 git-send-email.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-send-email.perl +1 -1
index 6dab3bf..0063606 100755
@@ -212,7 +212,7 @@ my %config_settings = (
     "smtpserverport" => \$smtp_server_port,
     "smtpuser" => \$smtp_authuser,
     "smtppass" => \$smtp_authpass,
-	"smtpdomain" => \$smtp_domain,
+    "smtpdomain" => \$smtp_domain,
     "to" => \@to,
     "cc" => \@initial_cc,
     "cccmd" => \$cc_cmd,
Signature · 1 line
1.7.2.3.316.ga4c47
#2 lore raw

PATCH v3 2/3 Remove @smtp_host_parts variable as not used.

In reply to Pascal Obry
---
 git-send-email.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-send-email.perl +1 -1
index 0063606..39cb5af 100755
@@ -189,7 +189,7 @@ sub do_edit {
 # Variables with corresponding config settings
 my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
 my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
-my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);
+my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
 my ($validate, $confirm);
 my (@suppress_cc);
 my ($auto_8bit_encoding);
Signature · 1 line
1.7.2.3.316.ga4c47
#3 lore raw

PATCH v3 3/3 New send-email option smtpserveroption.

In reply to Pascal Obry

The new command line parameter --smtp-server-option or default configuration sendemail.smtpserveroption can be used to pass specific options to the SMTP server. Update the documentation accordingly.

---
 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
Documentation/git-send-email.txt +8 -0
index c283084..5af05bc 100644
@@ -157,6 +157,14 @@ user is prompted for a password while the input is masked for privacy.
 	`/usr/lib/sendmail` if such program is available, or
 	`localhost` otherwise.
 
+--smtp-server-option=<option>::
+	If set, specifies the outgoing SMTP server option to use.
+	Default value can be specified by the 'sendemail.smtpserveroption'
+	configuration option.
++
+The --smtp-server-option option must be repeated for each option you want
+to pass to the server.
+
 --smtp-server-port=<port>::
 	Specifies a port different from the default port (SMTP
 	servers typically listen to smtp port 25, but may also listen to
git-send-email.perl +7 -1
index 39cb5af..47989fe 100755
@@ -60,6 +60,7 @@ git send-email [options] <file | directory | rev-list options >
     --envelope-sender       <str>  * Email envelope sender.
     --smtp-server       <str:int>  * Outgoing SMTP server to use. The port
                                      is optional. Default 'localhost'.
+    --smtp-server-option    <str>  * Outgoing SMTP server option to use.
     --smtp-server-port      <int>  * Outgoing SMTP server port.
     --smtp-user             <str>  * Username for SMTP-AUTH.
     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.
@@ -188,7 +189,8 @@ sub do_edit {
 
 # Variables with corresponding config settings
 my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
-my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
+my ($smtp_server, $smtp_server_port, @smtp_server_options);
+my ($smtp_authuser, $smtp_encryption);
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -210,6 +212,7 @@ my %config_bool_settings = (
 my %config_settings = (
     "smtpserver" => \$smtp_server,
     "smtpserverport" => \$smtp_server_port,
+    "smtpserveroption" => \@smtp_server_options,
     "smtpuser" => \$smtp_authuser,
     "smtppass" => \$smtp_authpass,
     "smtpdomain" => \$smtp_domain,
@@ -279,6 +282,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
 		    "no-bcc" => \$no_bcc,
 		    "chain-reply-to!" => \$chain_reply_to,
 		    "smtp-server=s" => \$smtp_server,
+		    "smtp-server-option=s" => \@smtp_server_options,
 		    "smtp-server-port=s" => \$smtp_server_port,
 		    "smtp-user=s" => \$smtp_authuser,
 		    "smtp-pass:s" => \$smtp_authpass,
@@ -1015,6 +1019,8 @@ X-Mailer: git-send-email $gitversion
 		}
 	}
 
+	unshift (@sendmail_parameters, @smtp_server_options);
+
 	if ($dry_run) {
 		# We don't want to send the email.
 	} elsif ($smtp_server =~ m#^/#) {
Signature · 1 line
1.7.2.3.316.ga4c47
#4 lore raw

Re: [PATCH v3 3/3] New send-email option smtpserveroption.

Quoted 4 lines · Pascal Obry

The new command line parameter --smtp-server-option or default configuration sendemail.smtpserveroption can be used to pass specific options to the SMTP server. Update the documentation accordingly.

Sign-off? (See Documentation/SubmittingPatches).

Quoted 4 lines
---
 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

Needs update to Documentation/config.txt, adding line about sendemail.smtpserveroption.

Quoted 6 lines
Documentation/git-send-email.txt +0 -0
index c283084..5af05bc 100644

Documentation/git-send-email.txt user is prompted for a password while the input is masked for privacy. · line 166

Quoted 10 lines
Documentation/git-send-email.txt +7 -0
@@ -157,6 +157,14 @@ user is prompted for a password while the input is masked for privacy.
 	`/usr/lib/sendmail` if such program is available, or
 	`localhost` otherwise.
 
+--smtp-server-option=<option>::
+	If set, specifies the outgoing SMTP server option to use.
+	Default value can be specified by the 'sendemail.smtpserveroption'
+	configuration option.
++
+The --smtp-server-option option must be repeated for each option you want
+to pass to the server.

Just a nitpick.

How do multiple options are supported with sendemail.smtpserveroption? This also needs to be described, I think.

Quoted 43 lines
Documentation/git-send-email.txt +1 -0
+
 --smtp-server-port=<port>::
 	Specifies a port different from the default port (SMTP
 	servers typically listen to smtp port 25, but may also listen to
git-send-email.perl +5 -1
index 39cb5af..47989fe 100755
@@ -60,6 +60,7 @@ git send-email [options] <file | directory | rev-list options >
     --envelope-sender       <str>  * Email envelope sender.
     --smtp-server       <str:int>  * Outgoing SMTP server to use. The port
                                      is optional. Default 'localhost'.
+    --smtp-server-option    <str>  * Outgoing SMTP server option to use.
     --smtp-server-port      <int>  * Outgoing SMTP server port.
     --smtp-user             <str>  * Username for SMTP-AUTH.
     --smtp-pass             <str>  * Password for SMTP-AUTH; not necessary.
@@ -188,7 +189,8 @@ sub do_edit {
 
 # Variables with corresponding config settings
 my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
-my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
+my ($smtp_server, $smtp_server_port, @smtp_server_options);
+my ($smtp_authuser, $smtp_encryption);
 my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -210,6 +212,7 @@ my %config_bool_settings = (
 my %config_settings = (
     "smtpserver" => \$smtp_server,
     "smtpserverport" => \$smtp_server_port,
+    "smtpserveroption" => \@smtp_server_options,
     "smtpuser" => \$smtp_authuser,
     "smtppass" => \$smtp_authpass,
     "smtpdomain" => \$smtp_domain,
@@ -279,6 +282,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
 		    "no-bcc" => \$no_bcc,
 		    "chain-reply-to!" => \$chain_reply_to,
 		    "smtp-server=s" => \$smtp_server,
+		    "smtp-server-option=s" => \@smtp_server_options,
 		    "smtp-server-port=s" => \$smtp_server_port,
 		    "smtp-user=s" => \$smtp_authuser,
 		    "smtp-pass:s" => \$smtp_authpass,

git-send-email.perl X-Mailer: git-send-email $gitversion · line 1023

Quoted 5 lines
git-send-email.perl +2 -0
@@ -1015,6 +1019,8 @@ X-Mailer: git-send-email $gitversion
 		}
 	}
 
+	unshift (@sendmail_parameters, @smtp_server_options);
+

I guess that you are following strange style that other 'unshift' invocation uses, but there should be no space between function and opening parentheses beginning its arguments, e.g.

join("\n", @xh)

not

join ("\n", @xh)

Quoted 8 lines
git-send-email.perl +0 -0
 	if ($dry_run) {
 		# We don't want to send the email.
 	} elsif ($smtp_server =~ m#^/#) {
Signature · 1 line
1.7.2.3.316.ga4c47
Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#5 lore raw

Re: [PATCH v3 3/3] New send-email option smtpserveroption.

Quoted 8 lines · Jakub Narebski
Quoted 4 lines · Pascal Obry

The new command line parameter --smtp-server-option or default configuration sendemail.smtpserveroption can be used to pass specific options to the SMTP server. Update the documentation accordingly.

Sign-off? (See Documentation/SubmittingPatches).

Thanks.

Quoted 7 lines
Quoted 4 lines
---
 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

Needs update to Documentation/config.txt, adding line about sendemail.smtpserveroption.

And test if it is easy to arrange (otherwise I'll take a look myself, so do not worry too much about it).

Quoted 18 lines
Quoted 5 lines
Documentation/git-send-email.txt +0 -0
index c283084..5af05bc 100644

Documentation/git-send-email.txt user is prompted for a password while the input is masked for privacy. · line 166

Quoted 10 lines
Documentation/git-send-email.txt +7 -0
@@ -157,6 +157,14 @@ user is prompted for a password while the input is masked for privacy.
 	`/usr/lib/sendmail` if such program is available, or
 	`localhost` otherwise.
 
+--smtp-server-option=<option>::
+	If set, specifies the outgoing SMTP server option to use.
+	Default value can be specified by the 'sendemail.smtpserveroption'
+	configuration option.
++
+The --smtp-server-option option must be repeated for each option you want
+to pass to the server.

Just a nitpick.

Quoted 2 lines

How do multiple options are supported with sendemail.smtpserveroption? This also needs to be described, I think.

That is a good and important point.

We could

[sendemail]
smtpserveroption = opt1
smtpserveroption = opt2

or if we choose to split at WS

[sendemail]
smtpserveroption = "opt1 opt2"

but with the second form there always is this nagging "how would you specify an option with WS in it" issue, so the former might be easier.

If we take the latter route, we should take a single command line option and split it, i.e. --smtp-server-option='opt1 opt2', using the same WS quoting mechanism, for consistency between command line and configuration.

I dunno. Have we solved a similar issue with other parts of the system, and how?

Quoted 11 lines

Documentation/git-send-email.txt X-Mailer: git-send-email $gitversion · line 1023

Quoted 6 lines
Documentation/git-send-email.txt +2 -0
@@ -1015,6 +1019,8 @@ X-Mailer: git-send-email $gitversion
 		}
 	}
 
+	unshift (@sendmail_parameters, @smtp_server_options);
+

I guess that you are following strange style that other 'unshift' invocation uses, but there should be no space between function and opening parentheses beginning its arguments, e.g.

Quoted 5 lines

join("\n", @xh)

not

join ("\n", @xh)

I tend to prefer shift/unshift/push/pop written without these parentheses. Is it just me?

#6 lore raw

Re: [PATCH v3 3/3] New send-email option smtpserveroption.

Quoted 8 lines · Junio C Hamano
Quoted 7 lines · Jakub Narebski
Quoted 4 lines · Pascal Obry
---
 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
Quoted 5 lines
Quoted 2 lines

Needs update to Documentation/config.txt, adding line about sendemail.smtpserveroption.

And test if it is easy to arrange (otherwise I'll take a look myself, so do not worry too much about it).

Actually because *all* options use the same mechanism (%config_settings which is used in read_config, and GetOptions from Getopt::Long), it would be better to just test the mechanism, I think.

But that is outside the scope of this patch... and probably require moving (some of) functionality to Git.pm

Quoted 21 lines
Quoted 18 lines
Quoted 5 lines
Documentation/git-send-email.txt +0 -0
index c283084..5af05bc 100644

Documentation/git-send-email.txt user is prompted for a password while the input is masked for privacy. · line 166

Quoted 10 lines
Documentation/git-send-email.txt +7 -0
@@ -157,6 +157,14 @@ user is prompted for a password while the input is masked for privacy.
 	`/usr/lib/sendmail` if such program is available, or
 	`localhost` otherwise.
 
+--smtp-server-option=<option>::
+	If set, specifies the outgoing SMTP server option to use.
+	Default value can be specified by the 'sendemail.smtpserveroption'
+	configuration option.
++
+The --smtp-server-option option must be repeated for each option you want
+to pass to the server.

Just a nitpick.

Quoted 2 lines

How do multiple options are supported with sendemail.smtpserveroption? This also needs to be described, I think.

Quoted 8 lines

That is a good and important point.

We could

[sendemail]
smtpserveroption = opt1
smtpserveroption = opt2

We do it this way, the same as for 'sendemail.to'... though I admit that it is much more natural for 'sendemail.to' than for 'sendemail.smtpServerOption'.

Quoted 7 lines

or if we choose to split at WS

[sendemail]
smtpserveroption = "opt1 opt2"

but with the second form there always is this nagging "how would you specify an option with WS in it" issue, so the former might be easier.

Yes, there would be a problem with something like this:

[sendemail]
smtpserveroption = "opt1 'opt2_a opt2_b'"

We could use extract_delimited or extract_quotelike, or just a regexp generated using gen_delimited_pat from Text::Balanced. Or better use shellwords from Text::ParseWords

Text::ParseWords is in Perl core since Perl 5... which is I think good enough for Git.

If we go this route we should probably provide shellwords / shellsplit / / split_sq also for C.

Quoted 5 lines

If we take the latter route, we should take a single command line option and split it, i.e. --smtp-server-option='opt1 opt2', using the same WS quoting mechanism, for consistency between command line and configuration.

Right.

Quoted 14 lines

I dunno. Have we solved a similar issue with other parts of the system, and how?

Quoted 11 lines

Documentation/git-send-email.txt X-Mailer: git-send-email $gitversion · line 1023

Quoted 6 lines
Documentation/git-send-email.txt +2 -0
@@ -1015,6 +1019,8 @@ X-Mailer: git-send-email $gitversion
 		}
 	}
 
+	unshift (@sendmail_parameters, @smtp_server_options);
+

I guess that you are following strange style that other 'unshift' invocation uses, but there should be no space between function and opening parentheses beginning its arguments, e.g.

Quoted 8 lines
Quoted 5 lines

join("\n", @xh)

not

join ("\n", @xh)

I tend to prefer shift/unshift/push/pop written without these parentheses. Is it just me?

The Perl-ish way is to avoid parentheses for built-in functions with prototypes, such as shift/unshift/join. But consistency trumps this rule, I think (till the cleanup :-))

Signature · 2 lines
Jakub Narebski
Poland
#7 lore raw

Re: [PATCH v3 3/3] New send-email option smtpserveroption.

Quoted 10 lines · Jakub Narebski

On Mon, 6 Sep 2010, Junio C Hamano wrote:
...

Quoted 2 lines

And test if it is easy to arrange (otherwise I'll take a look myself, so do not worry too much about it).

Actually because *all* options use the same mechanism (%config_settings which is used in read_config, and GetOptions from Getopt::Long), it would be better to just test the mechanism, I think.

But that is outside the scope of this patch...

I didn't mean a test that makes sure --sso=foo is parsed into @sso array; that would be a _mechanism_ test you alluded to, but I think we probably do not need such a test as long as we trust Getopt::Long().

What I meant was to make sure that the result is correctly propagated to the invocation of "exec($smtp_server, @sendmail_params)"; presumably the check will use a custom $smtp_server command that checks individual command line parameters. And that _is_ exactly within the scope of this change.

#8 lore raw

Re: [PATCH v3 3/3] New send-email option smtpserveroption.

In reply to Junio C Hamano
Quoted 61 lines · Junio C Hamano
Quoted 8 lines · Jakub Narebski
Quoted 4 lines · Pascal Obry

The new command line parameter --smtp-server-option or default configuration sendemail.smtpserveroption can be used to pass specific options to the SMTP server. Update the documentation accordingly.

Sign-off?  (See Documentation/SubmittingPatches).

Thanks.

Quoted 7 lines
Quoted 4 lines

---
 Documentation/git-send-email.txt |    8 ++++++++
 git-send-email.perl              |    8 +++++++-

 2 files changed, 15 insertions(+), 1 deletions(-)

Needs update to Documentation/config.txt, adding line about sendemail.smtpserveroption.

And test if it is easy to arrange (otherwise I'll take a look myself, so do not worry too much about it).

Quoted 18 lines
Quoted 13 lines
Documentation/git-send-email.txt +0 -0
index c283084..5af05bc 100644
@@ -157,6 +157,14 @@ user is prompted for a password while the input is masked for privacy.

     /usr/lib/sendmail if such program is available, or localhost otherwise.

+--smtp-server-option=<option>::
+    If set, specifies the outgoing SMTP server option to use.
+    Default value can be specified by the 'sendemail.smtpserveroption'
+    configuration option.
++

Documentation/git-send-email.txt user is prompted for a password while the input is masked for privacy. · line 166

Quoted 2 lines
Documentation/git-send-email.txt +2 -0
+The --smtp-server-option option must be repeated for each option you want
+to pass to the server.

Just a nitpick.

Quoted 2 lines

How do multiple options are supported with sendemail.smtpserveroption? This also needs to be described, I think.

That is a good and important point.

We could

       [sendemail]
               smtpserveroption = opt1
               smtpserveroption = opt2

or if we choose to split at WS

       [sendemail]
               smtpserveroption = "opt1 opt2"

but with the second form there always is this nagging "how would you specify an option with WS in it" issue, so the former might be easier.

Quoted 6 lines

If we take the latter route, we should take a single command line option and split it, i.e. --smtp-server-option='opt1 opt2', using the same WS quoting mechanism, for consistency between command line and configuration.

I dunno.  Have we solved a similar issue with other parts of the system, and how?

I can tell you that I *didn't* solve a similar problem with t/harness:

         ? (test_args    => [ split /\s+/, $ENV{GIT_TEST_OPTS} ])

That'll fail if the GIT_TEST_OPTS contains a space,
e.g. GIT_TEST_OPTS='--root="/tmp/a space"'. But I just ignored it at the time.

It would be useful for both of these if we had a str_to_options() utility function in e.g. Git.pm. If nothing else it's probably more user friendly to specify them in one smtpserveroption string, since you can copy/paste an existing invocation then.

Maybe we can convince a POSIX shell (which we require anyway) to split these up for us? Shelling out from Perl to split these up would be a good solution if it can be done.

Quoted 11 lines
Quoted 11 lines

Documentation/git-send-email.txt X-Mailer: git-send-email $gitversion · line 1023

Quoted 6 lines
Documentation/git-send-email.txt +2 -0
@@ -1015,6 +1019,8 @@ X-Mailer: git-send-email $gitversion
              }
      }
 
+    unshift (@sendmail_parameters, @smtp_server_options);
+

I guess that you are following strange style that other 'unshift' invocation uses, but there should be no space between function and opening parentheses beginning its arguments, e.g.

Quoted 8 lines
Quoted 5 lines

  join("\n", @xh)

not

  join ("\n", @xh)

I tend to prefer shift/unshift/push/pop written without these parentheses.  Is it just me?

It's not just you. The customary style in Perl is to avoid parentheses.

#9 lore raw
In reply to Pascal Obry
Quoted 4 lines · Pascal Obry

I'm not familiar at all with Perl so comments on style or usage most welcomed. This patch is to introduce a way to pass specific options to the SMTP server used by git-send-email.

Quoted 8 lines

I need that to be able to use different SMTP account (wanadoo, gmail...) on some Git repositories to send over proper identity.

This is v3 of the patch thanks to Junio and AEvar for the review and help.

The two first patches are really code clean-up found while working on this new feature. The last patch is the actual implementation of this new feature.

I looked these over and they look good, thanks.