/* Copyright (c) 2011-2018 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-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"
struct imapc_open_context {
int ret;
};
struct imapc_resp_code_map {
const char *code;
};
extern struct mail_storage imapc_storage;
extern struct mailbox imapc_mailbox;
/* { 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;
}
{
IMAPC_CAPABILITY_QRESYNC)) != 0 &&
}
{
}
enum mail_error default_error,
const struct imapc_command_reply *reply)
{
} else {
}
}
struct imapc_storage_client *client)
{
}
{
}
}
{
}
{
do {
}
void *context)
{
} else {
}
}
{
/* mailbox opening hasn't finished yet */
return;
}
}
static void
void *context)
{
}
return;
}
}
}
}
static void
void *context)
{
return;
if (client->destroying &&
/* user's work was finished before imapc login finished -
it's not an error */
return;
}
i_unreached();
}
{
return FALSE;
/* We need to set the error to either storage or to list, depending on
whether the caller is from mail-storage.h API or mailbox-list.h API.
We don't know here what the caller is though, so just set the error
to both of them. */
else {
}
}
else {
}
}
return TRUE;
}
{
if (!user->namespaces_created) {
/* we're still initializing the user. wait for the
login to finish, so we can fail the user creation
if it fails. */
while (!client->auth_returned)
"imapc: Login to %s failed: %s",
}
}
}
const struct imapc_settings *imapc_set,
const struct mail_storage_settings *mail_set,
struct imapc_storage_client **client_r,
const char **error_r)
{
*error_r = "missing imapc_host";
return -1;
}
else
*error_r = "missing imapc_password";
return -1;
}
else
/* start logging in immediately */
}
return 0;
}
{
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,
{
}
static void
struct mailbox_list_settings *set)
{
}
static struct mailbox *
{
}
{
}
static int
enum mailbox_existence *existence_r)
{
else
return 0;
}
return -1;
}
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 bool
{
if (!mbox->exists_received)
*error_r = "EXISTS not received";
else if (mbox->sync_uid_validity == 0)
*error_r = "UIDVALIDITY not received";
else
return TRUE;
return FALSE;
}
static void
void *context)
{
const char *errmsg;
}
t_strdup_printf("Reopening mailbox '%s' failed: %s",
}
}
{
/* we're reconnecting and need to reopen the mailbox */
mbox->prev_skipped_rseq = 0;
mbox->prev_skipped_uid = 0;
automatically resent by lib-imap-client, so we don't need to
send it again here. */
return;
}
if (imapc_mailbox_want_examine(mbox)) {
} else {
}
}
static void
void *context)
{
const char *error;
"imapc: Opening mailbox failed: %s", error);
} else {
}
} else {
}
}
{
/* If authentication failed, don't check again. */
return -1;
&mbox->capabilities);
}
{
/* see if we can get message GUIDs somehow */
/* GMail */
}
}
}
{
if (imapc_mailbox_get_capabilities(mbox) < 0)
return -1;
if (imapc_mailbox_has_modseqs(mbox)) {
else
}
mbox->client_box =
if (imapc_mailbox_want_examine(mbox)) {
} else {
}
if (!mbox->state_fetched_success)
}
{
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;
}
if (imapc_mailbox_select(mbox) < 0) {
return -1;
}
return 0;
}
{
}
{
bool changes;
}
static int
bool directory)
{
if (!directory)
;
} else {
}
}
const struct mailbox_update *update)
{
update->min_first_recent_uid != 0) {
"Not supported");
}
}
struct imapc_storage_client *client)
{
unsigned int i;
return;
return;
/* match */
/* case-insensitive INBOX */
} else {
return;
}
return;
}
}
struct imapc_storage_client *client)
{
};
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)
{
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). */
}
if (imapc_mailbox_has_modseqs(mbox)) {
/* even if local indexes are only in memory, we still
have modseqs on the IMAP server itself. */
}
}
{
return index_storage_mailbox_delete(box);
}
enum mailbox_status_items items,
struct mailbox_status *status_r)
{
if (imapc_mailbox_get_capabilities(mbox) < 0)
return -1;
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)
{
STATUS_FIRST_RECENT_UID)) != 0) {
/* getting these requires opening the mailbox */
if (mailbox_open(box) < 0)
return -1;
} else {
return -1;
}
mbox->sync_uid_next == 0) {
/* Courier-workaround, it doesn't send UIDNEXT on SELECT */
return -1;
}
return 0;
}
{
if (storage->namespaces_requested)
return 0;
if (imapc_mailbox_get_capabilities(mbox) < 0)
return -1;
/* 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)
{
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) {
if (imapc_mailbox_get_namespaces(mbox) < 0)
return -1;
}
}
if (items != 0) {
return -1;
}
return 0;
}
void *context)
{
;
else {
}
}
{
}
void *context)
{
}
{
return;
}
/* 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;
}
.v = {
NULL,
NULL,
NULL,
NULL,
}
};
.v = {
NULL,
NULL,
NULL,
NULL,
}
};