#!/bin/sh # (c) 2003 S. Smeenk MAILDIR=/home/ssmeenk/Maildir HOOKS=/home/ssmeenk/.mutt/folderhooks ACTED=0 TEMP=`mktemp` if [ -e $HOOKS ]; then # For safety, put a backup copy :) cp $HOOKS $HOOKS.backup mv -f $HOOKS $TEMP else echo "[!] $HOOKS: File not found!" exit 0 fi if ! cat $TEMP | grep -q 'folder-hook \. unmy_hdr From:'; then echo "[!] No default folder-hook found! [FIXED]" echo "folder-hook . unmy_hdr From:" >> $TEMP fi echo "[*] Checking for non-existing folderhooks ..." for FOLDER in `cat $TEMP | grep -v "^#" | awk '{print $2}'`; do if ! [ -d $MAILDIR/$FOLDER ]; then echo "[?] Folder $FOLDER was found deleted! Removed hook." TEMP2=`mktemp` grep -v "$FOLDER" $TEMP > $TEMP2 mv $TEMP2 $TEMP fi done echo "[*] Stage one completed." mv $TEMP $HOOKS echo "[*] Checking for new folders." for MAILDIR in `mailboxes | sed -e 's/=//g'` do if ! grep -q "$MAILDIR" $HOOKS; then echo "[*] No folder-hook for '$MAILDIR'!" echo " Leave fields empty to use alternates / default from" echo " What real name should be used for this folder:" echo -n " > " read REALN echo " What email address should be used for this folder:" echo -n " > " read EMAIL if [ "x$REALN" == "x" ] && [ "x$EMAIL" == "x" ]; then echo "folder-hook $MAILDIR unmy_hdr From:" >> $HOOKS else echo "folder-hook $MAILDIR my_hdr From: $REALN <$EMAIL>" >> $HOOKS fi echo " " ACTED=1 fi done # Reverse sort the list :) TEMP=`mktemp` sort < $HOOKS > $TEMP mv $TEMP $HOOKS echo "[*] Stage two completed." if [ "$ACTED" = "1" ]; then echo "[*] New folder-hooks installed succesfully." else echo "[*] No new maildirs found." fi