void message_search_reset(struct message_search_context *ctx) { /* Content-Type defaults to text/plain */ ctx->content_type_text = TRUE; ctx->prev_part = NULL; str_find_reset(ctx->str_find_ctx); message_decoder_decode_reset(ctx->decoder); }
static bool test_str_find_substring(const char *key, int expected_pos) { const unsigned char *text = (const unsigned char *)str_find_text; const unsigned int text_len = strlen(str_find_text); struct str_find_context *ctx; unsigned int i, j, pos, max, offset; bool ret; ctx = str_find_init(pool_datastack_create(), key); /* divide text into every possible block combination and test that it matches */ i_assert(text_len > 0); max = 1U << (text_len-1); for (i = 0; i < max; i++) { str_find_reset(ctx); pos = 0; offset = 0; ret = FALSE; for (j = 0; j < text_len; j++) { if ((i & (1 << j)) != 0) { if (str_find_more(ctx, text+pos, j-pos+1)) { ret = TRUE; break; } offset += j-pos + 1; pos = j + 1; } } if (pos != text_len && !ret) { if (str_find_more(ctx, text+pos, j-pos)) ret = TRUE; } if (expected_pos < 0) { if (ret) return FALSE; } else { if (!ret) return FALSE; pos = str_find_get_match_end_pos(ctx) + offset - strlen(key); if ((int)pos != expected_pos) return FALSE; } } return TRUE; }