diff options
Diffstat (limited to 'maintainer')
| -rwxr-xr-x | maintainer/mutt-hooks/b4-shazam.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/maintainer/mutt-hooks/b4-shazam.sh b/maintainer/mutt-hooks/b4-shazam.sh new file mode 100755 index 0000000..4920658 --- /dev/null +++ b/maintainer/mutt-hooks/b4-shazam.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +REPO_DIR=/home/cem/Source/MAINTAINER/xfs-linux +FORMAIL=$(which formail) +B4=$(which b4) + +_die() { + echo $1 + exit 1 +} + +check_env() { + + if [ ! -d $REPO_DIR ]; then + _die "Linux repo does not exist" + fi + + if [ -z $FORMAIL ]; then + _die "Formail program missing" + fi + + if [ -z $B4 ]; then + _die "b4 program missing" + fi +} + +shazam_message() { + local MSG_ID=$1 + local CUR_DIR=$PWD + + cd $REPO_DIR + + $B4 shazam -s $MSG_ID + + if [ $? -ne 0 ]; then + cd $CUR_DIR + _die "Failed to apply $MSG_ID" + fi + + cd $CUR_DIR + echo "Message/Series $MSG_ID applied" +} + +check_env + +MSG="" + +if [ ! -t 0 ]; then + MSG=$(cat) +else + _die "No email has been piped" +fi + +# Quote $MSG to trick the shell's IFS +MESSAGE_ID=$(echo "$MSG" | formail -x message-id | sed 's/[<>]//g') + +if [ -z $MESSAGE_ID ]; then + _die "Message is empty" +fi + +shazam_message $MESSAGE_ID |
