Hey, do not feel bad with this long heading :-) , It’s really simple to find/sort email details for a particular user (Sender or Receiver) from the Exim mail queue. We have already discussed about the Exim mail server in different way. Here I am explaining different option to sort emails for a User.
Method I : Basic method with “exim” command.
We can sort the emails by using the exim command, see the examples below:
I : List all emails from a particular sender:
# exim -bp|grep "username"
Where “username” is the sender name.
Example:
root@server [~]# exim -bp|grep olne5
43h  3.6K 1WFLFH-0006uA-Gk <olne5@nothing.com>
43h  3.6K 1WFLOL-0000LX-97 <olne5@nothing.com>
43h  1.9K 1WFLQG-0000hv-5M <olne5@nothing.com>
43h  3.6K 1WFM7W-0001T5-7B <olne5@nothing.com>
42h  6.0K 1WFMEn-0002yJ-A8 <olne5@nothing.com>
42h  3.7K 1WFMGq-0003Sf-4T <olne5@nothing.com>
42h  3.5K 1WFMyn-0002yN-Tt <olne5@nothing.com>
------
------
Use “wc -l” to count total emails
Example:
root@server [~]# exim -bp|grep olne5|wc -l
191
How to remove ? Yes, that’s actually our discussion. You can remove all emails from that user using “awk” and “xargs “ options.
Syntax:
# exim -bp|grep "username"| awk {'print $3'}| xargs exim -Mrm
Example:
root@server [~]# exim -bp|grep olne5| awk {'print $3'}| xargs exim -Mrm
Sorry, I can’t illustrate the example here, because those emails are important for that user :-) .
II : List all emails to a particular address:
# exim -bp|grep "username"
Where “username” is the recipient address.
Note that, the recipient details is listed in the second line of “exim -bp” command’s output.
Example:
root@server [~]# exim -bp|grep ommdsdsd
44h  3.6K 1WFLFH-0006uA-Gk <olne5@nothing.com>
          ommdsdsdws@yahoo.com
44h  3.6K 1WFLOL-0000LX-97 <olne5@nothing.com>
          ommdsdsdws@yahoo.com
44h  1.9K 1WFLQG-0000hv-5M <olne5@nothing.com>
          ommdsdsdws@yahoo.com
43h  3.6K 1WFM7W-0001T5-7B <ommane5@cphost8.veeblehosting.com>
          ommdsdsdws@yahoo.com
------
------
You can use the “awk” & “xargs” commands to remove it from the queue.
Method II : By using the command “exiqgrep”
The command “exiqgrep” has some useful switches to manage emails which are in the Exim mail queue. Before deleting mails with exiqgrep you must have a little knowledge in “exiqgrep”.
The smart switches of “EXIQGREP” command:
1, -f : to search the exim mail queue for emails from a particular user.
Syntax:
# exiqgrep -f user@domain
2, -r : to search the exim mail queue for emails to a particular address.
Syntax:
# exiqgrep -r user@domain
3, -i : Prints the message ID
You can use it in different manner, some examples are;
Print the message-id of the entire queue:
# exiqgrep -i
You can use it with -f and -r switches to get message ID of a particular sender or receiver.
# exiqgrep -i [-r | -f] ...
4, -o : Prints messages older than a particular time.
Example:
# exiqgrep -o 86400
Where time is specified in Seconds.
5, -y : Prints messages younger than a particular time.
6, -s : Prints messages with a particular size in bytes.
Example:
# exiqgrep -s "^3..$"
“^3$” –> 3bytes
“^3.$” –> 3-30bytes
“^3..$” –> 3-300bytes
“^3…$” –> 3-3000bytes
And so on..
7, -z : list all frozen mails.
8, -x : List all unfrozen mails.
9, -c : Counts the matches with all of the above searches.
Example:
root@server [~]# exiqgrep -c -s "^3...$"
114 matches out of 584 messages
Alright, Hope you got an idea about the usages of “exiqgrep”, Now it is very simple to manage emails for a particular user with the help of “exiqgrep”.
How to remove all emails from a particular user using exiqgrep?
Do follow this command:
# exiqgrep -i -f $user | xargs exim -Mrm
How to remove all emails to a particular user using exiqgrep?
Do follow this command:
# exiqgrep -i -r $user | xargs exim -Mrm
That’s it :-) :-)