remove specific messages from exim queue

jfall

Member
May 8, 2004
9
0
151
A user on one of my servers had bad PHP code which caused a mail loop. There are over 20,000 messages sitting in the queue that are from this particular user. How can I remove those specific messages without harming other valid messages in the queue?
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
You could script something to remove only mail based on your search criteria.

Here's a quick dirty way that may do what you need though

# cd /var/spool/exim/input

# grep -r 'sen[email protected]' * | awk '{print $1}' | cut -d: -f1 | xargs rm -f

Try without the | xargs rm -f first, to see what will be removed maybe.

# grep -r '[email protected]' * | awk '{print $1}' | cut -d: -f1

Use at your own risk. :)
 

jfall

Member
May 8, 2004
9
0
151
Yeah, I was thinking about that. I thought there may have been a more efficient way (like qmail has qmail-remove). Greping 20,000+ messages isn't something that is very effieicent, however it may get the job done
 

astopy

Well-Known Member
Apr 3, 2003
166
0
166
cPanel Access Level
Root Administrator
I've been using a script I wrote based on this thread for several months to remove certain mass emails from the queue. I've just discovered a problem with this method that others may like to know about.

It started when I noticed that it was taking a very long time to grep the few hundred messages in the queue - well over 10 minutes, probably more. So I decided to take a little look inside the directories inside /var/spool/exim/input and instantly noticed there were many, many more files than there should be. After some poking around, I soon discovered the problem: Exim stores the message headers in separate files to the message bodies, and this method of removing messages only removes the headers! I still had the message bodies from month's worth of deleted mail sitting there. I counted the files and there were well over 150,000 of them, that's over 600MB of data. No wonder grep was taking so damn long :)

I did the following to clean up the mess, without removing the few legitimate messages in the mail queue:
Code:
cd /var/spool/exim/input/
for f in */*-D; do if [ ! -f `echo $f | tr -- -D -H` ]; then rm -f $f; fi; done
This command is still running and has so far removed about 100MB worth of files. It's not exactly fast, but it's working :)