* [PATCH 0/3] send-email: --smtp-domain improvements
@ 2010-04-09 5:11 Brian Gernhardt
2010-04-09 5:11 ` [PATCH 1/3] send-email: Don't use FQDNs without a '.' Brian Gernhardt
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Brian Gernhardt @ 2010-04-09 5:11 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
The first patch keeps send-email from using a bogus FQDN for my laptop.
Oddly enough, my MTA doesn't mind "localhost.localdomain" but complains
about "My-Computer".
The second adds documentation for --smtp-domain to the git-send-email man
page. The only documentation for it was in the code and the usage message.
The last is just an enhancement, but I was honestly surprised that
--smtp-domain didn't have a configuration.
Brian Gernhardt (3):
send-email: Don't use FQDNs without a '.'
Document send-email --smtp-domain
send-email: Add sendemail.smtpdomain
Documentation/git-send-email.txt | 7 +++++++
git-send-email.perl | 26 ++++++++++++++------------
2 files changed, 21 insertions(+), 12 deletions(-)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3] send-email: Don't use FQDNs without a '.'
2010-04-09 5:11 [PATCH 0/3] send-email: --smtp-domain improvements Brian Gernhardt
@ 2010-04-09 5:11 ` Brian Gernhardt
2010-04-09 5:36 ` Junio C Hamano
2010-04-09 5:11 ` [PATCH 2/3] Document send-email --smtp-domain Brian Gernhardt
2010-04-09 5:11 ` [PATCH 3/3] send-email: Add sendemail.smtpdomain Brian Gernhardt
2 siblings, 1 reply; 12+ messages in thread
From: Brian Gernhardt @ 2010-04-09 5:11 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Although Net::Domain::domainname attempts to be very thorough, the
host's configuration can still refuse to give a FQDN. Check to see if
what we receive contains a dot as a basic sanity check.
Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
My OS X machine doesn't add ".local" to it's hostname for some reason.
Since a FQDN requires at least one . between the TLD and hostname,
we can check for it to avoid nonsense results like "My-Computer".
git-send-email.perl | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index ce569a9..85fe374 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -870,7 +870,8 @@ sub maildomain_net
if (eval { require Net::Domain; 1 }) {
my $domain = Net::Domain::domainname();
$maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ unless $^O eq 'darwin' && $domain =~ /\.local$/
+ or $domain !~ /\./;
}
return $maildomain;
@@ -888,7 +889,8 @@ sub maildomain_mta
$smtp->quit;
$maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ unless $^O eq 'darwin' && $domain =~ /\.local$/
+ or $domain !~ /\./;
last if $maildomain;
}
--
1.7.1.rc0.210.ge6da
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/3] Document send-email --smtp-domain
2010-04-09 5:11 [PATCH 0/3] send-email: --smtp-domain improvements Brian Gernhardt
2010-04-09 5:11 ` [PATCH 1/3] send-email: Don't use FQDNs without a '.' Brian Gernhardt
@ 2010-04-09 5:11 ` Brian Gernhardt
2010-04-09 5:11 ` [PATCH 3/3] send-email: Add sendemail.smtpdomain Brian Gernhardt
2 siblings, 0 replies; 12+ messages in thread
From: Brian Gernhardt @ 2010-04-09 5:11 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
--smtp-debug is still undocumented. It also appears to be a boolean that
takes 0 or 1 instead of being of the form --[no-]smtp-debug.
Documentation/git-send-email.txt | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index ced35b2..f171471 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -119,6 +119,12 @@ Sending
value reverts to plain SMTP. Default is the value of
'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.
+
--smtp-pass[=<password>]::
Password for SMTP-AUTH. The argument is optional: If no
argument is specified, then the empty string is used as
--
1.7.1.rc0.210.ge6da
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/3] send-email: Add sendemail.smtpdomain
2010-04-09 5:11 [PATCH 0/3] send-email: --smtp-domain improvements Brian Gernhardt
2010-04-09 5:11 ` [PATCH 1/3] send-email: Don't use FQDNs without a '.' Brian Gernhardt
2010-04-09 5:11 ` [PATCH 2/3] Document send-email --smtp-domain Brian Gernhardt
@ 2010-04-09 5:11 ` Brian Gernhardt
2010-04-09 6:56 ` Jakub Narebski
2 siblings, 1 reply; 12+ messages in thread
From: Brian Gernhardt @ 2010-04-09 5:11 UTC (permalink / raw)
To: Git List; +Cc: Junio C Hamano
--smtp-domain is an option that if you need once, you probably will
need again. To help with that, allow the user to set it in their
.gitconfig
Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
Seemed like a natural thing to add. Was surprised it wasn't there when I went
poking around.
Documentation/git-send-email.txt | 3 ++-
git-send-email.perl | 20 ++++++++++----------
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index f171471..288a4ec 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -123,7 +123,8 @@ Sending
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.
+ to determine your FQDN automatically. Default is the value of
+ 'sendemail.smtpdomain'.
--smtp-pass[=<password>]::
Password for SMTP-AUTH. The argument is optional: If no
diff --git a/git-send-email.perl b/git-send-email.perl
index 85fe374..14b996e 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -132,8 +132,7 @@ my $have_email_valid = eval { require Email::Valid; 1 };
my $have_mail_address = eval { require Mail::Address; 1 };
my $smtp;
my $auth;
-my $mail_domain_default = "localhost.localdomain";
-my $mail_domain;
+my $smtp_domain_default = "localhost.localdomain";
sub unique_email_list(@);
sub cleanup_compose_files();
@@ -190,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);
+my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);
my ($validate, $confirm);
my (@suppress_cc);
@@ -212,6 +211,7 @@ my %config_settings = (
"smtpserverport" => \$smtp_server_port,
"smtpuser" => \$smtp_authuser,
"smtppass" => \$smtp_authpass,
+ "smtpdomain" => \$smtp_domain,
"to" => \@to,
"cc" => \@initial_cc,
"cccmd" => \$cc_cmd,
@@ -283,7 +283,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
"smtp-ssl" => sub { $smtp_encryption = 'ssl' },
"smtp-encryption=s" => \$smtp_encryption,
"smtp-debug:i" => \$debug_net_smtp,
- "smtp-domain:s" => \$mail_domain,
+ "smtp-domain:s" => \$smtp_domain,
"identity=s" => \$identity,
"annotate" => \$annotate,
"compose" => \$compose,
@@ -902,7 +902,7 @@ sub maildomain_mta
sub maildomain
{
- return maildomain_net() || maildomain_mta() || $mail_domain_default;
+ return maildomain_net() || maildomain_mta() || $smtp_domain_default;
}
# Returns 1 if the message was sent, and 0 otherwise.
@@ -1007,18 +1007,18 @@ X-Mailer: git-send-email $gitversion
if ($smtp_encryption eq 'ssl') {
$smtp_server_port ||= 465; # ssmtp
require Net::SMTP::SSL;
- $mail_domain ||= maildomain();
+ $smtp_domain ||= maildomain();
$smtp ||= Net::SMTP::SSL->new($smtp_server,
- Hello => $mail_domain,
+ Hello => $smtp_domain,
Port => $smtp_server_port);
}
else {
require Net::SMTP;
- $mail_domain ||= maildomain();
+ $smtp_domain ||= maildomain();
$smtp ||= Net::SMTP->new((defined $smtp_server_port)
? "$smtp_server:$smtp_server_port"
: $smtp_server,
- Hello => $mail_domain,
+ Hello => $smtp_domain,
Debug => $debug_net_smtp);
if ($smtp_encryption eq 'tls' && $smtp) {
require Net::SMTP::SSL;
@@ -1041,7 +1041,7 @@ X-Mailer: git-send-email $gitversion
die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ",
"VALUES: server=$smtp_server ",
"encryption=$smtp_encryption ",
- "maildomain=$mail_domain",
+ "maildomain=$smtp_domain",
defined $smtp_server_port ? "port=$smtp_server_port" : "";
}
--
1.7.1.rc0.210.ge6da
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] send-email: Don't use FQDNs without a '.'
2010-04-09 5:11 ` [PATCH 1/3] send-email: Don't use FQDNs without a '.' Brian Gernhardt
@ 2010-04-09 5:36 ` Junio C Hamano
2010-04-13 8:43 ` [PATCH] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2010-04-09 5:36 UTC (permalink / raw)
To: Brian Gernhardt; +Cc: Jari Aalto, Git List
Brian Gernhardt <brian@gernhardtsoftware.com> writes:
> $maildomain = $domain
> - unless $^O eq 'darwin' && $domain =~ /\.local$/;
> + unless $^O eq 'darwin' && $domain =~ /\.local$/
> + or $domain !~ /\./;
It would become *much* easier to read if we stop using the statement
modifier, and write it in a more straightforward way:
unless (($^O eq 'darwin' && $domain =~ /\.local$/)
|| $domain !~ /\./) {
$maildomain = $domain;
}
as the condition seems to have grown large enough to exceed "by the way
don't do this under this narrow condition", which is what statement
modifiers are designed to be used. Also mixing && and or that have
different precedence taxes readers' brainpower unnecessarily.
I also think that this particular exception logic should probably be in a
separate helper function that is called from the two places.
Jari, you are the last person who touched code around this area. What do
you think?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] send-email: Add sendemail.smtpdomain
2010-04-09 5:11 ` [PATCH 3/3] send-email: Add sendemail.smtpdomain Brian Gernhardt
@ 2010-04-09 6:56 ` Jakub Narebski
0 siblings, 0 replies; 12+ messages in thread
From: Jakub Narebski @ 2010-04-09 6:56 UTC (permalink / raw)
To: Brian Gernhardt; +Cc: Git List, Junio C Hamano
Brian Gernhardt <brian@gernhardtsoftware.com> writes:
> --smtp-domain is an option that if you need once, you probably will
> need again. To help with that, allow the user to set it in their
> .gitconfig
via 'sendemail.smtpdomain' ?
>
> Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
> ---
>
> Seemed like a natural thing to add. Was surprised it wasn't there when I went
> poking around.
>
> Documentation/git-send-email.txt | 3 ++-
> git-send-email.perl | 20 ++++++++++----------
> 2 files changed, 12 insertions(+), 11 deletions(-)
You should also add one-liner to Documentation/config.txt, mentioning
'sendemail.smtpdomain' configuration variable (the part referring reader
to git-send-email(1) documentation).
P.S. Some of git-send-email configuration variables: sendemail.identity,
sendemail.smtpencryption, sendemail.smtpssl (deprecated), and the concept
of sendemail.<identity>.* are described in Documentation/config.txt,
which means that they are present in git-config(1) manpage. Some of them
are described in "Configuration" section of Documentation/git-send-email.txt
(which means git-send-email(1) manpage): sendemail.aliasesfile,
sendemail.aliasfiletype, sendemail.multiedit, sendemail.confirm; I think
those are config variables which do not have corresponding command line
option. The rest: sendemail.bcc, sendemail.cc, sendemail.from,
sendemail.to, sendemail.envelopesender, sendemail.smtpencryption (which
is described in git-config(1)), sendemail.smtppass, sendemail.smtpserver,
sendemail.smtpserverport, sendemail.smtpuser, sendemail.cccmd,
sendemail.chainreplyto, sendemail.identity and 'sendemail.<identity>'
subsection (described in git-config(1)), sendemail.signedoffbycc,
sendemail.suppresscc, sendemail.suppressfrom, sendemail.thread, and
sendemail.validate are described only with corresponding command-line
option.
Huh...
--
Jakub Narebski
Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH] git-send-email.perl: Add sub maildomain_sanitize
2010-04-09 5:36 ` Junio C Hamano
@ 2010-04-13 8:43 ` Jari Aalto
2010-04-13 11:35 ` [PATCH] git-send-email.perl: add maildomain_sanitize() Jari Aalto
0 siblings, 1 reply; 12+ messages in thread
From: Jari Aalto @ 2010-04-13 8:43 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Brian Gernhardt, Git List
Move duplicate maildomain checks to a single subroutine.
Require that a FQDN contains at least one period.
Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
git-send-email.perl | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
Here is improved version.
-- Jari
>Re: [PATCH 1/3] send-email: Don't use FQDNs without a '.'
>Junio C Hamano <gitster@pobox.com> writes:
>> Brian Gernhardt <brian@gernhardtsoftware.com> writes:
>
>> $maildomain = $domain
>> - unless $^O eq 'darwin' && $domain =~ /\.local$/;
>> + unless $^O eq 'darwin' && $domain =~ /\.local$/
>> + or $domain !~ /\./;
>
> [Junio] It would become *much* easier to read if we stop using the statement
> modifier, and write it in a more straightforward way:
>
> unless (($^O eq 'darwin' && $domain =~ /\.local$/)
> || $domain !~ /\./) {
> $maildomain = $domain;
> }
>
> as the condition seems to have grown large enough to exceed "by the way
> don't do this under this narrow condition", which is what statement
> modifiers are designed to be used. Also mixing && and or that have
> different precedence taxes readers' brainpower unnecessarily.
>
> I also think that this particular exception logic should probably be in a
> separate helper function that is called from the two places.
>
> Jari, you are the last person who touched code around this area. What do
> you think?
diff --git a/git-send-email.perl b/git-send-email.perl
index ce569a9..7a1c00f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -863,14 +863,28 @@ sub sanitize_address
# This maildomain*() code is based on ideas in Perl library Test::Reporter
# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
+sub maildomain_sanitize
+{
+ local $_ = shift;
+
+ # On Mac, the the domain name is not necessarily in FQDN format
+ # Require a period in the string
+
+ if ( $^O eq 'darwin' and /\.local$/ ) {
+ # Nope, pass this one.
+ }
+ elsif ( /\./ ) {
+ $_;
+ }
+}
+
sub maildomain_net
{
my $maildomain;
if (eval { require Net::Domain; 1 }) {
my $domain = Net::Domain::domainname();
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
}
return $maildomain;
@@ -887,8 +901,7 @@ sub maildomain_mta
my $domain = $smtp->domain;
$smtp->quit;
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
last if $maildomain;
}
--
1.7.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH] git-send-email.perl: add maildomain_sanitize()
2010-04-13 8:43 ` [PATCH] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
@ 2010-04-13 11:35 ` Jari Aalto
2010-04-15 12:47 ` Jakub Narebski
0 siblings, 1 reply; 12+ messages in thread
From: Jari Aalto @ 2010-04-13 11:35 UTC (permalink / raw)
To: git
Move duplicate maildomain checks to a single subroutine.
Require that a FQDN contains at least one period.
Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
git-send-email.perl | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
Here is improved version 2 (use "tab" for indentation).
-- Jari
>Re: [PATCH 1/3] send-email: Don't use FQDNs without a '.'
>Junio C Hamano <gitster@pobox.com> writes:
>> Brian Gernhardt <brian@gernhardtsoftware.com> writes:
>
>> $maildomain = $domain
>> - unless $^O eq 'darwin' && $domain =~ /\.local$/;
>> + unless $^O eq 'darwin' && $domain =~ /\.local$/
>> + or $domain !~ /\./;
>
> [Junio] It would become *much* easier to read if we stop using the statement
> modifier, and write it in a more straightforward way:
>
> unless (($^O eq 'darwin' && $domain =~ /\.local$/)
> || $domain !~ /\./) {
> $maildomain = $domain;
> }
>
> as the condition seems to have grown large enough to exceed "by the way
> don't do this under this narrow condition", which is what statement
> modifiers are designed to be used. Also mixing && and or that have
> different precedence taxes readers' brainpower unnecessarily.
>
> I also think that this particular exception logic should probably be in a
> separate helper function that is called from the two places.
>
> Jari, you are the last person who touched code around this area. What do
> you think?
diff --git a/git-send-email.perl b/git-send-email.perl
index ce569a9..0e8f18c 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -863,14 +863,28 @@ sub sanitize_address
# This maildomain*() code is based on ideas in Perl library Test::Reporter
# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
+sub maildomain_sanitize
+{
+ local $_ = shift;
+
+ # On Mac, the the domain name is not necessarily in FQDN format
+ # Require a period in the string
+
+ if ( $^O eq 'darwin' and /\.local$/ ) {
+ # Nope, pass this one.
+ }
+ elsif ( /\./ ) {
+ $_;
+ }
+}
+
sub maildomain_net
{
my $maildomain;
if (eval { require Net::Domain; 1 }) {
my $domain = Net::Domain::domainname();
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
}
return $maildomain;
@@ -887,8 +901,7 @@ sub maildomain_mta
my $domain = $smtp->domain;
$smtp->quit;
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
last if $maildomain;
}
--
1.7.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] git-send-email.perl: add maildomain_sanitize()
2010-04-13 11:35 ` [PATCH] git-send-email.perl: add maildomain_sanitize() Jari Aalto
@ 2010-04-15 12:47 ` Jakub Narebski
2010-04-16 15:49 ` [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
0 siblings, 1 reply; 12+ messages in thread
From: Jakub Narebski @ 2010-04-15 12:47 UTC (permalink / raw)
To: Jari Aalto; +Cc: git
Jari Aalto <jari.aalto@cante.net> writes:
> Move duplicate maildomain checks to a single subroutine.
> Require that a FQDN contains at least one period.
>
> Signed-off-by: Jari Aalto <jari.aalto@cante.net>
> ---
Good idea.
[...]
> diff --git a/git-send-email.perl b/git-send-email.perl
> index ce569a9..0e8f18c 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -863,14 +863,28 @@ sub sanitize_address
> # This maildomain*() code is based on ideas in Perl library Test::Reporter
> # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
>
> +sub maildomain_sanitize
> +{
> + local $_ = shift;
> +
> + # On Mac, the the domain name is not necessarily in FQDN format
> + # Require a period in the string
> +
> + if ( $^O eq 'darwin' and /\.local$/ ) {
> + # Nope, pass this one.
> + }
> + elsif ( /\./ ) {
> + $_;
> + }
> +}
Style:
+sub maildomain_sanitize {
+ local $domain = shift;
+
+ # On Mac, the the domain name is not necessarily in FQDN format
+ # Require a period in the string
+
+ if ($^O eq 'darwin' && $domain =~ /\.local$/) {
+ # Nope, pass this one.
+ } elsif ($domain =~ /\./) {
+ return $domain;
+ }
+}
(probably fixed in new version of this series).
--
Jakub Narebski
Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize
2010-04-15 12:47 ` Jakub Narebski
@ 2010-04-16 15:49 ` Jari Aalto
2010-04-16 16:11 ` Jakub Narebski
0 siblings, 1 reply; 12+ messages in thread
From: Jari Aalto @ 2010-04-16 15:49 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Move duplicate maildomain checks to a single subroutine.
Require that a FQDN contains at least one period.
Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
git-send-email.perl | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
Jakub Narebski <jnareb@gmail.com> writes:
> +sub maildomain_sanitize {
> + local $domain = shift;
> +
> + # On Mac, the the domain name is not necessarily in FQDN format
> + # Require a period in the string
> +
> + if ($^O eq 'darwin' && $domain =~ /\.local$/) {
> + # Nope, pass this one.
> + } elsif ($domain =~ /\./) {
> + return $domain;
> + }
> +}
Thanks for 2nd eye. Changed these in above:
* Starting brace placement at function start
* Placement of else
* Maybe: use or "return" (debatable).
But not these. Motivation:
* The "$_" simplifies ussage everywhere in the function. XP: less is more.
* The "and" is more readable than "&&". The "and" is also safer
due to its lower precedence.
Jari
diff --git a/git-send-email.perl b/git-send-email.perl
index ce569a9..d52a8c3 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -863,14 +863,26 @@ sub sanitize_address
# This maildomain*() code is based on ideas in Perl library Test::Reporter
# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
+sub maildomain_sanitize {
+ local $_ = shift;
+
+ # On Mac, the the domain name is not necessarily in FQDN format.
+ # Require a period in the string.
+
+ if ( $^O eq 'darwin' and /\.local$/ ) {
+ # Nope, pass this one.
+ } elsif ( /\./ ) {
+ return $_;
+ }
+}
+
sub maildomain_net
{
my $maildomain;
if (eval { require Net::Domain; 1 }) {
my $domain = Net::Domain::domainname();
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
}
return $maildomain;
@@ -887,8 +899,7 @@ sub maildomain_mta
my $domain = $smtp->domain;
$smtp->quit;
- $maildomain = $domain
- unless $^O eq 'darwin' && $domain =~ /\.local$/;
+ $maildomain = maildomain_sanitize($domain);
last if $maildomain;
}
--
1.7.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize
2010-04-16 15:49 ` [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
@ 2010-04-16 16:11 ` Jakub Narebski
2010-04-16 17:00 ` Start encouraging English.pm (Was: [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize) Jari Aalto
0 siblings, 1 reply; 12+ messages in thread
From: Jakub Narebski @ 2010-04-16 16:11 UTC (permalink / raw)
To: Jari Aalto; +Cc: git
Jari Aalto wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
> > +sub maildomain_sanitize {
> > + local $domain = shift;
> > +
> > + # On Mac, the the domain name is not necessarily in FQDN format
> > + # Require a period in the string
> > +
> > + if ($^O eq 'darwin' && $domain =~ /\.local$/) {
> > + # Nope, pass this one.
> > + } elsif ($domain =~ /\./) {
> > + return $domain;
> > + }
> > +}
>
> Thanks for 2nd eye. Changed these in above:
>
> * Starting brace placement at function start
> * Placement of else
> * Maybe: use or "return" (debatable).
>
> But not these. Motivation:
>
> * The "$_" simplifies usage everywhere in the function. XP: less is more.
> * The "and" is more readable than "&&". The "and" is also safer
> due to its lower precedence.
O.K.
Note however that while setting $_ ($ARG with English) simplifies regexp
matching, you have to take care to use
local $_ = shift;
and not
my $_ = shift;
And to use 'local'.
A bit of "difficulty conservation" at work.
[...]
> +sub maildomain_sanitize {
> + local $_ = shift;
> +
> + # On Mac, the the domain name is not necessarily in FQDN format.
> + # Require a period in the string.
> +
> + if ( $^O eq 'darwin' and /\.local$/ ) {
> + # Nope, pass this one.
> + } elsif ( /\./ ) {
> + return $_;
> + }
> +}
--
Jakub Narebski
Poland
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Start encouraging English.pm (Was: [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize)
2010-04-16 16:11 ` Jakub Narebski
@ 2010-04-16 17:00 ` Jari Aalto
0 siblings, 0 replies; 12+ messages in thread
From: Jari Aalto @ 2010-04-16 17:00 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Jakub Narebski <jnareb@gmail.com> writes:
> O.K.
>
>
> Note however that while setting $_ ($ARG with English) simplifies regexp
> matching
Speaking of which...
Could we please move to using this everywhere:
use English qw( -no_match_vars );
That would give all the benefits of readability without performance
penalties. The load time seems to be neglible:
$ perl --version | grep v5
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
$ time perl -e 'print'
real 0m0.005s
user 0m0.000s
sys 0m0.004s
$ time perl -e 'use English qw( -no_match_vars ); print'
real 0m0.017s
user 0m0.008s
sys 0m0.008s
> you have to take care to use
>
>> +sub maildomain_sanitize {
>> + local $_ = shift;
> local $_ = shift;
>
> and not
>
> my $_ = shift;
>
> And to use 'local'.
As done.
The Perl 5.12 now finally allow my'ing of $ARG too. But maybe we don't
switch to it just yet...
Jari
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-04-16 17:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-09 5:11 [PATCH 0/3] send-email: --smtp-domain improvements Brian Gernhardt
2010-04-09 5:11 ` [PATCH 1/3] send-email: Don't use FQDNs without a '.' Brian Gernhardt
2010-04-09 5:36 ` Junio C Hamano
2010-04-13 8:43 ` [PATCH] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
2010-04-13 11:35 ` [PATCH] git-send-email.perl: add maildomain_sanitize() Jari Aalto
2010-04-15 12:47 ` Jakub Narebski
2010-04-16 15:49 ` [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize Jari Aalto
2010-04-16 16:11 ` Jakub Narebski
2010-04-16 17:00 ` Start encouraging English.pm (Was: [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize) Jari Aalto
2010-04-09 5:11 ` [PATCH 2/3] Document send-email --smtp-domain Brian Gernhardt
2010-04-09 5:11 ` [PATCH 3/3] send-email: Add sendemail.smtpdomain Brian Gernhardt
2010-04-09 6:56 ` Jakub Narebski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).