diff options
| author | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-07-04 22:03:17 +0200 |
|---|---|---|
| committer | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-07-04 22:03:17 +0200 |
| commit | 2e09b15a077fc4f5c8e4189336a534ec88728c13 (patch) | |
| tree | 1855f36fb50b8b7ec26b9f422d22721890f5e8f8 | |
| parent | b1696a55c38a1838ca25ebad58cd5b9ad48a9b75 (diff) | |
implement cron
| -rwxr-xr-x | src/muttdelay | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/muttdelay b/src/muttdelay index a5a8bf5..3e3213c 100755 --- a/src/muttdelay +++ b/src/muttdelay @@ -1,5 +1,45 @@ #!/usr/bin/env bash +# (c) 2014 by Paul C. Buetow + declare -r VERSION='VERSION_DEVEL' +declare -r ARG="${1}" ; shift +declare -r QUEUE="${HOME}/.maildelayed" +declare -r MAILCMD='msmtp -t' + +usage () { + cat - <<USAGE >&2 + Usage: $0 mutt|cron +USAGE +} + +# Run by a periodic cron job +cron () { + declare -r now=$(date +%s) + + ls "${QUEUE}" | + while read mail; do + when=$(sed -E 's/^([0-9]+)\..*/\1/' <<< "${mail}") + if [ $now -gt $when ]; then + $MAILCMD < "${QUEUE}/${mail}" && rm "${QUEUE}/${mail}" + fi + done +} + +# Run from mutt +mutt () { + echo Not yet implemented + exit 3 +} + +[ ! -d "${QUEUE}" ] && mkdir "${QUEUE}" && chmod 0700 "${QUEUE}" + +case "${ARG}" in + cron) cron;; + mutt) mutt;; + *) usage;; +esac + +exit 0 -echo "This is version $VERSION of the example muttdelay project." +# vim: filetype=sh |
