public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-apps@cygwin.com
Subject: Re: [PATCH cygport] Add customization support for announce command
Date: Sun, 10 Mar 2024 17:33:29 +0100	[thread overview]
Message-ID: <acad7482-1ff4-f9d5-acf6-684e9105d982@t-online.de> (raw)
In-Reply-To: <20d64930-9c17-4fb0-861e-3145b5d67601@dronecode.org.uk>

[-- Attachment #1: Type: text/plain, Size: 1755 bytes --]

Jon Turney wrote:
> On 23/02/2024 11:23, Christian Franke via Cygwin-apps wrote:
>> Christian Franke wrote:
>>> The email generated by the cygport announce command is useful, but 
>>> actual use cases are somewhat limited due to the hard-coded email 
>>> submission.
>>>
>>> The attached patch adds more flexibility. The patch is on top of the 
>>> "Use correct wording if only one package is announced" patch.
>>
>> Slightly changed patch attached. Also adjusted to new version of "Use 
>> correct wording if only one package is announced" patch.
>>
>>
> [...]
>
> Thanks for this.
>
>> Possible (better?) alternative names for the new settings:
>> ANNOUNCEMENT_EDITOR
>> ANNOUNCEMENT_MAILER
>
> Hmmm... I think "ANNOUNCE_EDITOR" and "ANNOUNCE_MAILER" would be
> the best for clarity and conciseness.

New patch attached. Is still on top of "Use correct wording ..." patch.

I also added HOMEPAGE to the propagated variables as this should be 
included in an announcement.


>
>
>> -From: ${SMTP_SENDER}
>> -To: cygwin-announce@cygwin.com
>> +${SMTP_SENDER:+From: ${SMTP_SENDER}
>> +}To: cygwin-announce@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|')>
>> +Message-Id: <$(date "+%Y%m%d%H%M%S.$$" --date=${msgat})-1-$(echo 
>> ${SMTP_SENDER:-cygport} | sed 's|.*<\(.*\)>.*|\1|')>
>>  Subject: ${NAME} ${PVR}
>
> Can you also explain what this is doing in the commit message, since 
> it's not immediately apparent.
>
>

If the mail infrastructure always replaces the "From:" line or the 
default one is sufficient, then there is no need to generate one. 
SMTP_SENDER could be left alone then. I added a related comment to 
cygport.conf


[-- Attachment #2: 0001-Add-customization-support-for-announce-command.patch --]
[-- Type: text/plain, Size: 5155 bytes --]

From 335cbde3c6c2450051cc739cee60a555b236843e Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Sun, 10 Mar 2024 17:28:09 +0100
Subject: [PATCH] Add customization support for announce command

Two new configuration settings allow to override the launch of
a text editor (ANNOUNCE_EDITOR) and the builtin email submission
(ANNOUNCE_MAILER).  Don't create a "From:" header line if
SMTP_SENDER is undefined or empty.
---
 data/cygport.conf      | 27 +++++++++++++++++++-
 lib/pkg_upload.cygpart | 57 +++++++++++++++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/data/cygport.conf b/data/cygport.conf
index 34ccd291..3da744d9 100644
--- a/data/cygport.conf
+++ b/data/cygport.conf
@@ -101,10 +101,35 @@
 #PAGER=
 
 
+#****v* Configuration/ANNOUNCE_EDITOR
+#  DESCRIPTION
+#  Shell command string to process the email message created by cygport's
+#  announce command before sending the email.  If undefined, a text editor
+#  will be run, see EDITOR setting above.  If empty, nothing will be run.
+#  If not empty, '/bin/bash' will be launched with the command string passed
+#  with '-c' option and the path of the temporary email message file as '$1'.
+#  The working directory of the shell will be the directory of the cygport
+#  file.  The specified command string will be prepended by shell assignments
+#  of the cygport variables HOMEPAGE, P, PF, PN, PR and PV and all SMTP_*
+#  settings described below.
+#ANNOUNCE_EDITOR=
+
+#****v* Configuration/ANNOUNCE_MAILER
+#  DESCRIPTION
+#  Shell command string to process the email message created by cygport's
+#  announce command after editing.  If undefined, the email will be sent
+#  using the builtin perl-based SMTP support.  If empty, nothing will be run.
+#  If not empty, the command string will be handled similar to ANNOUNCE_EDITOR
+#  described above.
+#ANNOUNCE_MAILER=
+
+
 #****v* Configuration/SMTP_SENDER
 #  DESCRIPTION
 #  Name and email address, in the form of "First Last <user@domain>" to be used
-#  by cygport's announcement command.
+#  by cygport's announcement command.  If undefined or empty, no "From:" email
+#  header line will be generated.  The local mail tool or the mail provider may
+#  unconditionally replace this header line or only the "<user@domain>" part.
 #  NOTE
 #  Many webmail services do not allow using arbitrary sender address in SMTP
 #  mail, or may first require registering other email addresses as authorized
diff --git a/lib/pkg_upload.cygpart b/lib/pkg_upload.cygpart
index 37bc2d63..9ced1fb5 100644
--- a/lib/pkg_upload.cygpart
+++ b/lib/pkg_upload.cygpart
@@ -168,6 +168,34 @@ EOF
 	echo "Upload complete."
 }
 
+__pkg_announce_run_cmd_on_msg() {
+	local cmdvar=$1
+	local msg=$2
+	local cmd
+
+	eval cmd="\${${cmdvar}}"
+
+	if [ "${cmd:+y}" != "y" ]
+	then
+		inform "\${${cmdvar}} is empty"
+		return 0
+	fi
+	echo
+	inform "Launching '\${${cmdvar}} ${msg}'"
+
+	/bin/bash -c "cd ${top} || exit 1
+${HOMEPAGE+HOMEPAGE=${HOMEPAGE@Q}}
+P=${P@Q}; PF=${PF@Q}; PN=${PN@Q}; PR=${PR@Q}; PV=(${PV[*]@Q})
+${SMTP_SENDER+SMTP_SENDER=${SMTP_SENDER@Q}}
+${SMTP_SERVER+SMTP_SERVER=${SMTP_SERVER@Q}}
+${SMTP_SERVER_PORT+SMTP_SERVER_PORT=${SMTP_SERVER_PORT@Q}}
+${SMTP_ENCRYPTION+SMTP_ENCRYPTION=${SMTP_ENCRYPTION@Q}}
+${SMTP_USER+SMTP_USER=${SMTP_USER@Q}}
+${SMTP_PASS+SMTP_PASS=${SMTP_PASS@Q}}
+${cmd}
+" 		$0 ${msg} || error "Command '\${${cmdvar}} ${msg}' (cwd=${top}) failed"
+}
+
 __pkg_announce() {
 	local msg=$(mktemp -t cygwin-announce-${PF}.XXXXXX)
 	local msgat=$(date +@%s)
@@ -178,10 +206,10 @@ __pkg_announce() {
 
 	cat > ${msg} <<_EOF
 From cygwin-announce-${PF} $(date '+%a %b %d %H:%M:%S %Y' --date=${msgat})
-From: ${SMTP_SENDER}
-To: cygwin-announce@cygwin.com
+${SMTP_SENDER:+From: ${SMTP_SENDER}
+}To: cygwin-announce@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|')>
+Message-Id: <$(date "+%Y%m%d%H%M%S.$$" --date=${msgat})-1-$(echo ${SMTP_SENDER:-cygport} | sed 's|.*<\(.*\)>.*|\1|')>
 Subject: ${NAME} ${PVR}
 
 The following package${s_have} been uploaded to the Cygwin distribution:
@@ -199,7 +227,24 @@ _EOF
 ${DESCRIPTION}
 _EOF
 
-	${EDITOR:-vi} $msg || error "Editor exited abormally, aborting annoucement"
+	if [ "${ANNOUNCE_EDITOR+y}" = "y" ]
+	then
+		__pkg_announce_run_cmd_on_msg ANNOUNCE_EDITOR ${msg}
+	else
+		${EDITOR:-vi} ${msg} || error "Editor exited abnormally, aborting announcement"
+	fi
+
+	if [ "${ANNOUNCE_MAILER+y}" = "y" ]
+	then
+		__pkg_announce_run_cmd_on_msg ANNOUNCE_MAILER ${msg}
+	else
+		__pkg_announce_to_smtp ${msg}
+	fi
+	rm ${msg}
+}
+
+__pkg_announce_to_smtp() {
+	local msg=$1
 
 	perl <(cat <<EOF
 use strict;
@@ -242,8 +287,8 @@ if (defined \$smtp_user) {
 \$smtp->quit();
 print "Announcement sent\n";
 EOF
-) && rm $msg || error "Sending announcement failed, mbox is $msg"
+) || error "Sending announcement failed, mbox is $msg"
 }
 
 # protect functions
-readonly -f __pkg_upload __pkg_announce
+readonly -f __pkg_upload __pkg_announce __pkg_announce_run_cmd_on_msg __pkg_announce_to_smtp
-- 
2.43.0


  reply	other threads:[~2024-03-10 16:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 14:52 Christian Franke
2024-02-23 11:23 ` Christian Franke
2024-03-10 14:37   ` Jon Turney
2024-03-10 16:33     ` Christian Franke [this message]
2024-04-29 19:37       ` Jon Turney
2024-04-30 10:27         ` Christian Franke
2024-05-01 12:50           ` Adam Dinwoodie
2024-05-01 14:49             ` Christian Franke
2024-05-01 21:00               ` Adam Dinwoodie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=acad7482-1ff4-f9d5-acf6-684e9105d982@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).