[dovecot-cvs] dovecot/src/lib-mail Makefile.am, 1.16, 1.17 message-body-search.c, 1.36, NONE message-body-search.h, 1.11, NONE message-header-search.c, 1.21, NONE message-header-search.h, 1.7, NONE message-search.c, NONE, 1.1 message-search.h, NONE, 1.1
tss at dovecot.org
tss at dovecot.org
Wed Apr 4 13:16:42 EEST 2007
Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv26842/lib-mail
Modified Files:
Makefile.am
Added Files:
message-search.c message-search.h
Removed Files:
message-body-search.c message-body-search.h
message-header-search.c message-header-search.h
Log Message:
Removed message body/header searchers. They're now combined into one
message-search.
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/Makefile.am,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Makefile.am 22 Feb 2007 21:51:02 -0000 1.16
+++ Makefile.am 4 Apr 2007 10:16:38 -0000 1.17
@@ -7,16 +7,15 @@
libmail_a_SOURCES = \
istream-header-filter.c \
message-address.c \
- message-body-search.c \
message-content-parser.c \
message-date.c \
message-decoder.c \
message-header-decode.c \
message-header-parser.c \
- message-header-search.c \
message-id.c \
message-parser.c \
message-part-serialize.c \
+ message-search.c \
message-send.c \
message-size.c \
quoted-printable.c \
@@ -26,16 +25,15 @@
istream-header-filter.h \
mail-types.h \
message-address.h \
- message-body-search.h \
message-content-parser.h \
message-date.h \
message-decoder.h \
message-header-decode.h \
message-header-parser.h \
- message-header-search.h \
message-id.h \
message-parser.h \
message-part-serialize.h \
+ message-search.a \
message-send.h \
message-size.h \
quoted-printable.h \
--- message-body-search.c DELETED ---
--- message-body-search.h DELETED ---
--- message-header-search.c DELETED ---
--- message-header-search.h DELETED ---
--- NEW FILE: message-search.c ---
/* Copyright (C) 2002-2007 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "istream.h"
#include "str-find.h"
#include "charset-utf8.h"
#include "message-decoder.h"
#include "message-parser.h"
#include "message-content-parser.h"
#include "message-search.h"
struct message_search_context {
pool_t pool;
char *key;
char *key_charset;
unsigned int key_len;
enum message_search_flags flags;
struct str_find_context *str_find_ctx;
struct message_part *prev_part;
struct message_decoder_context *decoder;
unsigned int content_type_text:1; /* text/any or message/any */
};
static void parse_content_type(const unsigned char *value, size_t value_len,
void *context)
{
struct message_search_context *ctx = context;
const char *str;
t_push();
str = t_strndup(value, value_len);
ctx->content_type_text =
strncasecmp(str, "text/", 5) == 0 ||
strncasecmp(str, "message/", 8) == 0;
t_pop();
}
int message_search_init(pool_t pool, const char *key, const char *charset,
enum message_search_flags flags,
struct message_search_context **ctx_r)
{
struct message_search_context *ctx;
bool unknown_charset;
size_t key_len;
/* get the key uppercased */
t_push();
key = charset_to_ucase_utf8_string(charset, &unknown_charset,
(const unsigned char *)key,
strlen(key), &key_len);
if (key == NULL) {
t_pop();
return unknown_charset ? 0 : -1;
}
ctx = *ctx_r = p_new(pool, struct message_search_context, 1);
ctx->pool = pool;
ctx->key = p_strdup(pool, key);
ctx->key_len = key_len;
ctx->key_charset = p_strdup(pool, charset);
ctx->flags = flags;
ctx->decoder = message_decoder_init_ucase();
ctx->str_find_ctx = str_find_init(pool, ctx->key);
t_pop();
return 1;
}
void message_search_deinit(struct message_search_context **_ctx)
{
struct message_search_context *ctx = *_ctx;
*_ctx = NULL;
str_find_deinit(&ctx->str_find_ctx);
message_decoder_deinit(&ctx->decoder);
p_free(ctx->pool, ctx->key);
p_free(ctx->pool, ctx->key_charset);
p_free(ctx->pool, ctx);
}
static void handle_header(struct message_search_context *ctx,
struct message_header_line *hdr)
{
if (hdr->name_len == 12 &&
strcasecmp(hdr->name, "Content-Type") == 0) {
if (hdr->continues) {
hdr->use_full_value = TRUE;
return;
}
message_content_parse_header(hdr->full_value,
hdr->full_value_len,
parse_content_type, NULL, ctx);
}
}
static bool search_header(struct message_search_context *ctx,
const struct message_header_line *hdr)
{
return str_find_more(ctx->str_find_ctx,
(const unsigned char *)hdr->name, hdr->name_len) ||
str_find_more(ctx->str_find_ctx,
hdr->middle, hdr->middle_len) ||
str_find_more(ctx->str_find_ctx, hdr->full_value,
hdr->full_value_len);
}
int message_search_more(struct message_search_context *ctx,
struct message_block *raw_block)
{
struct message_block block;
if (raw_block->hdr != NULL) {
if (ctx->flags & MESSAGE_SEARCH_FLAG_SKIP_HEADERS)
return 0;
handle_header(ctx, raw_block->hdr);
} else {
/* body */
if (!ctx->content_type_text)
return 0;
}
if (!message_decoder_decode_next_block(ctx->decoder, raw_block, &block))
return 0;
return message_search_more_decoded(ctx, &block);
}
int message_search_more_decoded(struct message_search_context *ctx,
struct message_block *block)
{
if (block->part != ctx->prev_part) {
/* part changes */
message_search_reset(ctx);
ctx->prev_part = block->part;
}
if (block->hdr != NULL) {
if (search_header(ctx, block->hdr))
return 1;
} else {
if (str_find_more(ctx->str_find_ctx, block->data, block->size))
return 1;
}
return 0;
}
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);
}
int message_search_msg(struct message_search_context *ctx,
struct istream *input, const struct message_part *parts)
{
const enum message_header_parser_flags hdr_parser_flags =
MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE;
struct message_parser_ctx *parser_ctx;
struct message_block raw_block;
int ret = 0;
t_push();
message_search_reset(ctx);
if (parts != NULL) {
parser_ctx = message_parser_init_from_parts(
(struct message_part *)parts,
input, hdr_parser_flags, 0);
} else {
parser_ctx = message_parser_init(pool_datastack_create(),
input, hdr_parser_flags, 0);
}
while ((ret = message_parser_parse_next_block(parser_ctx,
&raw_block)) > 0) {
if ((ret = message_search_more(ctx, &raw_block)) != 0)
break;
}
i_assert(ret != 0);
if (ret < 0 && input->stream_errno == 0)
ret = 0;
(void)message_parser_deinit(&parser_ctx);
t_pop();
return ret;
}
--- NEW FILE: message-search.h ---
#ifndef __MESSAGE_SEARCH_H
#define __MESSAGE_SEARCH_H
struct message_block;
struct message_part;
struct message_search_context;
enum message_search_flags {
/* Skip the main header and all the MIME headers. */
MESSAGE_SEARCH_FLAG_SKIP_HEADERS = 0x01
};
/* Returns 1 if ok, 0 if unknown charset, -1 if key contains invalid characters
in given charset. */
int message_search_init(pool_t pool, const char *key, const char *charset,
enum message_search_flags flags,
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);
/* The data has already passed through decoder. */
int 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. */
int message_search_msg(struct message_search_context *ctx,
struct istream *input, const struct message_part *parts);
#endif
More information about the dovecot-cvs
mailing list