netqmail execute before qmail-remote patch
This patch was extracted from the upcoming eQmail-1.09 realease to find a lowest common denominator - netqmail-1.06 in our case. It allows to execute command(s) before qmail-remote will be invoked. Command can be a program or script. So it changes the pipe qmail-rspawn –>qmail-remote to:
qmail-rspawn   –>  qmail-bfrmt  –>  qmail-remote                        
by plugin. The functionality can be compared a bit with the  qmailqueue.patch 
by Bruce Guenter. The software comes WITHOUT WARRANTY of any kind. It works fine with eQmail-1.08.1, unfortunately is was not extensively tested with netqmail-1.06. The patch may be conflicts with other patches.
Download: netqmail-1.06-before-remote.patch (sha256sum)
The patch will be discussed at the openqmail mailing list.
I will use the term $QMAIL below, which stays for the basic install folder of qmail - usually “/var/qmail” by default.
How it works
Before  qmail-remote 
will be invoked,  qmail-rspawn 
checks if  $QMAIL/bin/qmail-bfrmt 
exists. If it doesn't exists  qmail-remote 
will be invoked. Otherwise  qmail-bfrmt 
checks for its config file  $QMAIL/control/beforemote 
and tries to execute the commands given in there. In case an error occurs or the config file doesn't exists,  qmail-remote 
will be called.
Installation
Assuming a complete fresh installation, apply the patch to netqmail-1.06 source code and follow the install instructions. Run  config-bfrmt 
to create the config file. Afterwards edit  $QMAIL/control/beforemote 
according to the Configuration section above.
It may be would sometimes be an option to do a
Manual upgrade
Follow these steps (ignore unneeded ones):
./config-bfrmt cp qmail-rspawn $QMAIL/bin cp qmail-bfrmt $QMAIL/bin cp qmail-rspawn.8 qmail-bfrmt.8 $QMAIL/man/man8 cp qmail-rspawn.0 qmail-bfrmt.0 $QMAIL/cat/cat8 chgrp qmail $QMAIL/bin/{qmail-rspawn,qmail-bfrmt} chmod 711 $QMAIL/bin/qmail-rspawn chmod 755 $QMAIL/bin/qmail-bfrmt chgrp qmail $QMAIL/man/man8/* chgrp qmail $QMAIL/cat/cat8/* chown 644 $QMAIL/man/man8/* chown 644 $QMAIL/cat/cat8/*
Configuration
I will use as an example  qmail-sdkim  
, which is part of my qmail-xdkim package and does insert DKIM signatures. It is the way I use this patch and initially it was created for. The whole thing is quite simple, edit  control/beforemote 
to your needs, which looks by default like:
#!/bin/sh export DKREMOTE="$BINDIR/qmail-remote" np="qmail-sdkim" ; exec $np "$@"
As you can see I inserted a line with  qmail-sdkim 
, which calls  qmail-remote 
by itself. The $BINDIR variable comes from  qmail-bfrmt 
and has as value the path to the $QMAILHOME/bin directory (usually “/var/qmail/bin”). Make sure that  qmail-remote 
will be called with the needed parameters (“$@”) and  beware to not break the pipe! 
May be it will be more clear with another example. Edit  control/beforemote 
like:
#!/bin/sh printenv > /tmp/envars printf "$1\n$2\n$3\n" > /tmp/params export DKREMOTE="$BINDIR/qmail-remote" if ["$DKREMOTE" ] ; then $DKREMOTE "$@" else np="qmail-remote" ; exec $np "$@" fi
At least  qmail-remote 
have to be the last program of the pipe. Check out the newly created files in  /tmp 
to see what was happen.
Troubleshooting Hints
- if
 qmail-bfrmt 
doesn't exists or $QMAIL/control/beforemote 
contains an error, qmail-remote 
will be invoked directly - a log entry shows which program was invoked by
 qmail-rspawn 
- temporarily add some commands into
 $QMAIL/control/beforemote 
for debugging - it is important that
 qmail-remote 
will be called with the parameters from qmail-rspawn 
(“$@”)
/*
- at the time
 qmail-bfrmt 
will be invoked, the actual directory is $QMAIL/bin - make sure that given commands in
 $QMAIL/control/beforemote 
are correct
*/
Enjoy!
Comments
Error: Class "XMLReader" not found
An unforeseen error has occured. This is most likely a bug somewhere. It might be a problem in the captcha plugin.
More info has been written to the DokuWiki error log.