[PATCH v2 cygport] Fix announce to work with ISP SMTP servers
Brian Inglis
Brian.Inglis@SystematicSw.ab.ca
Sun Jan 10 07:22:35 GMT 2021
On 2021-01-09 22:50, Brian Inglis wrote:
> Please apply the attached patch to avoid my further spamming of the announce
> list again, as my ISP SMTP server requires a valid SMTP Hello domain, does not
> accept Unix Mbox 'From ' initial header line, and various other requirements to
> work reliably for sending, and receiving at sourceware.
>
> The changes were based on git-send-email SMTP exchanges, which have never been
> an issue.
> They main parts are implemented behind flag variables
> SMTP_HELLO_DOMAIN (default 1 - fixes my issue and should work generally) and
> SMTP_MBOX_FROM (default 0 - fixes my issue and should work generally),
> which could be supported in cygport.conf, but I have not yet made doc patches,
> as I would like feedback if there are any issues with the changes or flag
> variable names, being a plain, not Perl, scripter ;^>
>
> Other tweaks were required to make the headers more SMTP compliant and to avoid
> issues with picky (configuration of?) ISP SMTP servers.
Resend with current patch.
--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]
-------------- next part --------------
--- a/cygport/lib/pkg_upload.cygpart 2020-07-10 17:02:29.781319400 -0600
+++ b/cygport/lib/pkg_upload.cygpart 2020-10-26 02:21:08.690020000 -0600
@@ -168,16 +168,21 @@ EOF
echo "Upload complete."
}
-
__pkg_announce() {
local msg=$(mktemp -t cygwin-announce-${PF}.XXXXXX)
local msgat=$(date +@%s)
local -i n=0
+ local smtp_mbox_from=${SMTP_MBOX_FROM:-0}
+
+ if [ $smtp_mbox_from = 1 ]
+ then
+ echo "From cygwin-announce-${PF} $(date '+%a %b %d %H:%M:%S %Y' --date=${msgat})" >> ${msg}
+ fi
- cat > ${msg} <<_EOF
-From cygwin-announce-${PF} $(date '+%a %b %d %H:%M:%S %Y' --date=${msgat})
+ cat >> ${msg} <<_EOF
From: ${SMTP_SENDER}
-To: cygwin-announce@cygwin.com
+To: <cygwin-announce@cygwin.com>
+Reply-To: <cygwin@cygwin.com>
Date: $(date -R --date=${msgat})
Message-Id: <$(date "+%Y%m%d%H%M%S.$$" --date=${msgat})-1-$(echo ${SMTP_SENDER} | sed 's|.*<\(.*\)>.*|\1|')>
Subject: ${NAME} ${PVR}
@@ -197,7 +202,7 @@ _EOF
${DESCRIPTION}
_EOF
- ${EDITOR:-vi} $msg || error "Editor exited abormally, aborting annoucement"
+ ${VISUAL:-${EDITOR:-vi}} $msg || error "Editor exited abormally, aborting announcement"
# FQDN from git send-email
# Returns the local Fully Qualified Domain Name (FQDN) if available.
@@ -215,8 +220,12 @@ _EOF
#
# 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
+use strict;
+use MIME::Parser;
+use Net::SMTP;
+use Net::Domain qw(hostdomain hostfqdn domainname);
+
sub valid_fqdn {
my \$domain = shift;
return defined \$domain && !(\$^O eq 'darwin' && \$domain =~ /\.local\$/) && \$domain =~ /\./;
@@ -224,13 +233,13 @@ sub valid_fqdn {
sub maildomain_net {
use Net::Domain ();
my \$maildomain;
- my \$domain = Net::Domain::domainname();
+ my \$domain = domainname();
\$maildomain = \$domain if valid_fqdn(\$domain);
return \$maildomain;
}
sub maildomain_mta {
my \$maildomain;
- for my \$host (qw(mailhost localhost)) {
+ for my \$host (qw(mailhost localhost mail smtp)) {
my \$smtp = Net::SMTP->new(\$host);
if (defined \$smtp) {
my \$domain = \$smtp->domain;
@@ -245,27 +254,29 @@ sub maildomain {
return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
}
-use strict;
-use MIME::Parser;
-use Net::SMTP;
-
my \$smtp_server = "${SMTP_SERVER:-localhost}";
my \$smtp_encryption = "${SMTP_ENCRYPTION:-none}";
my \$smtp_user${SMTP_USER+ = '$SMTP_USER'};
my \$smtp_pass${SMTP_PASS+ = '$SMTP_PASS'};
+my \$smtp_hello_domain = "${SMTP_HELLO_DOMAIN:-1}";
+my \$hello = 'localhost.localdomain';
+# get FQDN and add Hello below
+\$hello ||= hostfqdn() || hostdomain() || maildomain() if \$smtp_hello_domain;
my \$parser = new MIME::Parser;
\$parser->output_to_core(1);
my \$entity = \$parser->parse_open("$msg");
+if (\$smtp_hello_domain) {
+ \$hello = \$1 if (\$entity->head->get('From') =~ m/<?[^@>]+@([^>]+)>?/);
+}
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},}
+ Hello => \$hello,
SSL => \$smtp_encryption eq 'ssl')
- or die "No mailserver at ".\$smtp_server;
+ or die "No mailserver at ".\$smtp_server.":".\$@;
if (\$smtp_encryption eq 'tls') {
require Net::SMTP::SSL;
\$smtp->command('STARTTLS');
@@ -273,7 +284,7 @@ if (\$smtp_encryption eq 'tls') {
\$smtp->code == 220 or die "$server does not support STARTTLS";
\$smtp = Net::SMTP::SSL->start_SSL(\$smtp) or die "STARTTLS failed";
# Send EHLO again to receive fresh supported commands
- \$smtp->hello(\$smtp_domain);
+ \$smtp->hello(\$hello);
}
if (defined \$smtp_user) {
use Authen::SASL qw(Perl);
@@ -282,6 +293,8 @@ if (defined \$smtp_user) {
}
\$smtp->mail(\$entity->head->get('From')) or die "unable to set sender";
\$smtp->to(\$entity->head->get('To')) or die "unable to address message";
+\$smtp->cc(\$entity->head->get('Cc')) if \$entity->head->get('Cc');
+\$smtp->bcc(\$entity->head->get('Bcc')) if \$entity->head->get('Bcc');
\$smtp->data() or die "unable to start data send";
\$smtp->datasend(\$entity->as_string()) or die "Message send failed";
\$smtp->dataend() or die "Message end failed";
More information about the Cygwin-apps
mailing list