When using relay-ctrl with qmail-dk (domain keys module for qmail) I run into trouble to set additional environment data (fe. DKSIGN, or NOSPP for qmail-scanner) only for authenticated users. Although I scrutinized the sources I did not find how relay-ctr-check or relay-ctrl-allow may add a standard set of additional settings to the environment. So I altered relay-ctrl-check to do so. If "RELAY_CTRL_RELAYCLIENT_ENV" is set to a file name (fe: RELAY_CTRL_RELAYCLIENT_ENV='/var/spool/relay-ctrl/client.env') then this file is being read by relay-ctrl-check if the proper IP file can be found. Hence only authorized IPs (clients) have these values in their environment. Any previous value is overwritten!
Created attachment 44189 [details, diff] relay-ctrl-3.1.1-r2.package.diff a patch to relay-ctrl-3.1.1-r2.ebuild that includes a new enhancement to relay-ctrl-check. Necessary additional files are created and digests modified. Apply the patch within the ebuild package dir.
Moving this to qmail-bugs proper, I'll deal with it a bit later.
I see you already have a patch, but maybe this could be useful. relay-ctrl-check already does what you want: it will read the contents of the 'ip file' in /var/spool/relay-ctrl/allow/W.X.Y.Z and parse it looking for environment variables (NULL-terminated list, eg: "A=one\0B=two\0" and so on). relay-ctrl-allow use this feature to add USER and DOMAIN variables, per-ip.
since luckyluke points out that relay-ctrl already does what you want, I'm closing this bug.