[Dovecot] Order of istream and ostream chains

Philipp Brüll philippbruell at gmail.com
Tue Feb 11 17:27:59 UTC 2014


Hi,

I'm creating a scrambler plugin, that adds an istream and an ostream to 
the stream-chain for the mail input/output. It works well until the zlib 
plugin is added to the configuration. The scrambler should run before 
the zlib and encrypt the mail before it's compressed. Since, the plugin 
is named lib18_scrambler_... (and the other lib20_zlib....), that works 
well when a mail is received.

When a mail is read via IMAP, the plugins should handle the mail in the 
reverse order. So first, the zlib should decompress it and afterwards 
the scrambler should decrypt it.

But it seems, that they work the other way around. The scrambler istream 
gets compressed data as input. It's hooked in the chain of istream as 
the following...

static int scrambler_istream_opened(struct mail *_mail, struct istream 
**stream) {
     struct mail_private *mail = (struct mail_private *)_mail;
     union mail_module_context *mmail = SCRAMBLER_MAIL_CONTEXT(mail);
     struct istream *input, *inputs[2];

     input = *stream;
     *stream = scrambler_istream_create(input);
     i_stream_unref(&input);

     return mmail->super.istream_opened(_mail, stream);
}

static void scrambler_mail_allocated(struct mail *_mail) {
	struct mail_private *mail = (struct mail_private *)_mail;
	struct mail_vfuncs *v = mail->vlast;
	union mail_module_context *mmail;

	mmail = p_new(mail->pool, union mail_module_context, 1);
	mmail->super = *v;
	mail->vlast = &mmail->super;

	v->istream_opened = scrambler_istream_opened;

	MODULE_CONTEXT_SET_SELF(mail, scrambler_mail_module, mmail);
}

How can I reverse the order of istreams? Should I use another hook or vfuns?

I'm stuck in the problem for a while now, so any help would be very welcome.

Best regards,
Philipp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4261 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://dovecot.org/pipermail/dovecot/attachments/20140211/9284d066/attachment-0001.p7s>


More information about the dovecot mailing list