unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
@ 2021-07-09 10:26 Andrew Tropin
  2021-07-10 18:23 ` Leo Famulari
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Tropin @ 2021-07-09 10:26 UTC (permalink / raw)
  To: 49486


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1: 0001-gnu-msmtp-Make-it-configurable-with-envrinoment-vari.patch --]
[-- Type: text/x-patch, Size: 7637 bytes --]

From 38987bffcd1088315c6414d6c6141140c3969e6b Mon Sep 17 00:00:00 2001
From: Andrew Tropin <andrew@trop.in>
Date: Fri, 9 Jul 2021 13:20:10 +0300
Subject: [PATCH] gnu: msmtp: Make it configurable with envrinoment variables

Add the support of following environment variables:
MSMTPQ_QUEUE_DIR
MSMTPQ_LOG
MSMTPQ_QUIET
MSMTPQ_CONN_TEST

Add new --enqueue option, which forces to enqueue message instead of
attempting to send it.

Make msmtpq quite by default for compatibility with emacs and use ping instead
of netcat for connection test.

Use binary absolute path in msmtpq and msmtp-queue scripts instead of relying
on the binary being present in the $PATH.
---
 gnu/packages/mail.scm                         | 19 +++++--
 .../patches/msmtpq-add-enqueue-option.patch   | 40 +++++++++++++
 .../patches/msmtpq-add-env-variables.patch    | 56 +++++++++++++++++++
 3 files changed, 111 insertions(+), 4 deletions(-)
 create mode 100644 gnu/packages/patches/msmtpq-add-enqueue-option.patch
 create mode 100644 gnu/packages/patches/msmtpq-add-env-variables.patch

diff --git a/gnu/packages/mail.scm b/gnu/packages/mail.scm
index 74e3bda866..ed898d91d0 100644
--- a/gnu/packages/mail.scm
+++ b/gnu/packages/mail.scm
@@ -1677,7 +1677,10 @@ addons which can add many functionalities to the base client.")
        (uri (string-append "https://marlam.de/msmtp/releases/"
                            "/msmtp-" version ".tar.xz"))
        (sha256
-        (base32 "1klrj2a77671xb6xa0a0iyszhjb7swxhmzpzd4qdybmzkrixqr92"))))
+        (base32 "1klrj2a77671xb6xa0a0iyszhjb7swxhmzpzd4qdybmzkrixqr92"))
+       (patches
+        (search-patches "msmtpq-add-enqueue-option.patch"
+                        "msmtpq-add-env-variables.patch"))))
     (build-system gnu-build-system)
     (inputs
      `(("libsecret" ,libsecret)
@@ -1704,10 +1707,18 @@ addons which can add many functionalities to the base client.")
                (install-file (string-append msmtpq "/msmtp-queue") bin)
                (install-file (string-append msmtpq "/README.msmtpq") doc)
                (install-file "scripts/vim/msmtp.vim" vimfiles)
-               ;; Don't rely on netcat being in the PATH to test for a
-               ;; connection, instead look up and ping debian.org.
+               (substitute* (string-append bin "/msmtp-queue")
+                 (("^exec msmtpq") (format #f "exec ~a/msmtpq" bin)))
                (substitute* (string-append bin "/msmtpq")
-                 (("EMAIL_CONN_TEST=n") "EMAIL_CONN_TEST=p"))
+                 (("^MSMTP=msmtp") (format #f "MSMTP=~a/msmtp" bin))
+                 ;; Make msmtpq quite by default, because Emacs treat output
+                 ;; as an indicator of error.  Logging still works as it was.
+                 (("^EMAIL_QUEUE_QUIET=\\$\\{MSMTPQ_QUIET:-\\}")
+                  "EMAIL_QUEUE_QUIET=${MSMTPQ_QUIET:-t}")
+                 ;; Use ping test instead of netcat by default, because netcat
+                 ;; is optional and can be missing.
+                 (("^EMAIL_CONN_TEST=\\$\\{MSMTPQ_CONN_TEST:-n\\}")
+                  "EMAIL_CONN_TEST=${MSMTPQ_CONN_TEST:-p}"))
                #t))))))
     (synopsis
      "Simple and easy to use SMTP client with decent sendmail compatibility")
diff --git a/gnu/packages/patches/msmtpq-add-enqueue-option.patch b/gnu/packages/patches/msmtpq-add-enqueue-option.patch
new file mode 100644
index 0000000000..275ea6d04c
--- /dev/null
+++ b/gnu/packages/patches/msmtpq-add-enqueue-option.patch
@@ -0,0 +1,40 @@
+From a1be5a9b5ebaa3941f4cb08f99482bccf52a3082 Mon Sep 17 00:00:00 2001
+From: Andrew Tropin <andrew@trop.in>
+Date: Fri, 9 Jul 2021 08:30:00 +0300
+Subject: [PATCH] msmtpq: Add --enqueue option
+
+---
+ scripts/msmtpq/msmtpq | 13 ++++++++++++-
+ 1 file changed, 12 insertions(+), 1 deletion(-)
+
+diff --git a/scripts/msmtpq/msmtpq b/scripts/msmtpq/msmtpq
+index fbf38f9..0f127f0 100755
+--- a/scripts/msmtpq/msmtpq
++++ b/scripts/msmtpq/msmtpq
+@@ -520,11 +520,22 @@ if [ ! "$1" = '--q-mgmt' ] ; then    # msmtpq - sendmail mode
+   # write mail body text to queue .mail file
+   cat > "${FQP}.mail" || \
+     log -e "$?" "creating mail body file [ ${FQP}.mail ] : failed" # test for error
++  # remove first argument, when --engueue provided
++  if [ "$1" = '--enqueue' ] ; then
++    enqueue=t
++    shift
++  fi
+   # write msmtp command line to queue .msmtp file
+   echo "$@" > "${FQP}.msmtp" || \
+     log -e "$?" "creating msmtp cmd line file { $* }"\
+                 "           to [ ${ID}.msmtp ] : failed" # test for error
+-  send_mail "$@"                     # send the mail if possible, queue it if not
++
++  if [ -n "$enqueue" ] ; then
++    enqueue_mail "$@"                # always enqueue the mail
++  else
++    send_mail "$@"                   # send the mail if possible, queue it if not
++  fi
++
+   lock_queue -u                      # unlock here
+ else                                 # msmtp-queue - queue management mode
+   shift                              # trim off first (--q-mgmt) arg
+-- 
+2.32.0
+
diff --git a/gnu/packages/patches/msmtpq-add-env-variables.patch b/gnu/packages/patches/msmtpq-add-env-variables.patch
new file mode 100644
index 0000000000..d0a2813812
--- /dev/null
+++ b/gnu/packages/patches/msmtpq-add-env-variables.patch
@@ -0,0 +1,56 @@
+From 511be91b0aad2dc9bcb9ae16b4576cd01787ac34 Mon Sep 17 00:00:00 2001
+From: Andrew Tropin <andrew@trop.in>
+Date: Fri, 9 Jul 2021 08:29:19 +0300
+Subject: [PATCH] msmtpq: Allow to control queue dir, log file, etc via env
+ variables
+
+Provided variables:
+MSMTPQ_QUEUE_DIR
+MSMTPQ_LOG
+MSMTPQ_QUIET
+MSMTPQ_CONN_TEST
+---
+ scripts/msmtpq/msmtpq | 13 +++++++------
+ 1 file changed, 7 insertions(+), 6 deletions(-)
+
+diff --git a/scripts/msmtpq/msmtpq b/scripts/msmtpq/msmtpq
+index 4b074de..fbf38f9 100755
+--- a/scripts/msmtpq/msmtpq
++++ b/scripts/msmtpq/msmtpq
+@@ -70,9 +70,9 @@ MSMTP=msmtp
+ ##            ( chmod 0700 msmtp.queue )
+ ##
+ ## the queue dir - modify this to reflect where you'd like it to be  (no quotes !!)
+-Q=~/.msmtp.queue
+-[ -d "$Q" ] || \
+-  err '' "msmtpq : can't find msmtp queue directory [ $Q ]" ''     # if not present - complain ; quit
++Q=${MSMTPQ_QUEUE_DIR:-~/.msmtp.queue}
++[ -d "$Q" ] || mkdir -p "$Q" || \
++  err '' "msmtpq : can't create msmtp queue directory [ $Q ]" ''
+ ##
+ ## set the queue log file var to the location of the msmtp queue log file
+ ##   where it is or where you'd like it to be
+@@ -84,7 +84,8 @@ Q=~/.msmtp.queue
+ ##     (doing so would be inadvisable under most conditions, however)
+ ##
+ ## the queue log file - modify (or comment out) to taste  (but no quotes !!)
+-LOG=~/log/msmtp.queue.log
++LOG=${MSMTPQ_LOG:-~/log/msmtp.queue.log}
++[ -d "$(dirname $LOG)" ] || mkdir -p "$(dirname $LOG)"
+ ## ======================================================================================
+ 
+ ## msmtpq can use the following environment variables :
+@@ -108,8 +109,8 @@ LOG=~/log/msmtp.queue.log
+ ##
+ #EMAIL_CONN_NOTEST=y                 # deprecated ; use below var
+ #EMAIL_CONN_TEST={x| |p|P|n|s}       # see settings above for EMAIL_CONN_TEST
+-EMAIL_CONN_TEST=n
+-#EMAIL_QUEUE_QUIET=t
++EMAIL_QUEUE_QUIET=${MSMTPQ_QUIET:-}
++EMAIL_CONN_TEST=${MSMTPQ_CONN_TEST:-n}
+ ## ======================================================================================
+ 
+ umask 077                            # set secure permissions on created directories and files
+-- 
+2.32.0
+
-- 
2.32.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
  2021-07-09 10:26 [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables Andrew Tropin
@ 2021-07-10 18:23 ` Leo Famulari
  2021-07-12  3:33   ` Andrew Tropin
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Famulari @ 2021-07-10 18:23 UTC (permalink / raw)
  To: Andrew Tropin; +Cc: 49486

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

On Fri, Jul 09, 2021 at 01:26:30PM +0300, Andrew Tropin wrote:
> From 38987bffcd1088315c6414d6c6141140c3969e6b Mon Sep 17 00:00:00 2001
> From: Andrew Tropin <andrew@trop.in>
> Date: Fri, 9 Jul 2021 13:20:10 +0300
> Subject: [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
> 
> Add the support of following environment variables:
> MSMTPQ_QUEUE_DIR
> MSMTPQ_LOG
> MSMTPQ_QUIET
> MSMTPQ_CONN_TEST
> 
> Add new --enqueue option, which forces to enqueue message instead of
> attempting to send it.
> 
> Make msmtpq quite by default for compatibility with emacs and use ping instead
> of netcat for connection test.
> 
> Use binary absolute path in msmtpq and msmtp-queue scripts instead of relying
> on the binary being present in the $PATH.

Thanks!

Did you send these patches upstream?

https://marlam.de/msmtp/contact/

In general, we don't patch packages to add features in Guix. We try to
stay close to what is offered by the upstream development team, except
for bug fixes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
  2021-07-10 18:23 ` Leo Famulari
@ 2021-07-12  3:33   ` Andrew Tropin
  2021-07-12 14:56     ` Leo Famulari
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Tropin @ 2021-07-12  3:33 UTC (permalink / raw)
  To: Leo Famulari; +Cc: 49486

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

Leo Famulari <leo@famulari.name> writes:

> On Fri, Jul 09, 2021 at 01:26:30PM +0300, Andrew Tropin wrote:
>> From 38987bffcd1088315c6414d6c6141140c3969e6b Mon Sep 17 00:00:00 2001
>> From: Andrew Tropin <andrew@trop.in>
>> Date: Fri, 9 Jul 2021 13:20:10 +0300
>> Subject: [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
>> 
>> Add the support of following environment variables:
>> MSMTPQ_QUEUE_DIR
>> MSMTPQ_LOG
>> MSMTPQ_QUIET
>> MSMTPQ_CONN_TEST
>> 
>> Add new --enqueue option, which forces to enqueue message instead of
>> attempting to send it.
>> 
>> Make msmtpq quite by default for compatibility with emacs and use ping instead
>> of netcat for connection test.
>> 
>> Use binary absolute path in msmtpq and msmtp-queue scripts instead of relying
>> on the binary being present in the $PATH.
>
> Thanks!
>
> Did you send these patches upstream?
>
> https://marlam.de/msmtp/contact/
>

Yes, just a few minutes ago.

> In general, we don't patch packages to add features in Guix. We try to
> stay close to what is offered by the upstream development team, except
> for bug fixes.

Agree, --enqueue is a feature and probably doesn't belong to the PM
repo, the rest is more like a fix.  Ok, let's see, what Martin will
reply to proposed changes and I'll adjust this patch accordingly.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
  2021-07-12  3:33   ` Andrew Tropin
@ 2021-07-12 14:56     ` Leo Famulari
  2021-09-14  7:44       ` Andrew Tropin
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Famulari @ 2021-07-12 14:56 UTC (permalink / raw)
  To: Andrew Tropin; +Cc: 49486

On Mon, Jul 12, 2021 at 06:33:11AM +0300, Andrew Tropin wrote:
> Agree, --enqueue is a feature and probably doesn't belong to the PM
> repo, the rest is more like a fix.  Ok, let's see, what Martin will
> reply to proposed changes and I'll adjust this patch accordingly.

Thanks, let us know what happens. I use msmtp so I'm interested :)




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables
  2021-07-12 14:56     ` Leo Famulari
@ 2021-09-14  7:44       ` Andrew Tropin
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Tropin @ 2021-09-14  7:44 UTC (permalink / raw)
  To: Leo Famulari; +Cc: 49486

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

On 2021-07-12 10:56, Leo Famulari wrote:

> On Mon, Jul 12, 2021 at 06:33:11AM +0300, Andrew Tropin wrote:
>> Agree, --enqueue is a feature and probably doesn't belong to the PM
>> repo, the rest is more like a fix.  Ok, let's see, what Martin will
>> reply to proposed changes and I'll adjust this patch accordingly.
>
> Thanks, let us know what happens. I use msmtp so I'm interested :)

On 2021-08-26 08:59, Martin Lambers wrote:

> Hi, sorry for the late response.

> I am not sure about the changes. Changing behavior via environment
> variables is fragile and non-obvious to users. And there's a reason
> 'make install' does not put msmtpq in the user's $PATH: in its
> current state, the script is really only an example that needs to be
> customized.

> I would prefer a more complete solution, possibly including a
> configuration file.

> But interest in updating or maintaining the script has been very low in
> the last years, so I assume the user base is very small. This would mean
> that just keeping it as an example is ok.

It seems that this script is unmaintained and served as an example.
Martin also proposed to take the maintanance responsibility of it in the
other message, but I needed it only for testing and don't use it anymore
and thus don't want to take this duty.

However, the patches themselves still seems good to me and they can be
useful for other people.  So we can keep them downstream and provide a
little more flexible version of msmtpq script for guix users or close
this ticket and keep them only in that thread for the history)

The first one is a little more userfriendly IMO, the second one reduces
maintanance burden, which also is a good thing.

I'm ok with both options.  LMKWYT.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-14  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-09 10:26 [bug#49486] [PATCH] gnu: msmtp: Make it configurable with envrinoment variables Andrew Tropin
2021-07-10 18:23 ` Leo Famulari
2021-07-12  3:33   ` Andrew Tropin
2021-07-12 14:56     ` Leo Famulari
2021-09-14  7:44       ` Andrew Tropin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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).