X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=blobdiff_plain;ds=sidebyside;f=bsmtp-pull;fp=bsmtp-pull;h=5a2c474c6c68fc09bdf879bda76c08221888eae8;hb=f65a1cbceaa3ab471e5d9fa87f5637559e3b581d;hp=0000000000000000000000000000000000000000;hpb=8a33889ddb76bf64dbca86b40805d4a354b99f65;p=bin.git diff --git a/bsmtp-pull b/bsmtp-pull new file mode 100755 index 0000000..5a2c474 --- /dev/null +++ b/bsmtp-pull @@ -0,0 +1,31 @@ +#! /bin/sh +# Depends: lockfile-progs, ssh +set -e + +if [ -z "$1" ]; then + echo "Usage: $0 hostname" 2>&1 + exit 1 +fi + +DIR="$HOME/.bsmtp" +mkdir -p "$DIR" +cd "$DIR" + +HOST="$1" + +# TODO: Note that this scheme may currently lose mail if the local disk +# fills up! This is obviously very bad. Fix this. + +# By default, lockfile-create gives up after three minutes, so don't cron +# this any more frequently than that without supplying a --retry argument. +lockfile-create "$HOST" +lockfile-touch "$HOST" & +TOUCH="$!" +trap 'kill "$TOUCH"; lockfile-remove "$HOST"' EXIT ERR HUP INT QUIT TERM + +ssh -2 -C "$HOST" bsmtp-pull-server > "$HOST" +[ -s "$HOST" ] || exit 0 +/usr/sbin/sendmail -bS < "$HOST" +rm -f "$HOST" + +exit 0