How to recover messages on yanked folder on Qmail
Script name : unyank
How to use?
First you have to know the ID of the messages that moved to yanked folder. Then, you can run below command to recover the message to qmail queue (please turn off the qmail service before initiate recover process).
./unyank MESSAGE_ID
i.e
./unyank 6338259
This is the script :
#!/bin/bash
# Author: David Croft
# To the extent possible under law, the person who associated CC0 with this work has
# waived all copyright and related or neighboring rights to this work.
yankeddir=/var/qmail/queue/yanked
queuedir=/var/qmail/queue
confsplit=23
if [ -z "$1" ]; then
echo "syntax: $0 "
echo "Restores the message to the queue. Make sure qmail-send is not running!"
exit 1
fi
# allow the msgid to be passed as a (possibly absolute) filename - strip it down to just the msgid
msgid=`basename $1 | sed 's/\.\(info\|mess\|remote\|bounce\|intd\|todo\)//'`
# check that the mess file exists
mess=$yankeddir/$msgid.mess
if [ ! -f $mess ]; then
echo "Message file does not exist ($mess)"
exit 1
fi
# validate inode number still matches filename
inode=`ls -di $mess | cut -d ' ' -f 1`
if [ "$msgid" -ne "$inode" ]; then
echo "Cannot unyank message $msgid - inode is different ($inode)"
exit 1
fi
# Calculate the hashed dir
let dirnum="$msgid % $confsplit"
echo "restoring message $msgid to split dir $dirnum"
# Restore the message
mv $yankeddir/$msgid.mess $queuedir/mess/$dirnum/$msgid
mv $yankeddir/$msgid.info $queuedir/info/$dirnum/$msgid
if [ -f $yankeddir/$msgid.remote ]; then
mv $yankeddir/$msgid.remote $queuedir/remote/$dirnum/$msgid
fi
if [ -f $yankeddir/$msgid.local ]; then
mv $yankeddir/$msgid.local $queuedir/local/$dirnum/$msgid
fi
if [ -f $yankeddir/$msgid.intd ]; then
mv $yankeddir/$msgid.intd $queuedir/intd/$dirnum/$msgid
fi
if [ -f $yankeddir/$msgid.bounce ]; then
mv $yankeddir/$msgid.bounce $queuedir/bounce/$msgid
fi
if [ -f $yankeddir/$msgid.todo ]; then
mv $yankeddir/$msgid.todo $queuedir/todo/$dirnum/$msgid
fi
