Skip to content

Commit

Permalink
lib-mail: istream-header-filter - fixed adding headers at eoh
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed May 3, 2016
1 parent 32e3da4 commit bf5682e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib-mail/istream-header-filter.c
Expand Up @@ -199,7 +199,7 @@ static ssize_t read_header(struct header_filter_istream *mstream)
if (hdr->eoh) {
mstream->seen_eoh = TRUE;
matched = TRUE;
if (mstream->header_parsed) {
if (mstream->header_parsed && !mstream->headers_edited) {
if (mstream->eoh_not_matched)
matched = !matched;
} else if (mstream->callback != NULL) {
Expand Down
11 changes: 9 additions & 2 deletions src/lib-mail/test-istream-header-filter.c
Expand Up @@ -260,7 +260,14 @@ edit_callback(struct header_filter_istream *input,
struct message_header_line *hdr,
bool *matched, void *context ATTR_UNUSED)
{
if (hdr != NULL && strcasecmp(hdr->name, "To") == 0) {
if (hdr == NULL)
return;
if (hdr->eoh) {
/* add a new header */
const char *new_hdr = "Added: header\n\n";
i_stream_header_filter_add(input, new_hdr, strlen(new_hdr));
*matched = FALSE;
} else if (strcasecmp(hdr->name, "To") == 0) {
/* modify To header */
const char *new_to = "To: 123\n";
*matched = TRUE;
Expand All @@ -271,7 +278,7 @@ edit_callback(struct header_filter_istream *input,
static void test_istream_edit(void)
{
const char *input = "From: foo\nTo: bar\n\nhello world\n";
const char *output = "From: foo\nTo: 123\n\nhello world\n";
const char *output = "From: foo\nTo: 123\nAdded: header\n\nhello world\n";
struct istream *istream, *filter;

test_begin("i_stream_create_header_filter(edit)");
Expand Down

0 comments on commit bf5682e

Please sign in to comment.