mail-thread.c \
mail-user.c \
mailbox-get.c \
+ mailbox-header.c \
mailbox-keywords.c \
mailbox-list.c \
mailbox-search-result.c \
index_transaction_rollback,
NULL,
index_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
index_transaction_rollback,
NULL,
dbox_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
index_transaction_rollback,
NULL,
dbox_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
#include "index-storage.h"
#include "index-mail.h"
-#include <stdlib.h>
-
-struct index_header_lookup_ctx {
- struct mailbox_header_lookup_ctx ctx;
- pool_t pool;
-
- unsigned int count;
- unsigned int *idx;
- const char **name;
-};
-
static const enum message_header_parser_flags hdr_parser_flags =
MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP |
MESSAGE_HEADER_PARSER_FLAG_DROP_CR;
}
void index_mail_parse_header_init(struct index_mail *mail,
- struct mailbox_header_lookup_ctx *_headers)
+ struct mailbox_header_lookup_ctx *headers)
{
- struct index_header_lookup_ctx *headers =
- (struct index_header_lookup_ctx *)_headers;
const uint8_t *match;
unsigned int i, field_idx, match_count;
}
int index_mail_get_header_stream(struct mail *_mail,
- struct mailbox_header_lookup_ctx *_headers,
+ struct mailbox_header_lookup_ctx *headers,
struct istream **stream_r)
{
struct index_mail *mail = (struct index_mail *)_mail;
- struct index_header_lookup_ctx *headers =
- (struct index_header_lookup_ctx *)_headers;
struct istream *input;
string_t *dest;
- i_assert(_headers->box == _mail->box);
+ i_assert(headers->box == _mail->box);
if (mail->data.save_bodystructure_header) {
/* we have to parse the header. */
- if (index_mail_parse_headers(mail, _headers) < 0)
+ if (index_mail_parse_headers(mail, headers) < 0)
return -1;
}
if (mail->data.filter_stream != NULL)
i_stream_destroy(&mail->data.filter_stream);
- index_mail_parse_header_init(mail, _headers);
+ index_mail_parse_header_init(mail, headers);
mail->data.filter_stream =
i_stream_create_header_filter(mail->data.stream,
HEADER_FILTER_INCLUDE |
*stream_r = mail->data.filter_stream;
return 0;
}
-
-static struct mailbox_header_lookup_ctx *
-index_header_lookup_init_real(struct mailbox *box, const char *const headers[])
-{
- struct mail_cache_field *fields, header_field = {
- NULL, 0, MAIL_CACHE_FIELD_HEADER, 0,
- MAIL_CACHE_DECISION_TEMP
- };
- struct index_header_lookup_ctx *ctx;
- const char *const *name;
- const char **sorted_headers;
- pool_t pool;
- unsigned int i, count;
-
- i_assert(*headers != NULL);
-
- for (count = 0, name = headers; *name != NULL; name++)
- count++;
-
- /* @UNSAFE: headers need to be sorted for filter stream. */
- sorted_headers = t_new(const char *, count);
- memcpy(sorted_headers, headers, count * sizeof(*sorted_headers));
- qsort(sorted_headers, count, sizeof(*sorted_headers), i_strcasecmp_p);
- headers = sorted_headers;
-
- /* @UNSAFE */
- fields = t_new(struct mail_cache_field, count);
- for (i = 0; i < count; i++) {
- header_field.name = t_strconcat("hdr.", headers[i], NULL);
- fields[i] = header_field;
- }
- mail_cache_register_fields(box->cache, fields, count);
-
- pool = pool_alloconly_create("index_header_lookup_ctx", 1024);
- ctx = p_new(pool, struct index_header_lookup_ctx, 1);
- ctx->ctx.box = box;
- ctx->ctx.refcount = 1;
- ctx->pool = pool;
- ctx->count = count;
-
- ctx->idx = p_new(pool, unsigned int, count);
- ctx->name = p_new(pool, const char *, count + 1);
-
- /* @UNSAFE */
- for (i = 0; i < count; i++) {
- ctx->idx[i] = fields[i].idx;
- ctx->name[i] = p_strdup(pool, headers[i]);
- }
- ctx->ctx.headers = ctx->name;
- return &ctx->ctx;
-}
-
-struct mailbox_header_lookup_ctx *
-index_header_lookup_init(struct mailbox *box, const char *const headers[])
-{
- struct mailbox_header_lookup_ctx *ctx;
-
- T_BEGIN {
- ctx = index_header_lookup_init_real(box, headers);
- } T_END;
- return ctx;
-}
-
-void index_header_lookup_deinit(struct mailbox_header_lookup_ctx *_ctx)
-{
- struct index_header_lookup_ctx *ctx =
- (struct index_header_lookup_ctx *)_ctx;
-
- pool_unref(&ctx->pool);
-}
void index_mail_init(struct index_mail *mail,
struct mailbox_transaction_context *t,
enum mail_fetch_field wanted_fields,
- struct mailbox_header_lookup_ctx *_wanted_headers)
+ struct mailbox_header_lookup_ctx *wanted_headers)
{
- struct index_header_lookup_ctx *wanted_headers =
- (struct index_header_lookup_ctx *)_wanted_headers;
const struct mail_index_header *hdr;
array_create(&mail->mail.module_contexts, mail->mail.pool,
mail->mail.mail.box = t->box;
mail->mail.mail.transaction = t;
mail->mail.wanted_fields = wanted_fields;
- mail->mail.wanted_headers = _wanted_headers;
+ mail->mail.wanted_headers = wanted_headers;
hdr = mail_index_get_header(t->box->view);
mail->uid_validity = hdr->uid_validity;
mail->wanted_fields = wanted_fields;
if (wanted_headers != NULL) {
mail->wanted_headers = wanted_headers;
- mailbox_header_lookup_ref(_wanted_headers);
+ mailbox_header_lookup_ref(wanted_headers);
}
}
uint32_t uid_validity;
enum mail_fetch_field wanted_fields;
- struct index_header_lookup_ctx *wanted_headers;
+ struct mailbox_header_lookup_ctx *wanted_headers;
int pop3_state;
enum mailbox_status_items items,
struct mailbox_status *status_r);
-struct mailbox_header_lookup_ctx *
-index_header_lookup_init(struct mailbox *box, const char *const headers[]);
-void index_header_lookup_deinit(struct mailbox_header_lookup_ctx *ctx);
-
struct mail_search_context *
index_storage_search_init(struct mailbox_transaction_context *t,
struct mail_search_args *args,
index_transaction_rollback,
maildir_get_private_flags_mask,
index_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
mbox_transaction_rollback,
NULL,
index_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
index_transaction_rollback,
NULL,
index_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
index_storage_search_init,
index_storage_search_deinit,
index_storage_search_next_nonblock,
enum mail_fetch_field wanted_fields,
struct mailbox_header_lookup_ctx *wanted_headers);
- struct mailbox_header_lookup_ctx *
- (*header_lookup_init)(struct mailbox *box,
- const char *const headers[]);
- void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx);
-
struct mail_search_context *
(*search_init)(struct mailbox_transaction_context *t,
struct mail_search_args *args,
struct mailbox_header_lookup_ctx {
struct mailbox *box;
- const char *const *headers;
+ pool_t pool;
int refcount;
+
+ unsigned int count;
+ const char *const *name;
+ unsigned int *idx;
};
/* Modules should use do "my_id = mail_storage_module_id++" and
mailbox_notify_changes(box, 0, NULL, NULL);
}
-struct mailbox_header_lookup_ctx *
-mailbox_header_lookup_init(struct mailbox *box, const char *const headers[])
-{
- return box->v.header_lookup_init(box, headers);
-}
-
-void mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx)
-{
- i_assert(ctx->refcount > 0);
- ctx->refcount++;
-}
-
-void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **_ctx)
-{
- struct mailbox_header_lookup_ctx *ctx = *_ctx;
-
- *_ctx = NULL;
-
- i_assert(ctx->refcount > 0);
- if (--ctx->refcount > 0)
- return;
-
- ctx->box->v.header_lookup_deinit(ctx);
-}
-
struct mail_search_context *
mailbox_search_init(struct mailbox_transaction_context *t,
struct mail_search_args *args,
--- /dev/null
+/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "mail-cache.h"
+#include "mail-storage-private.h"
+
+#include <stdlib.h>
+
+static struct mailbox_header_lookup_ctx *
+mailbox_header_lookup_init_real(struct mailbox *box,
+ const char *const headers[])
+{
+ struct mail_cache_field *fields, header_field = {
+ NULL, 0, MAIL_CACHE_FIELD_HEADER, 0,
+ MAIL_CACHE_DECISION_TEMP
+ };
+ struct mailbox_header_lookup_ctx *ctx;
+ const char *const *name;
+ const char **sorted_headers, **dest_name;
+ pool_t pool;
+ unsigned int i, count;
+
+ i_assert(*headers != NULL);
+
+ for (count = 0, name = headers; *name != NULL; name++)
+ count++;
+
+ /* @UNSAFE: headers need to be sorted for filter stream. */
+ sorted_headers = t_new(const char *, count);
+ memcpy(sorted_headers, headers, count * sizeof(*sorted_headers));
+ qsort(sorted_headers, count, sizeof(*sorted_headers), i_strcasecmp_p);
+ headers = sorted_headers;
+
+ /* @UNSAFE */
+ fields = t_new(struct mail_cache_field, count);
+ for (i = 0; i < count; i++) {
+ header_field.name = t_strconcat("hdr.", headers[i], NULL);
+ fields[i] = header_field;
+ }
+ mail_cache_register_fields(box->cache, fields, count);
+
+ pool = pool_alloconly_create("mailbox_header_lookup_ctx", 1024);
+ ctx = p_new(pool, struct mailbox_header_lookup_ctx, 1);
+ ctx->box = box;
+ ctx->refcount = 1;
+ ctx->pool = pool;
+ ctx->count = count;
+
+ ctx->idx = p_new(pool, unsigned int, count);
+
+ /* @UNSAFE */
+ dest_name = p_new(pool, const char *, count + 1);
+ for (i = 0; i < count; i++) {
+ ctx->idx[i] = fields[i].idx;
+ dest_name[i] = p_strdup(pool, headers[i]);
+ }
+ ctx->name = dest_name;
+ return ctx;
+}
+
+struct mailbox_header_lookup_ctx *
+mailbox_header_lookup_init(struct mailbox *box, const char *const headers[])
+{
+ struct mailbox_header_lookup_ctx *ctx;
+
+ T_BEGIN {
+ ctx = mailbox_header_lookup_init_real(box, headers);
+ } T_END;
+ return ctx;
+}
+
+void mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx)
+{
+ i_assert(ctx->refcount > 0);
+ ctx->refcount++;
+}
+
+void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **_ctx)
+{
+ struct mailbox_header_lookup_ctx *ctx = *_ctx;
+
+ *_ctx = NULL;
+
+ i_assert(ctx->refcount > 0);
+ if (--ctx->refcount > 0)
+ return;
+
+ pool_unref(&ctx->pool);
+}
return 0;
}
-static struct mailbox_header_lookup_ctx *
-test_mailbox_header_lookup_init(struct mailbox *box,
- const char *const headers[])
-{
- struct mailbox_header_lookup_ctx *ctx;
-
- ctx = i_new(struct mailbox_header_lookup_ctx, 1);
- ctx->box = box;
- ctx->headers = headers; /* now exactly right, but .. */
- return ctx;
-}
-
-static void
-test_mailbox_header_lookup_deinit(struct mailbox_header_lookup_ctx *ctx)
-{
- i_free(ctx);
-}
-
static struct mail_search_context *
test_mailbox_search_init(struct mailbox_transaction_context *t,
struct mail_search_args *args,
test_mailbox_transaction_rollback,
NULL,
test_mailbox_mail_alloc,
- test_mailbox_header_lookup_init,
- test_mailbox_header_lookup_deinit,
test_mailbox_search_init,
test_mailbox_search_deinit,
test_mailbox_search_next_nonblock,
backend_headers = vmail->wanted_headers == NULL ? NULL :
mailbox_header_lookup_init(bbox->box,
- vmail->wanted_headers->headers);
+ vmail->wanted_headers->name);
vmail->backend_mail = mail_alloc(backend_trans, vmail->wanted_fields,
backend_headers);
if (backend_headers != NULL)
return -1;
backend_headers = mailbox_header_lookup_init(vmail->backend_mail->box,
- headers->headers);
+ headers->name);
ret = mail_get_header_stream(vmail->backend_mail, backend_headers,
stream_r);
mailbox_header_lookup_unref(&backend_headers);
virtual_transaction_rollback,
NULL,
virtual_mail_alloc,
- index_header_lookup_init,
- index_header_lookup_deinit,
virtual_search_init,
virtual_search_deinit,
virtual_search_next_nonblock,