"Fossies" - the Fresh Open Source Software Archive

Member "msmtp-1.8.5/scripts/msmtpqueue/msmtp-runqueue.sh" (2 May 2019, 1484 Bytes) of package /linux/privat/msmtp-1.8.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "msmtp-runqueue.sh": 1.8.4_vs_1.8.5.

    1 #!/usr/bin/env sh
    2 
    3 QUEUEDIR="$HOME/.msmtpqueue"
    4 LOCKFILE="$QUEUEDIR/.lock"
    5 MAXWAIT=120
    6 
    7 OPTIONS=$*
    8 
    9 # eat some options that would cause msmtp to return 0 without sendmail mail
   10 case "$OPTIONS" in 
   11     *--help*)
   12     echo "$0: send mails in $QUEUEDIR"
   13     echo "Options are passed to msmtp"
   14     exit 0
   15     ;;
   16     *--version*)
   17     echo "$0: unknown version"
   18     exit 0
   19     ;;
   20 esac
   21 
   22 # wait for a lock that another instance has set
   23 WAIT=0
   24 while [ -e "$LOCKFILE" ] && [ "$WAIT" -lt "$MAXWAIT" ]; do
   25     sleep 1
   26     WAIT="$((WAIT + 1))"
   27 done
   28 if [ -e "$LOCKFILE" ]; then
   29     echo "Cannot use $QUEUEDIR: waited $MAXWAIT seconds for"
   30     echo "lockfile $LOCKFILE to vanish, giving up."
   31     echo "If you are sure that no other instance of this script is"
   32     echo "running, then delete the lock file."
   33     exit 1
   34 fi
   35 
   36 # change into $QUEUEDIR 
   37 cd "$QUEUEDIR" || exit 1
   38 
   39 # check for empty queuedir
   40 if [ "$(echo ./*.mail)" = './*.mail' ]; then
   41     echo "No mails in $QUEUEDIR"
   42     exit 0
   43 fi
   44 
   45 # lock the $QUEUEDIR
   46 touch "$LOCKFILE" || exit 1
   47 
   48 # process all mails
   49 for MAILFILE in *.mail; do
   50     MSMTPFILE="$(echo $MAILFILE | sed -e 's/mail/msmtp/')"
   51     echo "*** Sending $MAILFILE to $(sed -e 's/^.*-- \(.*$\)/\1/' $MSMTPFILE) ..."
   52     if [ ! -f "$MSMTPFILE" ]; then
   53         echo "No corresponding file $MSMTPFILE found"
   54         echo "FAILURE"
   55         continue
   56     fi
   57     msmtp $OPTIONS $(cat "$MSMTPFILE") < "$MAILFILE"
   58     if [ $? -eq 0 ]; then
   59         rm "$MAILFILE" "$MSMTPFILE"
   60         echo "$MAILFILE sent successfully"
   61     else
   62         echo "FAILURE"
   63     fi
   64 done
   65 
   66 # remove the lock
   67 rm -f "$LOCKFILE"
   68 
   69 exit 0