[Dovecot] understand the struct message_header_line
Timo...
Using the src/lib-mail/test-istream-header-filter.c as example, and following your tips to jump my desired header value, but i need to store the value from the Header filtered.
In the Exemple, the callback is this:
static void filter_callback(struct message_header_line *hdr, bool *matched, void *context ATTR_UNUSED) { if (hdr != NULL && hdr->name_offset == 0) { /* drop first header */ *matched = TRUE; } }
What i try to understand is how the structs work, it's save the entire header or every line from header call the callback function ?
hdr->name_offset is the size of elements in the struct ? (like a array of message_header_line)
The void *context ATTR_UNUSED i can pass what i want to change ? like a pointer to a variable ?
On Tue, 2010-09-21 at 15:07 -0300, Alex Baule wrote:
static void filter_callback(struct message_header_line *hdr, bool *matched, void *context ATTR_UNUSED) .. What i try to understand is how the structs work, it's save the entire header or every line from header call the callback function ?
The function is called once for each header field and depending on *matched value after the call it's either filtered out or not.
hdr->name_offset is the size of elements in the struct ? (like a array of message_header_line)
I don't really know what name_offset contains in this case, probably nothing useful, don't use it. hdr->name, hdr->value and hdr->value_len are the only things you should need.
The void *context ATTR_UNUSED i can pass what i want to change ? like a pointer to a variable ?
The context pointer contains the same pointer you gave to i_stream_create_header_filter(). So for example you could do something like:
char *value = NULL;
i_stream_create_header_filter(..., &value);
static void filter_callback(struct message_header_line *hdr, bool *matched, void *context) { char **value = context; if (strcmp(hdr, "yourheader") == 0 && *value == NULL) *value = i_strndup(hdr->value, hdr->value_len); }
participants (2)
-
Alex Baule
-
Timo Sirainen