1
/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
1
/* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
7
7
#include "str-find.h"
8
#include "charset-utf8.h"
9
8
#include "rfc822-parser.h"
10
9
#include "message-decoder.h"
11
10
#include "message-parser.h"
12
11
#include "message-search.h"
14
13
struct message_search_context {
19
14
enum message_search_flags flags;
20
15
struct str_find_context *str_find_ctx;
21
16
struct message_part *prev_part;
24
19
unsigned int content_type_text:1; /* text/any or message/any */
28
message_search_init_real(const char *key, const char *charset,
29
enum message_search_flags flags,
30
struct message_search_context **ctx_r)
22
struct message_search_context *
23
message_search_init(const char *key_utf8,
24
enum message_search_flags flags)
26
enum message_decoder_flags decoder_flags = 0;
32
27
struct message_search_context *ctx;
34
enum charset_result result;
37
key_utf8 = t_str_new(128);
38
if (charset_to_utf8_str(charset, CHARSET_FLAG_DECOMP_TITLECASE,
39
key, key_utf8, &result) < 0)
41
else if (result != CHARSET_RET_OK)
44
ctx = *ctx_r = i_new(struct message_search_context, 1);
45
ctx->key = i_strdup(str_c(key_utf8));
46
ctx->key_len = str_len(key_utf8);
47
ctx->key_charset = i_strdup(charset);
49
ctx->decoder = message_decoder_init(MESSAGE_DECODER_FLAG_DTCASE);
50
ctx->str_find_ctx = str_find_init(default_pool, ctx->key);
56
int message_search_init(const char *key, const char *charset,
57
enum message_search_flags flags,
58
struct message_search_context **ctx_r)
63
ret = message_search_init_real(key, charset, flags, ctx_r);
29
i_assert(*key_utf8 != '\0');
31
if ((flags & MESSAGE_SEARCH_FLAG_DTCASE) != 0)
32
decoder_flags |= MESSAGE_DECODER_FLAG_DTCASE;
34
ctx = i_new(struct message_search_context, 1);
36
ctx->decoder = message_decoder_init(decoder_flags);
37
ctx->str_find_ctx = str_find_init(default_pool, key_utf8);
68
41
void message_search_deinit(struct message_search_context **_ctx)