[Dovecot] Passing info from mail process to mail_filter plugin script?

Timo Sirainen tss at iki.fi
Wed Sep 25 04:12:40 EEST 2013

On 25.9.2013, at 3.06, Charles Cazabon <charlesc-dovecot at pyropus.ca> wrote:

> Timo Sirainen <tss at iki.fi> wrote:
>> Without modifications the only way to pass data is via the plugin {
>> mail_filter } parameters, such as the %u expanding to username in the
>> example.
> I hacked an additional %variable (I used %q) into a copy of
> mail-user.c:mail_user_var_expand_table () (and called this modified version
> instead of the original, in the same place it is normally called), and moved
> my data collection around in imap/main.c:settings_var_expand() so that my info
> was available at the time mail_user->var_expand_table is populated.

Better to not give a one character name, but only the long name so it won't conflict with any future Dovecot additions.

> This appears to be working thus far.  If I iterate over that table, my custom
> variable is present and has a correct key, value, and long_key before
> client_create() is called.  
> But when I put %q into the mail_filter config like so:
>  mail_plugins = $mail_plugins mail_filter
>  plugin {
>    mail_filter = mail-filter %q foo %u
>    mail_filter_out = mail-filter-out %u
>  }
> ... and restart Dovecot, I find that the filter script is only being passed 2
> arguments, the constant "foo" in the above and the username.  The %q does not
> appear to be getting replaced; it's just skipped over.  It's not even passing
> an empty string in its place.

Hmm. yeah, the empty string isn't there because mail-filter uses t_strsplit_spaces() instead of t_strsplit(). I suppose it should use t_strsplit().

> Am I modifying the correct var_expand_table here?  Is there any step I've
> missed in making the new variable get substituted properly?  lib/var-expand.c
> doesn't appear to require anything else, but I may have missed something…

It looks like this should be correct. The plugin settings expansion i done by mail-user.c:mail_user_expand_plugins_envs().

The other possibility would be that you just modify mail-filter plugin and add the extra parameter without any %variable changes. Probably better since then you don't need to patch Dovecot core itself.

More information about the dovecot mailing list