mbox-sync-parse.c revision 7797aa2479e99aeb71057b7a2584b2cb72e4d3f8
/* Copyright (C) 2004 Timo Sirainen */
/* MD5 header summing logic was pretty much copy&pasted from popa3d by
Solar Designer */
#include "lib.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-sync-private.h"
#include <stdlib.h>
struct mbox_flag_type mbox_status_flags[] = {
{ 'R', MAIL_SEEN },
{ 'O', MBOX_NONRECENT },
{ 0, 0 }
};
struct mbox_flag_type mbox_xstatus_flags[] = {
{ 'A', MAIL_ANSWERED },
{ 'F', MAIL_FLAGGED },
{ 'T', MAIL_DRAFT },
{ 'D', MAIL_DELETED },
{ 0, 0 }
};
struct header_func {
const char *header;
struct message_header_line *hdr);
};
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;
}
struct message_header_line *hdr)
{
const char *str;
char *end;
/* Valid only in first message */
return FALSE;
}
/* <uid validity> <last uid> */
t_push();
t_pop();
pos++;
if (uid_validity == 0) {
/* broken */
return FALSE;
}
else {
}
}
/* broken, update */
}
return TRUE;
// FIXME: save keywords
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)
{
// FIXME: parse them
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;
}
}
/* next_uid broken - fix it */
}
/* broken - UIDs must be growing */
return FALSE;
}
}
/* we're in mbox_sync_parse_match_mail() */
return TRUE;
}
/* everything was good, except we can't have X-UID before
X-IMAPbase header (to keep c-client compatibility). keep
the UID, but when we're rewriting this makes sure the
X-UID is appended after X-IMAPbase. */
return FALSE;
}
return TRUE;
}
struct message_header_line *hdr)
{
size_t i;
for (i = 0; i < hdr->full_value_len; i++) {
break;
}
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;
}
struct message_header_line *hdr)
{
if (!ctx->seen_received_hdr) {
/* Received-header contains date too, and more trusted one */
}
return TRUE;
}
struct message_header_line *hdr)
{
return TRUE;
}
struct message_header_line *hdr)
{
if (!ctx->seen_received_hdr) {
/* Received-header contains unique ID too,
and more trusted one */
}
return TRUE;
}
struct message_header_line *hdr)
{
if (!ctx->seen_received_hdr) {
/* get only the first received-header */
}
return TRUE;
}
struct message_header_line *hdr)
{
/* Let the local delivery agent help generate unique ID's but don't
blindly trust this header alone as it could just as easily come from
the remote. */
return TRUE;
}
static struct 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 },
{ "X-UIDL", parse_x_uidl }
};
static struct header_func md5_header_funcs[] = {
{ "Date", parse_date },
{ "Delivered-To", parse_delivered_to },
{ "Message-ID", parse_message_id },
{ "Received", parse_received },
{ "X-Delivery-ID", parse_x_delivery_id }
};
#define MD5_HEADER_FUNCS_COUNT \
(sizeof(md5_header_funcs) / sizeof(*md5_header_funcs))
{
}
struct mbox_sync_mail_context *ctx)
{
struct message_header_parser_ctx *hdr_ctx;
struct message_header_line *hdr;
struct header_func *func;
int i, ret;
ctx->header_last_change = 0;
for (i = 0; i < MBOX_HDR_COUNT; i++)
line_start_pos = 0;
break;
}
}
sizeof(*header_funcs), bsearch_header_func_cmp);
/* these functions do nothing more than update
MD5 sums */
} else {
sizeof(*header_funcs),
}
continue;
}
/* this header is broken, remove it */
}
continue;
}
} else {
}
if (!hdr->no_newline)
}
/* missing X-IMAPbase */
}
/* update uid-last field in X-IMAPbase */
}
}
{
struct mbox_sync_mail_context ctx;
struct message_header_parser_ctx *hdr_ctx;
struct message_header_line *hdr;
struct header_func *func;
const void *data;
int ret;
break;
sizeof(*header_funcs), bsearch_header_func_cmp);
/* these functions do nothing more than update
MD5 sums */
continue;
}
break;
}
}
/* match by X-UID header */
return -1;
}
}
/* match by MD5 sum */
if (ibox->md5hdr_ext_idx == 0) {
0, 16);
}
return -1;
}
}