[Dovecot] Implementation of editheaders in dovecot

Konstantin Lepa konstantin.lepa at gmail.com
Mon Apr 6 15:18:42 EEST 2009


It's my code of message creation:

         chunks = t_new(struct istream *, max_chunks);
	chunks[cnt++] = header_filter(stream, &ra_mail->exclude_headers,  
exclude_cnt); /* calls i_stream_header_filter */
#if 0
         if (include_cnt) { /* calls i_stream_create_from_data  for my  
headers */
		chunks[cnt++] = create_header_stream(&ra_mail->include_headers,  
include_cnt);
	}
	chunks[cnt++] = create_stream_for_msgbody(stream); /* calls  
i_stream_create_limit  for message body */
#endif
	chunks[cnt++] = NULL;
         *stream_r = i_stream_create_concat(chunks);


if I enable the block of code, then header_filter_callback is called  
for message body only. Why?
I reviewed `i_stream_header_filter' and noticed, that it returns  
`i_stream_create(&mstream->istream, input, -1)' where `input' is  
parent stream. Maybe, is it reason of problem?

/************************************My  
header_filter_callback:************************************/
static void rarules_header_filter_callback(struct message_header_line  
* hdr,
                                            bool * matched, void *  
context)
{
         DPRINTF("Func `%s' is called", __FUNCTION__);

         if (hdr && hdr->eoh == TRUE) { *matched = FALSE; }
         else                                         { *matched =  
TRUE;  }

         if (hdr) { DPRINTF("#%s: %s", hdr->name, hdr->value); }
}

/***************************************** My header_filter:  
****************************************/
static struct istream *
header_filter(struct istream * stream, ARRAY_TYPE(const_string) *  
headers_arr,
                    unsigned int count)
{
         const char * const * headers = NULL;

         DPRINTF("Func `%s' is called", __FUNCTION__);

         if (count) { headers = (const char **)array_idx(headers_arr,  
0); }

         return i_stream_create_header_filter(stream,
                                              HEADER_FILTER_EXCLUDE |
                                              HEADER_FILTER_NO_CR |
                                              HEADER_FILTER_HIDE_BODY,
                                              headers,
                                              N_ELEMENTS(headers),
                                               
rarules_header_filter_callback,
                                              NULL);

}

On Apr 3, 2009, at 21:29 , Timo Sirainen wrote:

> On Fri, 2009-04-03 at 21:25 +0400, Konstantin Lepa wrote:
>> Yeah, but it doesn't work without i_stream_seek(stream, 0) before.
>>
>> How can I remove EOH after i_stream_create_header_filter (second
>> '\n')? Is it possible?
>
> You can give i_stream_create_header_filter() a callback function,  
> which
> gets called for each header line, and once for the EOH with hdr->eoh  
> ==
> TRUE. There you can set *matched = FALSE and it won't add the EOH.
>



More information about the dovecot mailing list