dovecot-1.1: message_search_more*() now returns bool instead of ...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Feb 14 22:43:27 EET 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/8cfa61f98e32
changeset: 7242:8cfa61f98e32
user: Timo Sirainen <tss at iki.fi>
date: Thu Feb 14 22:40:23 2008 +0200
description:
message_search_more*() now returns bool instead of int. They can't fail.
diffstat:
3 files changed, 32 insertions(+), 30 deletions(-)
src/lib-mail/message-search.c | 34 +++++++++++++++++-----------------
src/lib-mail/message-search.h | 14 +++++++-------
src/lib-storage/index/index-search.c | 14 ++++++++------
diffs (144 lines):
diff -r a6c066f50877 -r 8cfa61f98e32 src/lib-mail/message-search.c
--- 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 @@ static bool search_header(struct message
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 0;
-}
-
-int message_search_more(struct message_search_context *ctx,
- struct message_block *raw_block)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+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 @@ int message_search_more(struct message_s
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 */
diff -r a6c066f50877 -r 8cfa61f98e32 src/lib-mail/message-search.h
--- 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 @@ int message_search_init(pool_t pool, con
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);
diff -r a6c066f50877 -r 8cfa61f98e32 src/lib-storage/index/index-search.c
--- 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 @@ static void search_header_arg(struct mai
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 @@ static void search_header_arg(struct mai
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 @@ static void search_header_arg(struct mai
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);
- }
-
- if (ret > 0 ||
+ match = message_search_more(msg_search_ctx, &block);
+ }
+
+ 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);
}
}
More information about the dovecot-cvs
mailing list