doveadm-mail-index.c revision 71f4549303dc1691382748a096c2ada9d2a1a9fe
/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "strescape.h"
#include "net.h"
#include "write-full.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-search-build.h"
#include "mailbox-list-iter.h"
#include "doveadm-settings.h"
#include "doveadm-mail.h"
#include <stdio.h>
#define INDEXER_SOCKET_NAME "indexer"
#define INDEXER_HANDSHAKE "VERSION\tindexer\t1\t0\n"
struct index_cmd_context {
struct doveadm_mail_cmd_context ctx;
int queue_fd;
unsigned int max_recent_msgs;
unsigned int queue:1;
unsigned int have_wildcards:1;
};
{
struct mailbox_status status;
struct mailbox_transaction_context *trans;
struct mail_search_args *search_args;
struct mail_search_context *ctx;
struct mailbox_metadata metadata;
int ret = 0;
&metadata) < 0) {
i_error("Mailbox %s: Precache-fields lookup failed: %s",
}
&status) < 0) {
i_error("Mailbox %s: Status lookup failed: %s",
return -1;
}
if (doveadm_verbose) {
i_info("%s: Cache is already up to date",
}
return 0;
}
if (doveadm_verbose) {
i_info("%s: Caching mails seq=%u..%u",
}
}
}
if (doveadm_verbose)
if (mailbox_search_deinit(&ctx) < 0) {
i_error("Mailbox %s: Mail search failed: %s",
ret = -1;
}
if (mailbox_transaction_commit(&trans) < 0) {
i_error("Mailbox %s: Transaction commit failed: %s",
ret = -1;
}
return ret;
}
static int
{
struct mailbox_status status;
int ret = 0;
if (ctx->max_recent_msgs != 0) {
/* index only if there aren't too many recent messages.
don't bother syncing the mailbox, that alone can take a
while with large maildirs. */
if (mailbox_open(box) < 0) {
mailbox_free(&box);
return -1;
}
mailbox_free(&box);
return 0;
}
}
ret = -1;
} else {
if (cmd_index_box_precache(box) < 0) {
ret = -1;
}
}
mailbox_free(&box);
return ret;
}
{
const char *path;
strlen(INDEXER_HANDSHAKE)) < 0)
i_fatal("write(indexer) failed: %m");
}
{
T_BEGIN {
i_fatal("write(indexer) failed: %m");
} T_END;
}
static int
{
const enum mailbox_list_iter_flags iter_flags =
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
unsigned int i;
int ret = 0;
/* we can do this quickly without going through the mailboxes */
return 0;
}
MAILBOX_NONEXISTENT)) == 0) T_BEGIN {
else {
ret = -1;
}
} T_END;
}
if (mailbox_list_iter_deinit(&iter) < 0) {
i_error("Listing mailboxes failed: %s",
ret = -1;
}
return ret;
}
const char *const args[])
{
unsigned int i;
doveadm_mail_help_name("index");
break;
}
}
}
{
}
}
static bool
{
switch (c) {
case 'q':
break;
case 'n':
"Invalid -n parameter number: %s", optarg);
}
break;
default:
return FALSE;
}
return TRUE;
}
static struct doveadm_mail_cmd_context *cmd_index_alloc(void)
{
struct index_cmd_context *ctx;
}
struct doveadm_cmd_ver2 doveadm_cmd_index_ver2 = {
.name = "index",
.usage = "[-q] [-n <max recent>] <mailbox mask>",
};