snarf-plugin.c revision 2ed2459dbd183bb371da4a0aecb2d2b74ae7c815
/* Copyright (c) 2007-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "unichar.h"
#include "mail-namespace.h"
#include "mail-search-build.h"
#include "mail-storage-private.h"
#include "snarf-plugin.h"
#define SNARF_CONTEXT(obj) \
struct snarf_mail_storage {
const char *snarf_path;
bool snarfing_disabled;
};
struct snarf_mailbox {
union mailbox_module_context module_ctx;
};
const char *snarf_plugin_version = DOVECOT_ABI_VERSION;
{
struct mail_search_args *search_args;
struct mail_search_context *search_ctx;
struct mail_save_context *save_ctx;
enum mail_error error;
int ret;
/* make sure the destination mailbox has been opened.
note that this locks the mailbox. */
if (mailbox_open(destbox) < 0)
return -1;
return -1;
ret = 0;
continue;
/* if we failed because of out of disk space, just
move those messages we managed to move so far. */
if (error != MAIL_ERROR_NOQUOTA)
ret = -1;
break;
}
}
if (mailbox_search_deinit(&search_ctx) < 0)
ret = -1;
/* commit the copied messages to the destination mailbox. if we crash
between that and between expunging the messages from the source
mailbox, we're left with duplicates. */
if (ret < 0)
else if (mailbox_transaction_commit(&dest_trans) < 0)
ret = -1;
if (ret < 0)
else {
if (mailbox_transaction_commit(&src_trans) < 0)
ret = -1;
}
if (ret == 0) {
if (mailbox_sync(srcbox, 0) < 0)
ret = -1;
}
return ret;
}
static struct mailbox_sync_context *
{
/* close the mailbox so that we don't have to keep it locked */
}
{
}
static bool
const char **name_r)
{
struct mail_namespace *snarf_ns;
const char *snarf_name;
if (snarf_name == NULL)
return FALSE;
if (!uni_utf8_str_is_valid(snarf_name)) {
return FALSE;
}
*name_r = snarf_name;
return TRUE;
}
{
struct snarf_mailbox *sbox;
struct mailbox_list *snarf_list;
const char *snarf_name;
if (!box->inbox_user)
return;
return;
return;
v->sync_init = snarf_sync_init;
v->free = snarf_mailbox_free;
}
static struct mailbox *
struct mailbox_list *list,
{
struct mailbox_list *snarf_list;
const char *snarf_name;
else {
"stat(%s) failed: %m",
}
/* use the snarf box as our real INBOX */
&snarf_name)) {
list = snarf_list;
vname = snarf_name;
}
}
}
if (sstorage->snarfing_disabled) {
}
return box;
}
static void
{
struct snarf_mail_storage *mstorage;
}
{
const char *path;
/* snarfing is optional: do it only if the path specified
by mbox_snarf exists */
}
static struct mail_storage_hooks snarf_mail_storage_hooks = {
};
{
}
void snarf_plugin_deinit(void)
{
}