Repair Courier IMAP maildir
A handy little script to repair maildirs.
I stupidly deleted all empty folders in users' homes, realizing too late that it would delete some of the essential new, cur and tmp directories in the maildirs. After that, folders could not be opened anymore. Outlook would say "STATUS failed", and Thunderbird reported "Unable to open this mailbox".
This little script recreated the missing directories:
I stupidly deleted all empty folders in users' homes, realizing too late that it would delete some of the essential new, cur and tmp directories in the maildirs. After that, folders could not be opened anymore. Outlook would say "STATUS failed", and Thunderbird reported "Unable to open this mailbox".
This little script recreated the missing directories:
#!/bin/sh
for M in /home/*/Maildir ; do
echo checking $M
for d in cur new tmp ; do
[ -d "$M/$d" ] || { echo "* Creating $M/$d"; mkdir "$M/$d"; }
chown -c --reference "$M" "$M/$d"
chmod -c 700 "$M/$d"
done
find $M -type f -name maildirfolder | while read ; do
f=`dirname "$REPLY"`
echo " checking $f"
for d in cur new tmp ; do
[ -d "$f/$d" ] || { echo " * Creating $f/$d"; mkdir "$f/$d"; }
chown -c --reference "$f" "$f/$d"
chmod -c 700 "$f/$d"
done
done
done
9 Comments:
thanks for your little script :o).
i had same problems after running "cleanlinks".
everything is fine again now.
thank you too for this script! helped a lot!
OMG. I have been looking for a fix to the "STATUS failed" thing ever since I put in courier-imap.
Thank you so very much.
Hello,
I upgraded your script for users of vpopmail with virtual domains, and, it also accounts for missing new/cur/tmp directories in the .Draft/, .Sent/ and .Trash/ directories:
#!/bin/sh
domain=$1
if [ -z "$domain" ] ; then
echo -n "Enter broken domain name: "
read domain
fi
if [ -d "/home/vpopmail/domains/$domain/*/Maildir" ] ; then
echo "I couldn't find /home/vpopmail/domains/$domain/*/Maildir"
echo "Exiting."
exit 1
fi
for M in /home/vpopmail/domains/$domain/*/Maildir ; do
echo checking $M
for d in cur new tmp ; do
[ -d "$M/$d" ] || { echo "* Creating $M/$d"; mkdir "$M/$d"; }
chown -c --reference "$M" "$M/$d"
chmod -c 700 "$M/$d"
done
find $M -type f -name maildirfolder | while read ; do
f=`dirname "$REPLY"`
echo " checking $f"
for d in cur new tmp ; do
[ -d "$f/$d" ] || { echo " * Creating $f/$d"; mkdir "$f/$d"; }
chown -c --reference "$f" "$f/$d"
chmod -c 700 "$f/$d"
done
done
done
for subdir in .Sent .Drafts .Trash ; do
for M in /home/vpopmail/domains/$domain/*/Maildir/$subdir ; do
echo checking $M
for d in cur new tmp ; do
[ -d "$M/$d" ] || { echo "* Creating $M/$d"; mkdir "$M/$d"; }
chown -c --reference "$M" "$M/$d"
chmod -c 700 "$M/$d"
done
find $M -type f -name maildirfolder | while read ; do
f=`dirname "$REPLY"`
echo " checking $f"
for d in cur new tmp ; do
[ -d "$f/$d" ] || { echo " * Creating $f/$d"; mkdir "$f/$d"; }
chown -c --reference "$f" "$f/$d"
chmod -c 700 "$f/$d"
done
done
done
done
Hope someone gets some use out of this.
You have saved my arse.....
Your script fix my email beautifully, Thanks so much:)
Randall
Yes, i agree all postings here. Very clean and easy. I just surrounded this script with running through all my virtual domains on a plesk-system.
So i added/changed the lines
for DOM in /var/qmail/mailnames/*; do
for M in $DOM/*/Maildir; do
in the beginning and the closing
done
at the end.
That vpopmail modified script saved me! THANKS FOR THAT!!!
Thank you very much! helped me to repair our companys mail server :)
Thanks for this script. Worked first time, saved me googling for yet more hours!
:)
Post a Comment
<< Home