I need to keep a copy of all outgoing and
incoming email (for a single domain if possible) using qmail or Plesk. I can't recompile qmail, so qmailtap is out of the question, as is setting QUEUE_EXTRA in extra.h.
I'm pretty sure it should be possible with Plesk's mailmng utility, aka Mail Handlers but I'm having trouble getting them to work.
I've registered 2 hooks:
incoming hook
./mailmng --add-handler --handler-name=incoming --recipient-domain=example.com
--executable=/xxx/incoming.sh --context=/xxx/incoming/ --hook=before-local
incoming.sh
#!/bin/bash
# The email is passed on stdin - grab it to a variable
e=`cat -`
# $1 = context (/xxx/incoming)
# $3 = recipient (
[email protected])
# Create /xxx/incoming/
[email protected]
mkdir -p $1$3
# Save the email to /xxx/incoming/
[email protected]/0123456789.txt
echo "$e" > $1$3/`date +%s%N`.txt
# Echo PASS to stderr
echo 'PASS' >&2
# Echo the email to stdout
echo "$e"
outgoing hook
# ./mailmng --add-handler --handler-name=outgoing --sender-domain=holidaysplease.com --executable=/xxx/outgoing.sh --context=/xxx/outgoing/ --hook=before-remote
The outgoing.sh file is the same as
incoming.sh, except replace $3 (recipient) with $2 (sender).
The
incoming hook does work, but saves 2 copies of each email - one before and one after SpamAssassin has run. The outgoing hook doesn't seem to get called at all.
So finally, my questions are:
How can I make the
incoming hook save only a single copy (preferably after SpamAssassin has run)?
How can I get the outgoing hook to work?