mbox-sync-parse.c revision 19e8adccba16ff419f5675b1575358c2956dce83
/* Copyright (c) 2004-2008 Dovecot authors, see the included COPYING file */
/* MD5 header summing logic was pretty much copy&pasted from popa3d by
Solar Designer */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "buffer.h"
#include "istream.h"
#include "str.h"
#include "write-full.h"
#include "message-parser.h"
#include "mail-index.h"
#include "mbox-storage.h"
#include "mbox-md5.h"
#include "mbox-sync-private.h"
#include <stdlib.h>
struct mbox_sync_header_func {
const char *header;
struct message_header_line *hdr);
};
struct mbox_flag_type mbox_status_flags[] = {
{ 'R', MAIL_SEEN },
{ 'O', MBOX_NONRECENT_KLUDGE },
{ 0, 0 }
};
struct mbox_flag_type mbox_xstatus_flags[] = {
{ 'A', MAIL_ANSWERED },
{ 'F', MAIL_FLAGGED },
{ 'T', MAIL_DRAFT },
{ 'D', MAIL_DELETED },
{ 0, 0 }
};
struct message_header_line *hdr)
{
/* the value may contain newlines. we can't count whitespace before
and after it as a single contiguous whitespace block, as that may
get us into situation where removing whitespace goes eg.
" \n \n" -> " \n\n" which would then be treated as end of headers.
that could probably be avoided by being careful, but as newlines
should never be there (we don't generate them), it's not worth the
trouble. */
for (i = hdr->full_value_len; i > 0; i--) {
break;
space++;
}
}
}
{
int i;
}
return 0;
}
struct message_header_line *hdr,
struct mbox_flag_type *flags_list)
{
size_t i;
for (i = 0; i < hdr->full_value_len; i++) {
}
}
struct message_header_line *hdr)
{
return TRUE;
}
struct message_header_line *hdr)
{
return TRUE;
}
static void
{
count = 0;
pos++;
continue;
}
/* read the keyword */
keyword_start = pos;
break;
}
/* add it to index's keyword list if it's not there already */
pos - keyword_start);
}
count++;
}
/* need to update this list */
}
}
struct message_header_line *hdr)
{
size_t i, j, uid_last_pos;
/* Valid only in first message */
return FALSE;
}
/* <uid-validity> 10x<uid-last> */
return FALSE;
break;
}
}
if (uid_validity == 0) {
/* broken */
return FALSE;
}
for (; i < hdr->full_value_len; i++) {
break;
}
uid_last_pos = i;
return FALSE;
break;
}
}
if (j != 10 ||
/* uid-last field must be exactly 10 characters to make
rewriting it easier. also don't try to do this if some
headers have been removed */
} else {
}
/* first time parsing this (ie. we're not rewriting).
save the values. */
/* new messages have been added since our last sync.
just update our internal next_uid. */
} else {
/* we need to rewrite the next-uid */
}
}
T_BEGIN {
} T_END;
return TRUE;
}
struct message_header_line *hdr)
{
return FALSE;
/* this is the c-client style "FOLDER INTERNAL DATA" message.
skip it. */
return TRUE;
}
struct message_header_line *hdr)
{
const unsigned int *list;
return FALSE; /* duplicate header, delete */
/* read keyword indexes to temporary array first */
pos++;
continue;
}
/* read the keyword string */
keyword_start = pos;
break;
}
str_truncate(keyword, 0);
pos - keyword_start);
/* keyword wasn't found. that means the sent mail
originally contained X-Keywords header. Delete it. */
return FALSE;
}
/* check that the keyword isn't already added there.
we don't want duplicates. */
for (i = 0; i < count; i++) {
break;
}
if (i == count)
}
/* once we know how many keywords there are, we can allocate the array
from mail_keyword_pool without wasting memory. */
if (array_count(&keyword_list) > 0) {
}
return TRUE;
}
struct message_header_line *hdr)
{
bool ret;
T_BEGIN {
} T_END;
return ret;
}
struct message_header_line *hdr)
{
size_t i;
/* duplicate */
return FALSE;
}
for (i = 0; i < hdr->full_value_len; i++) {
break;
}
for (; i < hdr->full_value_len; i++) {
/* broken value */
return FALSE;
}
}
/* we're in mbox_sync_parse_match_mail().
don't do any extra checks. */
return TRUE;
}
/* Don't bother allowing X-UID before X-IMAPbase
header. c-client doesn't allow it either, and this
way the UID doesn't have to be reset if X-IMAPbase
header isn't what we expect it to be. */
return FALSE;
}
/* X-UID is the next expected one. allow it because
we'd just use this UID anyway. X-IMAPbase header
still needs to be updated for this. */
/* UID is larger than expected. Don't allow it because
incoming mails can contain untrusted X-UID fields,
causing possibly DoS if the UIDs get large enough. */
return FALSE;
}
/* broken - UIDs must be growing */
return FALSE;
}
/* if we had multiple X-UID headers, we could have
uid_broken=TRUE here. */
/* if we're expunging the first mail, delete this header since
otherwise X-IMAPbase header would be added after this, which
we don't like */
return FALSE;
}
return TRUE;
}
struct message_header_line *hdr)
{
size_t i;
/* duplicate */
return FALSE;
}
for (i = 0; i < hdr->full_value_len; i++) {
break;
}
for (; i < hdr->full_value_len; i++) {
/* broken value */
return FALSE;
}
}
return TRUE;
}
static struct mbox_sync_header_func header_funcs[] = {
{ "Content-Length", parse_content_length },
{ "Status", parse_status },
{ "X-IMAP", parse_x_imap },
{ "X-IMAPbase", parse_x_imap_base },
{ "X-Keywords", parse_x_keywords },
{ "X-Status", parse_x_status },
{ "X-UID", parse_x_uid }
};
{
}
struct mbox_sync_mail_context *ctx)
{
struct message_header_parser_ctx *hdr_ctx;
struct message_header_line *hdr;
struct mbox_sync_header_func *func;
struct mbox_md5_context *mbox_md5_ctx;
int i, ret;
ctx->header_last_change = 0;
for (i = 0; i < MBOX_HDR_COUNT; i++)
line_start_pos = 0;
break;
}
}
continue;
}
/* this header is broken, remove it */
}
continue;
}
} else {
}
if (!hdr->no_newline) {
if (hdr->crlf_newline)
}
}
/* missing X-IMAPbase */
if (sync_ctx->base_uid_validity == 0) {
/* figure out a new UIDVALIDITY for us. */
}
}
}
{
struct mbox_sync_mail_context ctx;
struct message_header_parser_ctx *hdr_ctx;
struct message_header_line *hdr;
struct header_func *func;
struct mbox_md5_context *mbox_md5_ctx;
const void *data;
int ret;
/* we only wish to be sure that this mail actually is what we expect
it to be. If there's X-UID header and it matches our UID, we use it.
Otherwise it could mean that the X-UID header is invalid and it's
just not yet been rewritten. In that case use MD5 sum, if it
exists. */
break;
continue;
}
break;
}
} else {
}
}
return TRUE;
/* match by MD5 sum */
}