Mercurial > dovecot > original-hg > dovecot-1.2
changeset 7242:8cfa61f98e32 HEAD
message_search_more*() now returns bool instead of int. They can't fail.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 14 Feb 2008 22:40:23 +0200 |
parents | a6c066f50877 |
children | 289765861d66 |
files | src/lib-mail/message-search.c src/lib-mail/message-search.h src/lib-storage/index/index-search.c |
diffstat | 3 files changed, 27 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-mail/message-search.c Thu Feb 14 22:34:39 2008 +0200 +++ b/src/lib-mail/message-search.c Thu Feb 14 22:40:23 2008 +0200 @@ -128,21 +128,21 @@ str_find_more(ctx->str_find_ctx, crlf, 2)); } -static int message_search_more_decoded2(struct message_search_context *ctx, - struct message_block *block) +static bool message_search_more_decoded2(struct message_search_context *ctx, + struct message_block *block) { if (block->hdr != NULL) { if (search_header(ctx, block->hdr)) - return 1; + return TRUE; } else { if (str_find_more(ctx->str_find_ctx, block->data, block->size)) - return 1; + return TRUE; } - return 0; + return FALSE; } -int message_search_more(struct message_search_context *ctx, - struct message_block *raw_block) +bool message_search_more(struct message_search_context *ctx, + struct message_block *raw_block) { struct message_header_line *hdr = raw_block->hdr; struct message_block block; @@ -161,31 +161,31 @@ but decoder needs some headers so that it can decode the body properly. */ if (hdr->name_len != 12 && hdr->name_len != 25) - return 0; + return FALSE; if (strcasecmp(hdr->name, "Content-Type") != 0 && strcasecmp(hdr->name, "Content-Transfer-Encoding") != 0) - return 0; + return FALSE; } } else { /* body */ if (!ctx->content_type_text) - return 0; + return FALSE; } if (!message_decoder_decode_next_block(ctx->decoder, raw_block, &block)) - return 0; + return FALSE; if (block.hdr != NULL && (ctx->flags & MESSAGE_SEARCH_FLAG_SKIP_HEADERS) != 0) { /* Content-* header */ - return 0; + return FALSE; } return message_search_more_decoded2(ctx, &block); } -int message_search_more_decoded(struct message_search_context *ctx, - struct message_block *block) +bool message_search_more_decoded(struct message_search_context *ctx, + struct message_block *block) { if (block->part != ctx->prev_part) { /* part changes */
--- a/src/lib-mail/message-search.h Thu Feb 14 22:34:39 2008 +0200 +++ b/src/lib-mail/message-search.h Thu Feb 14 22:40:23 2008 +0200 @@ -17,15 +17,15 @@ struct message_search_context **ctx_r); void message_search_deinit(struct message_search_context **ctx); -/* Returns 1 if key is found from input buffer, 0 if not and -1 if error - occurred */ -int message_search_more(struct message_search_context *ctx, - struct message_block *raw_block); +/* Returns TRUE if key is found from input buffer, FALSE if not. */ +bool message_search_more(struct message_search_context *ctx, + struct message_block *raw_block); /* The data has already passed through decoder. */ -int message_search_more_decoded(struct message_search_context *ctx, - struct message_block *block); +bool message_search_more_decoded(struct message_search_context *ctx, + struct message_block *block); void message_search_reset(struct message_search_context *ctx); -/* Search a full message. */ +/* Search a full message. Returns 1 if match was found, 0 if not, + -1 if error (if stream_error == 0, the parts contained broken data) */ int message_search_msg(struct message_search_context *ctx, struct istream *input, const struct message_part *parts);
--- a/src/lib-storage/index/index-search.c Thu Feb 14 22:34:39 2008 +0200 +++ b/src/lib-storage/index/index-search.c Thu Feb 14 22:40:23 2008 +0200 @@ -330,6 +330,7 @@ struct message_block block; struct message_header_line hdr; int ret; + bool match; /* first check that the field name matches to argument. */ switch (arg->type) { @@ -374,7 +375,7 @@ memset(&block, 0, sizeof(block)); msg_search_ctx = msg_search_arg_context(ctx->index_context, arg); if (msg_search_ctx == NULL) - ret = 0; + match = FALSE; else if (arg->type == SEARCH_HEADER_ADDRESS) { /* we have to match against normalized address */ T_BEGIN { @@ -391,17 +392,18 @@ hdr.value = hdr.full_value = str_data(str); hdr.value_len = hdr.full_value_len = str_len(str); block.hdr = &hdr; - ret = message_search_more(msg_search_ctx, &block); + match = message_search_more(msg_search_ctx, &block); } T_END; } else { block.hdr = ctx->hdr; - ret = message_search_more(msg_search_ctx, &block); + match = message_search_more(msg_search_ctx, &block); } - if (ret > 0 || + if (match || (arg->type != SEARCH_HEADER && arg->type != SEARCH_HEADER_ADDRESS)) { /* set only when we definitely know if it's a match */ + ret = match ? 1 : 0; ARG_SET_RESULT(arg, ret); } }