summaryrefslogtreecommitdiff
path: root/dotfiles/system/.local/bin/msmtp-enqueue.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-05-21 22:01:35 -0500
committerCraig Jennings <c@cjennings.net>2025-05-21 22:01:35 -0500
commitb4463015b97912658d630377fafbf630f7588d1e (patch)
treed04b66d992fe2ce88391889c21c5d8dc97acd0ef /dotfiles/system/.local/bin/msmtp-enqueue.sh
parent548154ea395356868e87980b149dfc0abdc84e17 (diff)
moving arch dotfiles into archsetup
Diffstat (limited to 'dotfiles/system/.local/bin/msmtp-enqueue.sh')
-rwxr-xr-xdotfiles/system/.local/bin/msmtp-enqueue.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/dotfiles/system/.local/bin/msmtp-enqueue.sh b/dotfiles/system/.local/bin/msmtp-enqueue.sh
new file mode 100755
index 0000000..c9beaca
--- /dev/null
+++ b/dotfiles/system/.local/bin/msmtp-enqueue.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env sh
+
+QUEUEDIR=$HOME/.msmtpqueue
+
+# Set secure permissions on created directories and files
+umask 077
+
+# Change to queue directory (create it if necessary)
+if [ ! -d "$QUEUEDIR" ]; then
+ mkdir -p "$QUEUEDIR" || exit 1
+fi
+cd "$QUEUEDIR" || exit 1
+
+# Create new unique filenames of the form
+# MAILFILE: ccyy-mm-dd-hh.mm.ss[-x].mail
+# MSMTPFILE: ccyy-mm-dd-hh.mm.ss[-x].msmtp
+# where x is a consecutive number only appended if you send more than one
+# mail per second.
+BASE="$(date +%Y-%m-%d-%H.%M.%S)"
+if [ -f "$BASE.mail" ] || [ -f "$BASE.msmtp" ]; then
+ TMP="$BASE"
+ i=1
+ while [ -f "$TMP-$i.mail" ] || [ -f "$TMP-$i.msmtp" ]; do
+ i=$((i + 1))
+ done
+ BASE="$BASE-$i"
+fi
+MAILFILE="$BASE.mail"
+MSMTPFILE="$BASE.msmtp"
+
+# Write command line to $MSMTPFILE
+echo "$@" > "$MSMTPFILE" || exit 1
+
+# Write the mail to $MAILFILE
+cat > "$MAILFILE" || exit 1
+
+# If we are online, run the queue immediately.
+# Replace the test with something suitable for your site.
+#ping -c 1 -w 2 SOME-IP-ADDRESS > /dev/null
+#if [ $? -eq 0 ]; then
+# msmtp-runqueue.sh > /dev/null &
+#fi
+
+exit 0