send-email: Cleanup smtp-domain and add config

The way the code stored --smtp-domain was unlike its handling of other
similar options.  Bring it in line with the others by:

- Renaming $mail_domain to $smtp_domain to match the command line
  option. Also move its declaration from near the top of the file to
  near other option variables.

- Removing $mail_domain_default.  The variable was used once and only
  served to move the default away from where it gets used.

- Adding a sendemail.smtpdomain config option.  smtp-domain was the
  only SMTP configuration option that couldn't be set in the user's
  .gitconfig.

Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brian Gernhardt 2010-04-10 10:53:56 -04:00 committed by Junio C Hamano
parent 79ca070ce5
commit 69cf7bfd13
3 changed files with 12 additions and 11 deletions

View File

@ -1573,6 +1573,7 @@ sendemail.smtppass::
sendemail.suppresscc:: sendemail.suppresscc::
sendemail.suppressfrom:: sendemail.suppressfrom::
sendemail.to:: sendemail.to::
sendemail.smtpdomain::
sendemail.smtpserver:: sendemail.smtpserver::
sendemail.smtpserverport:: sendemail.smtpserverport::
sendemail.smtpuser:: sendemail.smtpuser::

View File

@ -123,7 +123,8 @@ Sending
Specifies the Fully Qualified Domain Name (FQDN) used in the Specifies the Fully Qualified Domain Name (FQDN) used in the
HELO/EHLO command to the SMTP server. Some servers require the HELO/EHLO command to the SMTP server. Some servers require the
FQDN to match your IP address. If not set, git send-email attempts FQDN to match your IP address. If not set, git send-email attempts
to determine your FQDN automatically. to determine your FQDN automatically. Default is the value of
'sendemail.smtpdomain'.
--smtp-pass[=<password>]:: --smtp-pass[=<password>]::
Password for SMTP-AUTH. The argument is optional: If no Password for SMTP-AUTH. The argument is optional: If no

View File

@ -132,8 +132,6 @@ my $have_email_valid = eval { require Email::Valid; 1 };
my $have_mail_address = eval { require Mail::Address; 1 }; my $have_mail_address = eval { require Mail::Address; 1 };
my $smtp; my $smtp;
my $auth; my $auth;
my $mail_domain_default = "localhost.localdomain";
my $mail_domain;
sub unique_email_list(@); sub unique_email_list(@);
sub cleanup_compose_files(); sub cleanup_compose_files();
@ -187,7 +185,7 @@ sub do_edit {
# Variables with corresponding config settings # Variables with corresponding config settings
my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd); 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_authuser, $smtp_encryption);
my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts); my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);
my ($validate, $confirm); my ($validate, $confirm);
my (@suppress_cc); my (@suppress_cc);
@ -209,6 +207,7 @@ my %config_settings = (
"smtpserverport" => \$smtp_server_port, "smtpserverport" => \$smtp_server_port,
"smtpuser" => \$smtp_authuser, "smtpuser" => \$smtp_authuser,
"smtppass" => \$smtp_authpass, "smtppass" => \$smtp_authpass,
"smtpdomain" => \$smtp_domain,
"to" => \@to, "to" => \@to,
"cc" => \@initial_cc, "cc" => \@initial_cc,
"cccmd" => \$cc_cmd, "cccmd" => \$cc_cmd,
@ -277,7 +276,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
"smtp-ssl" => sub { $smtp_encryption = 'ssl' }, "smtp-ssl" => sub { $smtp_encryption = 'ssl' },
"smtp-encryption=s" => \$smtp_encryption, "smtp-encryption=s" => \$smtp_encryption,
"smtp-debug:i" => \$debug_net_smtp, "smtp-debug:i" => \$debug_net_smtp,
"smtp-domain:s" => \$mail_domain, "smtp-domain:s" => \$smtp_domain,
"identity=s" => \$identity, "identity=s" => \$identity,
"annotate" => \$annotate, "annotate" => \$annotate,
"compose" => \$compose, "compose" => \$compose,
@ -889,7 +888,7 @@ sub maildomain_mta {
} }
sub maildomain { sub maildomain {
return maildomain_net() || maildomain_mta() || $mail_domain_default; return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
} }
# Returns 1 if the message was sent, and 0 otherwise. # Returns 1 if the message was sent, and 0 otherwise.
@ -993,18 +992,18 @@ X-Mailer: git-send-email $gitversion
if ($smtp_encryption eq 'ssl') { if ($smtp_encryption eq 'ssl') {
$smtp_server_port ||= 465; # ssmtp $smtp_server_port ||= 465; # ssmtp
require Net::SMTP::SSL; require Net::SMTP::SSL;
$mail_domain ||= maildomain(); $smtp_domain ||= maildomain();
$smtp ||= Net::SMTP::SSL->new($smtp_server, $smtp ||= Net::SMTP::SSL->new($smtp_server,
Hello => $mail_domain, Hello => $smtp_domain,
Port => $smtp_server_port); Port => $smtp_server_port);
} }
else { else {
require Net::SMTP; require Net::SMTP;
$mail_domain ||= maildomain(); $smtp_domain ||= maildomain();
$smtp ||= Net::SMTP->new((defined $smtp_server_port) $smtp ||= Net::SMTP->new((defined $smtp_server_port)
? "$smtp_server:$smtp_server_port" ? "$smtp_server:$smtp_server_port"
: $smtp_server, : $smtp_server,
Hello => $mail_domain, Hello => $smtp_domain,
Debug => $debug_net_smtp); Debug => $debug_net_smtp);
if ($smtp_encryption eq 'tls' && $smtp) { if ($smtp_encryption eq 'tls' && $smtp) {
require Net::SMTP::SSL; require Net::SMTP::SSL;
@ -1027,7 +1026,7 @@ X-Mailer: git-send-email $gitversion
die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ", die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ",
"VALUES: server=$smtp_server ", "VALUES: server=$smtp_server ",
"encryption=$smtp_encryption ", "encryption=$smtp_encryption ",
"maildomain=$mail_domain", "hello=$smtp_domain",
defined $smtp_server_port ? "port=$smtp_server_port" : ""; defined $smtp_server_port ? "port=$smtp_server_port" : "";
} }