Skip to content

Commit

Permalink
lib-mail: istream-header-filter: Fixed stat() with HEADER_FILTER_HIDE…
Browse files Browse the repository at this point in the history
…_BODY
  • Loading branch information
sirainen committed May 11, 2016
1 parent 9a26f96 commit 8047bd3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib-mail/istream-header-filter.c
Expand Up @@ -558,7 +558,10 @@ i_stream_header_filter_stat(struct istream_private *stream, bool exact)
if (skip_header(mstream) < 0)
return -1;

if (!mstream->end_body_with_lf) {
if (mstream->hide_body) {
/* no body */
stream->statbuf.st_size = mstream->header_size.physical_size;
} else if (!mstream->end_body_with_lf) {
/* no last-LF */
} else if (mstream->last_lf_added) {
/* yes, we have added LF */
Expand Down
37 changes: 37 additions & 0 deletions src/lib-mail/test-istream-header-filter.c
Expand Up @@ -385,6 +385,42 @@ static void test_istream_add_missing_eoh(void)
test_end();
}

static void test_istream_hide_body(void)
{
struct {
const char *input;
const char *output;
int extra;
} tests[] = {
{ "From: foo", "From: foo", 0 },
{ "From: foo\n", "From: foo\n", 0 },
{ "From: foo\n\n", "From: foo\n\n", 1 },
{ "From: foo\n\nbar", "From: foo\n\n", -2 },
{ "From: foo\r\n", "From: foo\r\n", 0 },
{ "From: foo\r\n\r\n", "From: foo\r\n\r\n", 0 },
{ "From: foo\r\n\r\nbar", "From: foo\r\n\r\n", -3 }
};
struct istream *istream, *filter;
unsigned int i;

test_begin("i_stream_create_header_filter(add_missing_eoh)");
for (i = 0; i < N_ELEMENTS(tests); i++) {
istream = test_istream_create(tests[i].input);
filter = i_stream_create_header_filter(istream,
HEADER_FILTER_EXCLUDE |
HEADER_FILTER_CRLF_PRESERVE |
HEADER_FILTER_HIDE_BODY,
NULL, 0,
*null_header_filter_callback, (void *)NULL);
test_istream_run(istream, filter,
strlen(tests[i].input) + tests[i].extra,
tests[i].output);
i_stream_unref(&filter);
i_stream_unref(&istream);
}
test_end();
}

static void ATTR_NULL(3)
strip_eoh_callback(struct header_filter_istream *input ATTR_UNUSED,
struct message_header_line *hdr,
Expand Down Expand Up @@ -421,6 +457,7 @@ int main(void)
test_istream_edit,
test_istream_add_missing_eoh,
test_istream_end_body_with_lf,
test_istream_hide_body,
test_istream_strip_eoh,
NULL
};
Expand Down

0 comments on commit 8047bd3

Please sign in to comment.