mbox-sync-private.h revision e68309fcfa2eaa88217fd51e7b4900fc9c20ef5d
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen#ifndef __MBOX_SYNC_PRIVATE_H
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen#define __MBOX_SYNC_PRIVATE_H
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen#include "mail-index.h"
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstruct mbox_flag_type {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen char chr;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen enum mail_flags flag;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen};
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenenum header_position {
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen MBOX_HDR_STATUS,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen MBOX_HDR_X_IMAPBASE,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen MBOX_HDR_X_KEYWORDS,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen MBOX_HDR_X_STATUS,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen MBOX_HDR_X_UID,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen MBOX_HDR_COUNT
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen};
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen#define MBOX_NONRECENT MAIL_RECENT /* kludgy */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen#define STATUS_FLAGS_MASK (MAIL_SEEN|MBOX_NONRECENT)
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen#define XSTATUS_FLAGS_MASK (MAIL_ANSWERED|MAIL_FLAGGED|MAIL_DRAFT|MAIL_DELETED)
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenextern struct mbox_flag_type mbox_status_flags[];
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenextern struct mbox_flag_type mbox_xstatus_flags[];
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstruct mbox_sync_mail {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uint32_t uid;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uint8_t flags;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen keywords_mask_t keywords;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uoff_t offset; /* if space <= 0, points to beginning */
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen off_t space;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uoff_t body_size;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen};
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenstruct mbox_sync_mail_context {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct mbox_sync_context *sync_ctx;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct mbox_sync_mail mail;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uint32_t seq;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uoff_t from_offset, hdr_offset, body_offset;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen size_t header_first_change, header_last_change;
4efba37e4f27b93832f6147c3a353d6d22c855c7Timo Sirainen string_t *header;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uoff_t content_length;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen size_t hdr_pos[MBOX_HDR_COUNT];
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen unsigned int have_eoh:1;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen unsigned int need_rewrite:1;
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen unsigned int seen_imapbase:1;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen};
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
c345aae9f46e6ecad7bd562089696e449f8b0099Timo Sirainenstruct mbox_sync_context {
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct index_mailbox *ibox;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct istream *input, *file_input;
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen int fd;
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen string_t *header, *from_line;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen uint32_t base_uid_validity, base_uid_last;
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen uint32_t prev_msg_uid, next_uid;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen off_t expunged_space;
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen};
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenint mbox_sync(struct index_mailbox *ibox, int last_commit);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenvoid mbox_sync_parse_next_mail(struct istream *input,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen struct mbox_sync_mail_context *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen int rewriting);
e376e08040b5f21ff79a15ae728d2532a34207f6Timo Sirainenvoid mbox_sync_update_header(struct mbox_sync_mail_context *ctx,
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen buffer_t *syncs_buf);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainenvoid mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen const struct mbox_sync_mail *mail);
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenint mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff);
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenint mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, buffer_t *mails_buf,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen uint32_t first_seq, uint32_t last_seq, off_t extra_space);
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainenint mbox_move(struct mbox_sync_context *sync_ctx,
32142dc3b19a1dff23ef351596703f1a43ea51a0Timo Sirainen uoff_t dest, uoff_t source, uoff_t size);
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen#endif
7d548d4984752d74bfea8dc4bf1781a8996f43e7Timo Sirainen