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

Charles Cazabon charlesc-dovecot at pyropus.ca
Mon Sep 23 00:11:15 EEST 2013

Timo Sirainen <tss at iki.fi> wrote:
> On 21.9.2013, at 20.32, Charles Cazabon <charlesc-dovecot at pyropus.ca> wrote:
> > 
> > However, my mail-filter script (for filtering messages on the way from the
> > mail store through the IMAP process to a remote client) needs some extra info
> > from the IMAP mail process.  I'm having difficulty figuring out how this can
> > be accomplished.
> > 
> > Ideally, I'd like to pass another open file descriptor (opened in the IMAP
> > process) to the script, but I'm not sure if this is possible.
> imap process communicates with the mail_filter process via UNIX socket. It
> would be possible to pass a file descriptor, but it would need motifications
> to both the mail-filter/[io]stream-ext-filter.c and to src/util/script.c to
> use fd_send() and fd_recv().

Thanks for the response, Timo.

Okay, given that this looks a little more complex than the other route, I
decided to try your suggestion of adding a new % variable which I can supply
in the mail_filter plugin configuration as a commandline argument to the
filter script.

> If you want some other parameters that don't exist in %variables
> (they get expanded immediately when the imap process starts), you need to
> modify for example mail-filter-plugin.c where it passes muser->args and
> muser->out_args to [io]_stream_create_ext_filter().

I *think*, if I'm reading the code correctly, that it might be simpler in my
particular case to modify the var_expand_table directly.  The info I want to
pass to the filter becomes available in the imap code shortly after login
(actually immediately after client_add_input()), so unfortunately it's just
after settings_var_expand() is called in

I hacked in some code to change the table at that point (i.e. just before
client_create_from_input() returns), but it seems the table has already been
used to expand the vars by then, i.e. I'm just too late and my new variable
isn't recognized/expanded.

Would a simple, ugly hack like calling settings_var_expand() a second time be
sufficient to get my new % variable added here?

Charles Cazabon
GPL'ed software available at:               http://pyropus.ca/software/

More information about the dovecot mailing list