Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib-mail: Added message_search_more_get_decoded()
- Loading branch information
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (c) 2016 Dovecot authors, see the included COPYING file */ | ||
|
||
#include "lib.h" | ||
#include "str.h" | ||
#include "unichar.h" | ||
#include "message-parser.h" | ||
#include "message-search.h" | ||
#include "test-common.h" | ||
|
||
static void test_message_search_more_get_decoded(void) | ||
{ | ||
const char input[] = "p\xC3\xB6\xC3\xB6"; | ||
const unsigned char text_plain[] = "text/plain; charset=utf-8"; | ||
struct message_search_context *ctx1, *ctx2; | ||
struct message_block raw_block, decoded_block; | ||
struct message_header_line hdr; | ||
struct message_part part; | ||
unsigned int i; | ||
|
||
test_begin("message_search_more_get_decoded()"); | ||
|
||
ctx1 = message_search_init("p\xC3\xA4\xC3\xA4", NULL, 0); | ||
ctx2 = message_search_init("p\xC3\xB6\xC3\xB6", NULL, 0); | ||
|
||
memset(&raw_block, 0, sizeof(raw_block)); | ||
raw_block.part = ∂ | ||
|
||
/* feed the Content-Type header */ | ||
memset(&hdr, 0, sizeof(hdr)); | ||
hdr.name = "Content-Type"; hdr.name_len = strlen(hdr.name); | ||
hdr.value = hdr.full_value = text_plain; | ||
hdr.value_len = hdr.full_value_len = sizeof(text_plain)-1; | ||
raw_block.hdr = &hdr; | ||
test_assert(!message_search_more_get_decoded(ctx1, &raw_block, &decoded_block)); | ||
test_assert(!message_search_more_decoded(ctx2, &decoded_block)); | ||
|
||
/* EOH */ | ||
raw_block.hdr = NULL; | ||
test_assert(!message_search_more_get_decoded(ctx1, &raw_block, &decoded_block)); | ||
test_assert(!message_search_more_decoded(ctx2, &decoded_block)); | ||
|
||
/* body */ | ||
raw_block.size = 1; | ||
for (i = 0; input[i] != '\0'; i++) { | ||
raw_block.data = (const void *)&input[i]; | ||
test_assert(!message_search_more_get_decoded(ctx1, &raw_block, &decoded_block)); | ||
test_assert(message_search_more_decoded(ctx2, &decoded_block) == (input[i+1] == '\0')); | ||
} | ||
message_search_deinit(&ctx1); | ||
message_search_deinit(&ctx2); | ||
test_end(); | ||
} | ||
|
||
int main(void) | ||
{ | ||
static void (*test_functions[])(void) = { | ||
test_message_search_more_get_decoded, | ||
NULL | ||
}; | ||
return test_run(test_functions); | ||
} |