imapc-mail.c revision 7b0a52bf38f8a7ab0c262acf4c761d6a0f22a07c
/* Copyright (c) 2011-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "hex-binary.h"
#include "sha1.h"
#include "istream.h"
#include "message-part-data.h"
#include "imap-envelope.h"
#include "imapc-msgmap.h"
#include "imapc-mail.h"
#include "imapc-storage.h"
struct mail *
imapc_mail_alloc(struct mailbox_transaction_context *t,
struct mailbox_header_lookup_ctx *wanted_headers)
{
struct imapc_mail *mail;
}
{
struct imapc_msgmap *msgmap;
if (!mbox->initial_sync_done) {
/* unknown at this point */
return FALSE;
}
/* check if another session has already expunged it */
return TRUE;
}
/* check if we've received EXPUNGE for it */
return TRUE;
/* we may be running against a server that hasn't bothered sending
us an EXPUNGE. see if NOOP sends it. */
if (!mbox->initial_sync_done) {
/* NOOP caused a reconnection and desync */
return FALSE;
}
}
{
bool fix_broken_mail = FALSE;
/* we've already logged a disconnection error */
} else {
/* By default we'll assume that this is a critical failure,
because we don't want to lose any data. We can be here
either because it's a temporary failure on the server or
it's a permanent failure. Unfortunately we can't know
which case it is, so permanent failures need to be worked
around by setting imapc_features=fetch-fix-broken-mails.
One reason for permanent failures was that earlier Exchange
versions failed to return any data for messages in Calendars
mailbox. This seems to be fixed in newer versions.
*/
"imapc: Remote server didn't send %s for UID %u in %s%s (FETCH replied: %s)",
}
return fix_broken_mail ? 0 : -1;
}
{
struct imapc_msgmap *msgmap;
unsigned int count;
if (!imapc_mailbox_has_modseqs(mbox))
return index_mail_get_modseq(_mail);
}
return 1; /* unknown modseq */
}
{
return 0;
return -1;
return -1;
/* assume that the server never returns INTERNALDATE
for this mail (see BODY[] failure handling) */
data->received_date = 0;
}
}
return 0;
}
{
/* FIXME: we could use a value stored in cache */
}
return 0;
}
{
int ret;
return 0;
}
/* trust RFC822.SIZE to be correct */
return -1;
return -1;
/* assume that the server never returns RFC822.SIZE
for this mail (see BODY[] failure handling) */
data->physical_size = 0;
}
return 0;
}
return -1;
&data->physical_size);
if (ret <= 0) {
"imapc: stat(%s) failed: %m",
return -1;
}
return 0;
}
{
return -1;
return 0;
}
static int
struct mailbox_header_lookup_ctx *headers,
{
int ret;
}
/* see if the wanted headers are already in cache */
if (ret == 0)
return 0;
/* fetch only the wanted headers */
return -1;
/* the headers should cached now. */
}
static int
bool decode_to_utf8, const char *const **value_r)
{
struct mailbox_header_lookup_ctx *headers;
const char *header_names[2];
const unsigned char *data;
int ret;
header_names[0] = field;
if (ret < 0)
return -1;
/* the header should cached now. */
}
static int
bool decode_to_utf8, const char **value_r)
{
const char *const *values;
int ret;
if (ret <= 0)
return ret;
return 1;
}
static int
struct message_size *hdr_size,
{
enum mail_fetch_field fetch_field;
/* we've fetched the header, but we need the body now too */
/* don't re-use any cached header sizes. we may be
intentionally downloading the full body because the header
wasn't returned correctly (e.g. pop3-migration does this) */
}
/* See if we can get it from cache. If the wanted_fields/headers are
set properly, this is usually already done by prefetching. */
if (!data->initialized) {
/* coming here from mail_set_seq() */
return -1;
}
fetch_field = get_body ||
return -1;
return -1;
/* return the broken email as empty */
}
}
stream_r);
}
struct mailbox_header_lookup_ctx *headers)
{
unsigned int i;
return FALSE;
}
return TRUE;
}
{
struct mailbox_header_lookup_ctx *header_ctx;
const char *str;
}
}
MAIL_FETCH_VIRTUAL_SIZE)) != 0) {
}
(void)imapc_mail_get_cached_guid(_mail);
/* see if all wanted headers exist in cache */
}
if (data->access_part == 0 &&
/* the common code already checked this partially,
but we need a guaranteed correct answer */
}
}
{
/* searching code handles prefetching internally,
elsewhere we want to do it immediately */
(void)imapc_mail_prefetch(_mail);
}
static void
enum mail_fetch_field fields,
struct mailbox_header_lookup_ctx *headers)
{
}
{
if (mail->fetch_count > 0) {
while (mail->fetch_count > 0)
}
if (mail->body_fetched) {
} else {
}
}
i_error("close(imapc mail) failed: %m");
}
}
{
const unsigned char *data;
unsigned char sha1_output[SHA1_RESULTLEN];
const char *sha1_str;
return -1;
}
return 0;
}
{
const enum index_cache_field cache_idx =
/* GUID was prefetched - add to cache */
}
return TRUE;
}
return TRUE;
}
return FALSE;
}
{
const enum index_cache_field cache_idx =
if (imapc_mail_get_cached_guid(_mail)) {
return 0;
}
/* GUID not in cache, fetch it */
return -1;
return -1;
}
} else {
/* use hash of message headers as the GUID */
if (imapc_mail_get_hdr_hash(imail) < 0)
return -1;
}
return 0;
}
static int
const char **value_r)
{
switch (field) {
case MAIL_FETCH_GUID:
/* GUIDs not supported by server */
break;
}
*value_r = "";
case MAIL_FETCH_UIDL_BACKEND:
break;
return -1;
"X-GM-MSGID not 64bit integer as expected for POP3 UIDL generation: %s", *value_r);
return -1;
}
(unsigned long long)num);
return 0;
case MAIL_FETCH_IMAP_BODY:
break;
return 0;
return -1;
return -1;
}
return 0;
break;
return 0;
return -1;
return -1;
}
return 0;
default:
break;
}
}
struct mail_vfuncs imapc_mail_vfuncs = {
NULL,
};