msmtpq: inherit MSMTP, Q and LOG from environment

When a user is installing msmtpq simply by copying it to a location on
their PATH, it it perfectly reasonable to ask the user to edit msmtpq
before using it. However, when installing msmtpq via a package manager,
editing the msmtpq executable itself is not a good idea. In general,
files installed by a package manager should only be modified by that
package manager (unless the file is a configuration file).

Additionally, recommending that users to edit a script before it is used
creates friction when the script is updated. Every time the script is
updated, the user has to make those same changes again.

This change allows (and even encourages) the user to set the MSMTP, Q
and LOG variables from outside of the script. This allows users to
configure the location of the msmtp executable, msmtpq’s queue directory
and msmtpq’s log without modifying msmtpq itself.

This change was inspired by a patch that was included in a nixpkgs PR:
<f8e3437ef2 (diff-db16f24325854530247bb84d212795a677d9477a0507fb9aa174f561653c5138R11)>
pull/89/head
Jason Yundt 2 months ago committed by Martin Lambers
parent 91a5c7c43c
commit 8139cf6207
  1. 21
      scripts/msmtpq/README.msmtpq
  2. 25
      scripts/msmtpq/msmtpq

@ -55,7 +55,7 @@ from msmtpq
Configuration :
-------------
all config is done within the msmtpq script
all config is done by exporting these environment variables
set the MSMTP var to point to the location of the msmtp executable
(set this only if necessary ; if it's not on the path)
@ -68,15 +68,12 @@ circumstances, such as embedded systems, etc. ; otherwise, if you are
running a normal Linux distribution you can leave it as is ; msmtp will
by default be on the execution path
the Q variable should have the location of the queue directory
the Q variable should have the location of the queue directory ; please
note that it's preferable to create the queue directory (with 0700
permissions) before using these routines
the LOG variable should have the desired name & location of the queue log
the locations are clearly marked near the beginning of the script ;
modify all to the locations you prefer (the defaults work for me ; you
may or may not be happy with them) ... please note that it's preferable
to create the queue directory (with 0700 permissions) before using these
routines
the LOG variable should have the desired name & location of the queue
log ; set it to an empty string (export LOG="") to disable logging
note that the default msmtpq set up creates a separate log for queue
operations ; all operations which modify the queue in any way are logged
@ -85,9 +82,9 @@ to the queue log ; this is distinct from the msmtp log set by the
have separate logs (for the distinct functions) ; if this doesn't sit
well with you it's possible to define the queue log to be the same log
file as the one defined in .msmtprc ; it's also possible to turn off
queue logging entirely (by commenting out the 'LOG=' var - to be
'#LOG=') but this seems hardly advisable, particularly before you are
confident that all is working
queue logging entirely (by setting LOG to an empty string -
export LOG="" ) but this seems hardly advisable, particularly before
you are confident that all is working
mutt users please take note of the additional setup instructions in the
msmtp docs & man page.

@ -56,12 +56,13 @@ err() { dsp '' "$@" '' ; exit 1 ; }
## ======================================================================================
##
## only if necessary (in unusual circumstances - e.g. embedded systems),
## enter the location of the msmtp executable (no quotes !!)
## e.g. ( MSMTP=/path/to/msmtp )
## and uncomment the test for its existence
MSMTP=msmtp
#[ -x "$MSMTP" ] || \
# log -e 1 "msmtpq : can't find the msmtp executable [ $MSMTP ]" # if not found - complain ; quit
## export the location of the msmtp executable before running this script (no quotes !!)
## e.g. ( export MSMTP=/path/to/msmtp )
if [ "$MSMTP" = "" ] ; then # If MSMTP is unset or empty...
MSMTP=msmtp
elif [ ! -x "$MSMTP" ] ; then
log -e 1 "msmtpq : can't find the msmtp executable [ $MSMTP ]" # if not found - complain ; quit
fi
##
## set the queue var to the location of the msmtp queue directory
## if the queue dir doesn't yet exist, create it (0700)
@ -69,8 +70,8 @@ MSMTP=msmtp
## e.g. ( mkdir msmtp.queue )
## ( chmod 0700 msmtp.queue )
##
## the queue dir - modify this to reflect where you'd like it to be (no quotes !!)
Q=~/.msmtp.queue
## the queue dir - export this variable to reflect where you'd like it to be (no quotes !!)
Q=${Q:-~/.msmtp.queue}
[ -d "$Q" ] || mkdir -m 0700 "$Q" || \
err '' "msmtpq : can't find or create msmtp queue directory [ $Q ]" '' # if not present - complain ; quit
##
@ -79,12 +80,12 @@ Q=~/.msmtp.queue
## ( note that the LOG setting could be the same as the )
## ( 'logfile' setting in .msmtprc - but there may be )
## ( some advantage in keeping the two logs separate )
## if you don't want the log at all unset (comment out) this var
## LOG=~/log/msmtp.queue.log --> #LOG=~/log/msmtp.queue.log
## if you don't want the log at all set the var to an empty string
## (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
## the queue log file - export this variable to change where logs are stored (but no quotes !!)
## Set it to "" (empty string) to disable logging.
[ -v LOG ] || LOG=~/log/msmtp.queue.log
## ======================================================================================
## msmtpq can use the following environment variables :

Loading…
Cancel
Save