Alex Baule
2011-Oct-31 15:25 UTC
[Dovecot] Rewrite the ostream output method, to save messages in another directory.
Hi Timo, I Trying to integrate my antispam with dovecot, using the imap folder to do certain actions. I Do almost every thing, but i have some problems saving the message. Explaining this function, i try to use a imap folder like a "collector folder", the user append a message from outside (ie another imap or pop message) to this folder, and i don't want to copy this message, i need to redirect it to another folder outside from user's maildir. Well, i try to base it in zlib plugin, with was the o_stream_create_gz(). Inside the o_stream_create_gz has the Output, it's a copy from the original output. I Try to replace this output, with another one, that i try to create to another location, without sucessfull. struct ostream * o_stream_create_X_list(struct ostream *output, struct istream *input, const char *type) { struct emexis_ostream *X_stream; struct ostream *new_output; int fd; fd = open("/tmp/email",O_WRONLY); new_output = o_stream_create_fd_file(fd, 0, TRUE); o_stream_cork(new_output); emexis_stream = i_new(struct emexis_ostream, 1); emexis_stream->ostream.sendv = o_stream_X_sendv; emexis_stream->ostream.flush = o_stream_X_flush; emexis_stream->ostream.iostream.close = o_stream_X_close; emexis_stream->output = new_output; emexis_stream->input = input; o_stream_ref(new_output); return o_stream_create(&X_stream->ostream); } With this new o_stream, i got this error. Oct 27 15:14:24 brc dovecot: imap(alex at exemplo.com.br): Error: o_stream_send_istream(/storage/gss/emexis/messages/ exemplo.com.br/alex/Maildir/.Emexis.Ext-Blacklist/tmp/1319735664.M568409P30815.brc) failed: Bad file descriptor Oct 27 15:14:24 brc dovecot: imap(alex at exemplo.com.br): Error: o_stream_flush(/storage/gss/emexis/messages/ exemplo.com.br/alex/Maildir/.Emexis.Ext-Blacklist/tmp/1319735664.M568409P30815.brc) failed: Bad file descriptor Oct 27 15:14:24 brc dovecot: imap(alex at exemplo.com.br): Error: write(/storage/gss/emexis/messages/ exemplo.com.br/alex/Maildir/.Emexis.Ext-Blacklist/tmp/1319735664.M568409P30815.brc) failed: Bad file descriptor There is something wrong Timo ? Like missing something or i need to rewrite another funcion ? Tks !!!
Timo Sirainen
2011-Nov-04 21:47 UTC
[Dovecot] Rewrite the ostream output method, to save messages in another directory.
On Mon, 2011-10-31 at 13:25 -0200, Alex Baule wrote:> struct ostream * > o_stream_create_X_list(struct ostream *output, struct istream *input, const > char *type) > { > struct emexis_ostream *X_stream; > struct ostream *new_output; > int fd; > > fd = open("/tmp/email",O_WRONLY); > > new_output = o_stream_create_fd_file(fd, 0, TRUE); > o_stream_cork(new_output); > > emexis_stream = i_new(struct emexis_ostream, 1); > emexis_stream->ostream.sendv = o_stream_X_sendv; > emexis_stream->ostream.flush = o_stream_X_flush; > emexis_stream->ostream.iostream.close = o_stream_X_close; > emexis_stream->output = new_output; > emexis_stream->input = input; > > o_stream_ref(new_output); > > return o_stream_create(&X_stream->ostream); > }This part of the code looks ok.> With this new o_stream, i got this error. > > Oct 27 15:14:24 brc dovecot: imap(alex at exemplo.com.br): Error: > o_stream_send_istream(/storage/gss/emexis/messages/ > exemplo.com.br/alex/Maildir/.Emexis.Ext-Blacklist/tmp/1319735664.M568409P30815.brc) > failed: Bad file descriptorI guess this should call your o_stream_X_sendv(). What do you do in that? I guess you're calling o_stream_sendv() for the new_output stream? Check if it returns -1, if it does then you're somehow breaking the new_output. Maybe you're closing it too early? Try what happens if you create it with: new_output = o_stream_create_fd_file(fd, 0, FALSE); Then it doesn't automatically close the fd, and it's at least clearer if the problem is because the stream is closed too early or if some completely wrong fd is attempted to be used.> There is something wrong Timo ? Like missing something or i need to rewrite > another funcion ?Nope. I think this is completely internal to your code.