* [PATCH] cygport announce SMTP HELO fails without smtp server FQDN
@ 2020-07-13 13:10 Brian Inglis
0 siblings, 0 replies; only message in thread
From: Brian Inglis @ 2020-07-13 13:10 UTC (permalink / raw)
To: cygwin-apps
pkg_upload.cygpart(__pkg_announce): added perl code to embedded perl
script for email domain FQDN copied from git send-email with minor hooks
---
lib/pkg_upload.cygpart | 51 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/lib/pkg_upload.cygpart b/lib/pkg_upload.cygpart
index f88525d..06024b4 100644
--- a/lib/pkg_upload.cygpart
+++ b/lib/pkg_upload.cygpart
@@ -168,6 +168,7 @@ EOF
echo "Upload complete."
}
+
__pkg_announce() {
local msg=$(mktemp -t cygwin-announce-${PF}.XXXXXX)
local msgat=$(date +@%s)
@@ -198,7 +199,52 @@ _EOF
${EDITOR:-vi} $msg || error "Editor exited abormally, aborting annoucement"
+# FQDN from git send-email
+# Returns the local Fully Qualified Domain Name (FQDN) if available.
+#
+# Tightly configured MTAa require that a caller sends a real DNS
+# domain name that corresponds the IP address in the HELO/EHLO
+# handshake. This is used to verify the connection and prevent
+# spammers from trying to hide their identity. If the DNS and IP don't
+# match, the receiving MTA may deny the connection.
+#
+# Here is a deny example of Net::SMTP with the default "localhost.localdomain"
+#
+# Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain
+# Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host
+#
+# This maildomain*() code is based on ideas in Perl library Test::Reporter
+# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
+
perl <(cat <<EOF
+sub valid_fqdn {
+ my \$domain = shift;
+ return defined \$domain && !(\$^O eq 'darwin' && \$domain =~ /\.local\$/) && \$domain =~ /\./;
+}
+sub maildomain_net {
+ use Net::Domain ();
+ my \$maildomain;
+ my \$domain = Net::Domain::domainname();
+ \$maildomain = \$domain if valid_fqdn(\$domain);
+ return \$maildomain;
+}
+sub maildomain_mta {
+ my \$maildomain;
+ for my \$host (qw(mailhost localhost)) {
+ my \$smtp = Net::SMTP->new(\$host);
+ if (defined \$smtp) {
+ my \$domain = \$smtp->domain;
+ \$smtp->quit;
+ \$maildomain = \$domain if valid_fqdn(\$domain);
+ last if \$maildomain;
+ }
+ }
+ return \$maildomain;
+}
+sub maildomain {
+ return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
+}
+
use strict;
use MIME::Parser;
use Net::SMTP;
@@ -214,7 +260,9 @@ my \$entity = \$parser->parse_open("$msg");
print "Sending announcement of ${NAME}-${PVR} via \$smtp_server\n";
+my \$smtp_domain ||= maildomain(); # get FQDN and add Hello below
my \$smtp = new Net::SMTP(\$smtp_server,
+ Hello => \$smtp_domain,
${SMTP_SERVER_PORT+Port => ${SMTP_SERVER_PORT},}
SSL => \$smtp_encryption eq 'ssl')
or die "No mailserver at ".\$smtp_server;
@@ -224,7 +272,8 @@ if (\$smtp_encryption eq 'tls') {
\$smtp->response();
\$smtp->code == 220 or die "$server does not support STARTTLS";
\$smtp = Net::SMTP::SSL->start_SSL(\$smtp) or die "STARTTLS failed";
- \$smtp->hello(\$smtp_server);
+ # Send EHLO again to receive fresh supported commands
+ \$smtp->hello(\$smtp_domain);
}
if (defined \$smtp_user) {
use Authen::SASL qw(Perl);
--
2.27.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-07-13 13:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 13:10 [PATCH] cygport announce SMTP HELO fails without smtp server FQDN Brian Inglis
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 read-only IMAP folder(s) and NNTP newsgroup(s).