[Dovecot] Plugin

Timo Sirainen tss at iki.fi
Wed Jan 20 20:54:27 EET 2010


On 20.1.2010, at 20.45, Alex Baule wrote:

> Timo Sirainen send to me this modification, in
> src/lib-storage/index/maildir/maildir-mail.c
> 
> struct istream *full_input[3];
> full_input[0] = i_stream_create_fd(fd, 0, TRUE);
> full_input[1] = i_stream_create_fd(fd1, 0, TRUE);
> full_input[2] = NULL;
> input = i_stream_create_concat(full_
> input);
> 
> This is necessary because my Header and Body is splited.
> This modification works fine.
> 
> My question is:
> 
> There is a way to do this with a plugin ?
> I dont know how to implement this in a plugin, because i dont know what is
> the hook to change the maildir_open_mail functions. (this is the function
> with the modification above) .

It's similar to how zlib plugin does its work. You need to copy&paste enough code from it, so that you'll get to

static int zlib_maildir_get_stream(struct mail *_mail,

The important part of the code below it that replaces the maildir's istream is:

                imail->data.destroying_stream = TRUE;
                i_stream_unref(&imail->data.stream);
                i_assert(!imail->data.destroying_stream);

                if (fd == -1)
                        return -1;
                imail->data.stream = handler->create_istream(fd);

So instead of handler->create_istream(fd), you'll use your own. Or actually IIRC you didn't even want to destroy the original stream, so instead of any of the above, you'd probably do something like:

old_stream = imail->data.stream;
imail->data.stream = create_your_stream(old_stream);
i_stream_unref(&old_stream);

> Another question is: There is a seek function, in dovecot, and in zlib
> plugin, it is rewrite by another function, that use the "gzseek" to do the
> seek. My splited body will be encrypted, and the crypto no have seek,
> because the message will be encrypted. (if i open the message, decrypt and
> seek to some position, maybe work).
> 
> The seek function is really necessary to IMAP and maildir ?

Well, gzseek() doesn't work any easier. It can't directly jump to wanted position. When seeking forwards, it'll just read and uncompress data until it reaches the wanted offset. When seeking backwards, it'll go back to beginning and start reading and uncompressing from there. That's why there's the "marked" code in istream-zlib that tries to 
avoid the backwards seeks. You could maybe use something like that too, but you could also put the whole thing through i_stream_create_seekable() and Dovecot just keeps the whole message in memory (by setting max_buffer_size=(size_t)-1).


More information about the dovecot mailing list