Script to delete Dovecot files in MagicMail

Posted August 19, 2018

Last updated April 1, 2019 | 7a57399


3 minute read

Every once in a while, Dovecot goofs itself up when customers are using multiple devices at the same time to check their mail, and we need to delete some files to get it to allow customers to view their emails again. This is partially a manual process until we’re able to get it more automated, but the script below has made it a bit easier to deal with needing to delete them.

Basically, it can be run with a check param to check if the files that would potentially need deleted exist, and then if you run it without any params, it will go through the process of prompting for the location and then confirm you want to delete the dovecot.index.lock, dovecot.index.cache or dovecot.index.log files. It’s hopefully pretty easy to read with all of my comments in it, so here’s the script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

# Written by oct8l (www.oct8l.com)
# https://www.apache.org/licenses/LICENSE-2.0

#
#

# This first if statment handles if you want to run the script to check if the
# files exist in the mailbox directory

# The syntax will be: ./unlock check /home/vpopmail/domains/[domain]/2/O/abc,123
#(if you were wanting to check the mailbox of my account)

if [ "$1" == "check" ]; then
	ls -l ${2}/Maildir | grep 'dovecot.index.log*\|dovecot.index.cache*\|dovecot.index.lock*' | awk '{print " "$6" "$7" "$8" "$9" "}' && exit;
fi


# This is the main part of the script to prompt you for the path of the user's
# mailbox that you can find in the Magic Mail admin page under Mailbox Info

echo "Enter the mailbox's path"
read mailboxpath
cd $mailboxpath/Maildir

# This will tell you what will be deleted by the script if you give confirmation
# in the next step

echo 
echo "-------------------------------------------------"
echo "Files up for deletion:"
echo 
ls -l | grep 'dovecot.index.log*\|dovecot.index.cache*\|dovecot.index.lock*' | awk '{print " "$6" "$7" "$8" "$9" "}'
echo 
echo "-------------------------------------------------"
echo 

# This is where you can answer y, yes, Yes, yEs, yeS, YeS, or YES if you'd like
# to go ahead and delete the files, or the script will exit if any other input
# is received
read -r -p "Would you like to delete dovecot.index.log, dovecot.index.cache and dovecot.index.lock? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
    rm dovecot.index.log* ; rm dovecot.index.cache ; rm dovecot.index.lock ; ls -l | grep 'dovecot.index.log*\|dovecot.index.cache*\|dovecot.index.lock*' | awk '{print " "$6" "$7" "$8" "$9" "}';
else
    echo "Exiting script" && exit;
fi

exit

Try it out if you by chance run MagicMail and run into these same issues! I’ll update this post when I’m able to get this fully automated.