[PATCH v2] git-send-email.perl: Add sub maildomain_sanitize

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH v2] git-send-email.perl: Add sub maildomain_sanitize

From: Jari Aalto <hidden>
Date: 2016-06-15 22:48:39

Move duplicate maildomain checks to a single subroutine.
Require that a FQDN contains at least one period.

Signed-off-by: Jari Aalto <redacted>
---
 git-send-email.perl |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

    Jakub Narebski [off-list ref] 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

Re: [PATCH v2] git-send-email.perl: Add sub maildomain_sanitize

From: Jakub Narebski <hidden>
Date: 2016-06-15 22:48:39

Jari Aalto wrote:
    Jakub Narebski [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help