Merge branch 'bg/send-email-smtpdomain' into maint

* bg/send-email-smtpdomain:
  send-email: Cleanup smtp-domain and add config
  Document send-email --smtp-domain
  send-email: Don't use FQDNs without a '.'
  send-email: Cleanup { style
This commit is contained in:
Junio C Hamano
2010-06-16 16:20:06 -07:00
3 changed files with 30 additions and 26 deletions

View File

@ -1642,6 +1642,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

@ -119,6 +119,13 @@ Sending
value reverts to plain SMTP. Default is the value of value reverts to plain SMTP. Default is the value of
'sendemail.smtpencryption'. 'sendemail.smtpencryption'.
--smtp-domain=<FQDN>::
Specifies the Fully Qualified Domain Name (FQDN) used in 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
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
argument is specified, then the empty string is used as argument is specified, then the empty string is used as

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();
@ -190,7 +188,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);
@ -212,6 +210,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,
@ -283,7 +282,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,
@ -761,8 +760,7 @@ sub extract_valid_address {
# We'll setup a template for the message id, using the "from" address: # We'll setup a template for the message id, using the "from" address:
my ($message_id_stamp, $message_id_serial); my ($message_id_stamp, $message_id_serial);
sub make_message_id sub make_message_id {
{
my $uniq; my $uniq;
if (!defined $message_id_stamp) { if (!defined $message_id_stamp) {
$message_id_stamp = sprintf("%s-%s", time, $$); $message_id_stamp = sprintf("%s-%s", time, $$);
@ -817,8 +815,7 @@ sub is_rfc2047_quoted {
} }
# use the simplest quoting being able to handle the recipient # use the simplest quoting being able to handle the recipient
sub sanitize_address sub sanitize_address {
{
my ($recipient) = @_; my ($recipient) = @_;
my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/); my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
@ -863,21 +860,23 @@ sub sanitize_address
# This maildomain*() code is based on ideas in Perl library Test::Reporter # This maildomain*() code is based on ideas in Perl library Test::Reporter
# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain () # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
sub maildomain_net sub valid_fqdn {
{ my $domain = shift;
return !($^O eq 'darwin' && $domain =~ /\.local$/) && $domain =~ /\./;
}
sub maildomain_net {
my $maildomain; my $maildomain;
if (eval { require Net::Domain; 1 }) { if (eval { require Net::Domain; 1 }) {
my $domain = Net::Domain::domainname(); my $domain = Net::Domain::domainname();
$maildomain = $domain $maildomain = $domain if valid_fqdn($domain);
unless $^O eq 'darwin' && $domain =~ /\.local$/;
} }
return $maildomain; return $maildomain;
} }
sub maildomain_mta sub maildomain_mta {
{
my $maildomain; my $maildomain;
if (eval { require Net::SMTP; 1 }) { if (eval { require Net::SMTP; 1 }) {
@ -887,8 +886,7 @@ sub maildomain_mta
my $domain = $smtp->domain; my $domain = $smtp->domain;
$smtp->quit; $smtp->quit;
$maildomain = $domain $maildomain = $domain if valid_fqdn($domain);
unless $^O eq 'darwin' && $domain =~ /\.local$/;
last if $maildomain; last if $maildomain;
} }
@ -898,17 +896,15 @@ sub maildomain_mta
return $maildomain; return $maildomain;
} }
sub maildomain sub maildomain {
{ return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
return maildomain_net() || maildomain_mta() || $mail_domain_default;
} }
# Returns 1 if the message was sent, and 0 otherwise. # Returns 1 if the message was sent, and 0 otherwise.
# In actuality, the whole program dies when there # In actuality, the whole program dies when there
# is an error sending a message. # is an error sending a message.
sub send_message sub send_message {
{
my @recipients = unique_email_list(@to); my @recipients = unique_email_list(@to);
@cc = (grep { my $cc = extract_valid_address($_); @cc = (grep { my $cc = extract_valid_address($_);
not grep { $cc eq $_ } @recipients not grep { $cc eq $_ } @recipients
@ -1005,18 +1001,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;
@ -1039,7 +1035,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" : "";
} }