git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jari Aalto <jari.aalto@cante.net>
Date
Apr 16, 2010, 15:49 UTC
Message-ID
<87wrw7qtx8.fsf_-_@jondo.cante.net>
In-Reply-To
<m38w8og9w4.fsf@localhost.localdomain>

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
Previous: Jakub NarebskiNext: Jakub Narebski
Message 7 of 12 in “send-email: --smtp-domain improvements”
  1. 0/3 send-email: --smtp-domain improvementsBrian Gernhardt, Apr 9, 2010
  2. 1/3 send-email: Don't use FQDNs without a '.'Brian Gernhardt, Apr 9, 2010
  3. Junio C HamanoApr 9, 2010
  4. git-send-email.perl: Add sub maildomain_sanitizeJari Aalto, Apr 13, 2010
  5. git-send-email.perl: add maildomain_sanitize()Jari Aalto, Apr 13, 2010
  6. Jakub NarebskiApr 15, 2010
  7. git-send-email.perl: Add sub maildomain_sanitizeJari Aalto, Apr 16, 2010
  8. Jakub NarebskiApr 16, 2010
  9. Jari AaltoApr 16, 2010
  10. 2/3 Document send-email --smtp-domainBrian Gernhardt, Apr 9, 2010
  11. 3/3 send-email: Add sendemail.smtpdomainBrian Gernhardt, Apr 9, 2010
  12. Jakub NarebskiApr 9, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.