mbox-sync-parse.c revision 9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2004 Timo Sirainen */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen#define IS_LWSP_LF(c) (IS_LWSP(c) || (c) == '\n')
fe779565bda49a0ed0476724819c6e3c1340c94bTimo Sirainen int (*func)(struct mbox_sync_mail_context *ctx,
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Boschstatic enum mail_flags mbox_flag_find(struct mbox_flag_type *flags, char chr)
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic void parse_status_flags(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen mbox_flag_find(flags_list, hdr->full_value[i]);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic int parse_status(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen parse_status_flags(ctx, hdr, mbox_status_flags);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->hdr_pos[MBOX_HDR_STATUS] = str_len(ctx->header);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic int parse_x_status(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen parse_status_flags(ctx, hdr, mbox_xstatus_flags);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->hdr_pos[MBOX_HDR_X_STATUS] = str_len(ctx->header);
0adc24c0c534944b55a185795e09dfaea2ca3131Stephan Boschstatic int parse_x_imap_base(struct mbox_sync_mail_context *ctx,
0adc24c0c534944b55a185795e09dfaea2ca3131Stephan Bosch const char *str;
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* Valid only in first message */
1c75bf24894a3fc0631caa4954e5130e9bb01d8dTimo Sirainen /* <uid validity> <last uid> */
1c75bf24894a3fc0631caa4954e5130e9bb01d8dTimo Sirainen str = t_strndup(hdr->full_value, hdr->full_value_len);
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch while (pos < hdr->full_value_len && IS_LWSP_LF(hdr->full_value[pos]))
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen // FIXME: save keywords
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->sync_ctx->base_uid_validity = uid_validity;
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic int parse_x_keywords(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen // FIXME: parse them
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] = str_len(ctx->header);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic int parse_x_uid(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* duplicate */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (hdr->full_value[i] < '0' || hdr->full_value[i] > '9')
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen value = value*10 + (hdr->full_value[i] - '0');
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* broken value */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* broken - UIDs must be growing */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen ctx->hdr_pos[MBOX_HDR_X_UID] = str_len(ctx->header);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (extra_space != 0 && ctx->mail.space == 0) {
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* set it only if X-Keywords hasn't been seen. spaces in X-UID
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen should be removed when writing X-Keywords. */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic int parse_content_length(struct mbox_sync_mail_context *ctx,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* duplicate */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (hdr->full_value[i] < '0' || hdr->full_value[i] > '9')
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen value = value*10 + (hdr->full_value[i] - '0');
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* broken value */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic struct header_func *header_func_find(const char *header)
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen for (i = 0; header_funcs[i].header != NULL; i++) {
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (strcasecmp(header_funcs[i].header, header) == 0)
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenvoid mbox_sync_parse_next_mail(struct istream *input,
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch for (i = 0; i < MBOX_HDR_COUNT; i++)
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch hdr_ctx = message_parse_header_init(input, NULL);
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch while ((hdr = message_parse_header_next(hdr_ctx)) != NULL) {
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch /* this header is broken, remove it */
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch if (ctx->seq == 1 && ctx->sync_ctx->base_uid_validity == 0) {
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch /* missing X-IMAPbase */
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch /* missing X-UID */