#!/bin/sh # # qmail-reinject: move a message from state 5 to state 4 # ie from preprocessed to queued stat # useful when a message is "stuck" in the wrong queue # (local or remote) or to force a delivery retry # usage: qmail-reinject [-v] inode # reinjects the message int ~qmail/queue/mess/xx/inode # function die() { rm -f "$1"; shift echo ${1+"$@"} exit 1 } if [ "$1" = "-v" ]; then v=verbose shift; fi if [ $# = 0 ]; then echo usage: fixit [options] inode echo options: -v verbose exit fi q=/opt/qmail/queue u=$UID i=$1; echo $i | grep [^0-9] &>/dev/null && die "" "'$i' is not an inode" p=$$ if [ -n "$v" ]; then echo my uid is $UID and my pid is $p echo looking for message with inode $i fi F=$(cat $q/info/*/$i 2>/dev/null); [ -z "$F" ] && die "" bogus F T=$(cat $q/remote/*/$i 2>/dev/null); [ -z "$F" ] && die "" bogus T r=$(echo $q/mess/*/$i | sed "s@^$q/mess/@@;s@/$i@@"); [ -f $q/mess/$r/$i ] || die "" "Can't find mess subdirectory" w=$(echo $q/local}/$r/$i | sed "s@^$q/@@;s@/$r/$i@@") [ -f $q/$q/$r/$i ] || w=$(echo $q/remote/$r/$i | sed "s@^$q/@@;s@/$r/$i@@") [ -f $q/$w/$r/$i ] || die "" "Can't find local or remote (looking for '$w')" if [ -n "$v" ]; then echo message lives in mess/$r echo from ${F##F} to ${T##T} fi # make todo [ -n "$v" ] && echo writing pid/$p printf 'u%s\0p%s\0%s\0%s\0' $u $p $F $T > $q/pid/$p [ $? = 0 ] || die $q/pid/$p failed to create todo [ -n "$v" ] && echo changing permission of pid/$p to 644 qmailq.users chown qmailq.users $q/pid/$p && chmod 644 $q/pid/$p [ $? = 0 ] || die $q/pid/$p failed to set ownership of todo [ -n "$v" ] && echo linking pid/$p to todo/$r/$p ln $q/pid/$p $q/todo/$r/$i [ $? = 0 ] || die $q/pid/$p failed to link todo [ -n "$v" ] && echo unlinking pid/$p rm $q/pid/$p # make intd [ -n "$v" ] && echo copying todo/$r/$p to intd/$r/$i cp -p $q/todo/$r/$i $q/intd/$r/$i [ $? = 0 ] || die "" failed to create intd # lose info and remote [ -n "$v" ] && echo unlinking info/$r/$i and $w/$r/$i rm -f $q/info/$r/$i $q/$w/$r/$i