imapc-storage.c revision 857c471c13ca215f4be9dd4b336b742b8d434e31
/* Copyright (c) 2011-2016 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "str.h"
#include "imap-arg.h"
#include "imap-resp-code.h"
#include "mailbox-tree.h"
#include "imapc-client.h"
#include "imapc-connection.h"
#include "imapc-msgmap.h"
#include "imapc-mail.h"
#include "imapc-list.h"
#include "imapc-search.h"
#include "imapc-sync.h"
#include "imapc-settings.h"
#include "imapc-storage.h"
#define DNS_CLIENT_SOCKET_NAME "dns-client"
struct imapc_open_context {
struct imapc_mailbox *mbox;
int ret;
};
struct imapc_resp_code_map {
const char *code;
enum mail_error error;
};
extern struct mail_storage imapc_storage;
extern struct mailbox imapc_mailbox;
static struct imapc_resp_code_map imapc_resp_code_map[] = {
/* { IMAP_RESP_CODE_CLIENTBUG, 0 }, */
};
struct imapc_storage_client *client);
struct imapc_storage_client *client);
enum mailbox_status_items items,
struct mailbox_status *status_r);
{
unsigned int i;
return FALSE;
for (i = 0; i < N_ELEMENTS(imapc_resp_code_map); i++) {
return TRUE;
}
}
return FALSE;
}
{
enum imapc_capability capa =
return (capa & (IMAPC_CAPABILITY_CONDSTORE |
IMAPC_CAPABILITY_QRESYNC)) != 0 &&
}
static struct mail_storage *imapc_storage_alloc(void)
{
struct imapc_storage *storage;
}
enum mail_error default_error,
const struct imapc_command_reply *reply)
{
enum mail_error error;
} else {
}
}
struct imapc_storage_client *client)
{
}
{
}
}
{
}
{
do {
}
void *context)
{
} else {
}
}
{
struct imapc_command *cmd;
struct imapc_simple_context sctx;
/* mailbox opening hasn't finished yet */
return;
}
}
static void
void *context)
{
const struct imapc_storage_event_callback *cb;
const struct imapc_mailbox_event_callback *mcb;
}
return;
}
}
}
}
static void
void *context)
{
return;
if (client->destroying &&
/* user's work was finished before imapc login finished -
it's not an error */
return;
}
else {
}
}
else {
}
}
}
const struct imapc_settings *imapc_set,
const struct mail_storage_settings *mail_set,
struct imapc_storage_client **client_r,
const char **error_r)
{
struct imapc_storage_client *client;
struct imapc_client_settings set;
*error_r = "missing imapc_host";
return -1;
}
else
*error_r = "missing imapc_password";
return -1;
}
else
/* start logging in immediately */
}
return 0;
}
{
struct imapc_storage_event_callback *cb;
return;
}
static int
struct mail_namespace *ns,
const char **error_r)
{
/* serialize all the settings */
"%s%s://(%s|%s):%s@%s:%u/%s mechs:%s features:%s "
"pop3delflg:%s root_dir:%s",
} else {
return -1;
}
return 0;
}
{
/* make sure all pending commands are aborted before anything is
deinitialized */
}
const char *name,
{
struct imapc_storage_event_callback *cb;
}
static void
struct mailbox_list_settings *set)
{
}
static struct mailbox *
{
struct imapc_mailbox *mbox;
}
{
}
static int
enum mailbox_existence *existence_r)
{
enum mailbox_info_flags flags;
return -1;
}
if ((flags & MAILBOX_NONEXISTENT) != 0)
else if ((flags & MAILBOX_NOSELECT) != 0)
else
return 0;
}
{
/* mainly a Courier-workaround: With POP3-only Maildir that
doesn't have UIDVALIDITY set, EXAMINE won't generate a
permanent UIDVALIDITY while SELECT will. */
return FALSE;
}
}
static void
void *context)
{
"imapc: Reopening mailbox '%s' failed: %s",
}
}
static void imapc_mailbox_reopen(void *context)
{
struct imapc_command *cmd;
/* we're reconnecting and need to reopen the mailbox */
mbox->prev_skipped_rseq = 0;
mbox->prev_skipped_uid = 0;
if (imapc_mailbox_want_examine(mbox)) {
} else {
}
}
static void
void *context)
{
} else {
"imapc: Opening mailbox '%s' failed: %s",
}
}
{
enum imapc_capability capa =
/* see if we can get message GUIDs somehow */
if ((capa & IMAPC_CAPABILITY_X_GM_EXT_1) != 0) {
/* GMail */
}
}
}
{
struct imapc_command *cmd;
struct imapc_open_context ctx;
/* If authentication failed, don't check again. */
return -1;
}
mbox->client_box =
if (imapc_mailbox_want_examine(mbox)) {
} else {
}
}
{
return -1;
/* We don't actually want to SELECT the mailbox. */
return 0;
}
/* trying to open INBOX as the namespace prefix.
Don't allow this. */
"Mailbox isn't selectable");
return -1;
}
else
}
if (imapc_mailbox_select(mbox) < 0) {
return -1;
}
return 0;
}
{
i_error("close(imapc cached mail) failed: %m");
}
}
{
}
}
static int
bool directory)
{
struct imapc_command *cmd;
struct imapc_simple_context sctx;
if (!directory)
;
struct imapc_mailbox_list *imapc_list =
} else {
}
}
const struct mailbox_update *update)
{
update->min_first_recent_uid != 0) {
"Not supported");
}
}
struct imapc_storage_client *client)
{
struct mailbox_status *status;
unsigned int i;
return;
return;
/* match */
/* case-insensitive INBOX */
} else {
return;
}
return;
}
}
struct imapc_storage_client *client)
{
static enum mail_namespace_type ns_types[] = {
};
struct imapc_namespace *ns;
unsigned int i;
for (i = 0; i < N_ELEMENTS(ns_types); i++) {
continue;
break;
break;
}
}
}
enum mailbox_status_items items,
struct mailbox_status *status_r)
{
int ret = 0;
if ((items & STATUS_PERMANENT_FLAGS) != 0)
if ((items & STATUS_FIRST_RECENT_UID) != 0)
if ((items & STATUS_HIGHESTMODSEQ) != 0) {
/* FIXME: this doesn't work perfectly. we're now just returning
the HIGHESTMODSEQ from the current index, which may or may
not be correct. with QRESYNC enabled we could be returning
sync_highestmodseq, but that would require implementing
VANISHED replies. and without QRESYNC we'd have to issue
STATUS (HIGHESTMODSEQ), which isn't efficient since we get
here constantly (after every IMAP command). */
}
/* even if local indexes are only in memory, we still
have modseqs on the IMAP server itself. */
}
return ret;
}
{
return index_storage_mailbox_delete(box);
}
enum mailbox_status_items items,
struct mailbox_status *status_r)
{
struct imapc_command *cmd;
struct imapc_simple_context sctx;
if ((items & STATUS_MESSAGES) != 0)
if ((items & STATUS_RECENT) != 0)
if ((items & STATUS_UIDNEXT) != 0)
if ((items & STATUS_UIDVALIDITY) != 0)
if ((items & STATUS_UNSEEN) != 0)
if ((items & STATUS_HIGHESTMODSEQ) != 0 &&
/* nothing requested */
return 0;
}
}
enum mailbox_status_items items,
struct mailbox_status *status_r)
{
/* can't do anything about this */
}
STATUS_FIRST_RECENT_UID)) != 0) {
/* getting these requires opening the mailbox */
if (mailbox_open(box) < 0)
return -1;
return -1;
} else {
return -1;
}
mbox->sync_uid_next == 0) {
/* Courier-workaround, it doesn't send UIDNEXT on SELECT */
return -1;
}
return 0;
}
{
enum imapc_capability capa;
struct imapc_command *cmd;
struct imapc_simple_context sctx;
if (storage->namespaces_requested)
return 0;
if ((capa & IMAPC_CAPABILITY_NAMESPACE) == 0) {
/* NAMESPACE capability not supported */
return 0;
}
return -1;
return 0;
}
static const struct imapc_namespace *
{
}
}
}
return best_ns;
}
enum mailbox_metadata_items items,
struct mailbox_metadata *metadata_r)
{
const struct imapc_namespace *ns;
if ((items & MAILBOX_METADATA_GUID) != 0) {
/* a bit ugly way to do this, but better than nothing for now.
FIXME: if indexes are enabled, keep this there. */
}
if ((items & MAILBOX_METADATA_BACKEND_NAMESPACE) != 0) {
return -1;
}
}
if (items != 0) {
return -1;
}
return 0;
}
void *context)
{
;
else {
}
}
{
struct imapc_command *cmd;
}
void *context)
{
}
{
struct imapc_command *cmd;
enum imapc_capability capa;
return;
}
if ((capa & IMAPC_CAPABILITY_IDLE) != 0) {
/* remote server is already in IDLE. but since some servers
don't notice changes immediately, we'll force them to check
here by sending a NOOP. this helps with clients that break
IDLE when clicking "get mail". */
} else {
/* remote server doesn't support IDLE.
check for changes with NOOP every once in a while. */
}
}
{
return TRUE;
}
struct mail_storage imapc_storage = {
.v = {
NULL,
NULL,
NULL,
NULL,
}
};
struct mailbox imapc_mailbox = {
.v = {
NULL,
NULL,
NULL,
NULL,
}
};