mbox-sync-update.c revision 33ae95df45c9b5ec51332a6b39eb5322038686b9
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void status_flags_append(struct mbox_sync_mail_context *ctx,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
0db42260be85e797aa9909a29b20296996f52e75Timo Sirainenstatic void status_flags_replace(struct mbox_sync_mail_context *ctx, size_t pos,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen unsigned char *data;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* how many bytes do we need? */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0, need = 0; flags_list[i].chr != 0; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* how many bytes do we have now? */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen data = buffer_get_modifyable_data(ctx->header, &size);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* see if this is unknown flag for us */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* save this one */
0ca3b9cb0f2a322a25ce7f229dc3d3a0b46be17bTimo Sirainen for (i = 0; i < MBOX_HDR_COUNT; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* @UNSAFE */
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen data = buffer_get_space_unsafe(ctx->header, pos, need);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0, need = 0; flags_list[i].chr != 0; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainenstatic void keywords_append(struct mbox_sync_mail_context *ctx,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_add_missing_headers(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen old_hdr_size = ctx->body_offset - ctx->hdr_offset;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->mail.uid == ctx->sync_ctx->first_uid &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen //FIXME:keywords_append(ctx, all_keywords);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen i_assert(ctx->sync_ctx->base_uid_validity != 0);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_X_UID] == (size_t)-1) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_UID] = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_printfa(ctx->header, "X-UID: %u\n", ctx->mail.uid);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_STATUS] == (size_t)-1 &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_STATUS] = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_X_STATUS] == (size_t)-1 &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen (ctx->mail.flags & XSTATUS_FLAGS_MASK) != 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_STATUS] = str_len(ctx->header);
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek status_flags_append(ctx, mbox_xstatus_flags);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] == (size_t)-1 && have_keywords) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_printfa(ctx->header, "Content-Length: %"PRIuUOFF_T"\n",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.space -= str_len(ctx->header) - new_hdr_size;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* we should rewrite this header, so offset
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen must be broken if it's used anymore. */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* we don't have enough space for this header, change
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen offset to point back to beginning of headers */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_status(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_STATUS] != (size_t)-1) {
9a1f68e5ab08eabd352d533315cba1c69006e2c1Timo Sirainen status_flags_replace(ctx, ctx->hdr_pos[MBOX_HDR_STATUS],
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_xstatus(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_X_STATUS] != (size_t)-1) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen status_flags_replace(ctx, ctx->hdr_pos[MBOX_HDR_X_STATUS],
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_xkeywords(struct mbox_sync_mail_context *ctx)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipekvoid mbox_sync_update_header(struct mbox_sync_mail_context *ctx,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen memcpy(old_keywords, ctx->mail.keywords, sizeof(old_keywords));
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; i < size; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mail_index_sync_flags_apply(&sync[i], &ctx->mail.flags,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & MBOX_NONRECENT) == 0) {
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainenvoid mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen ctx->mail.flags = (ctx->mail.flags & ~STATUS_FLAGS_MASK) |
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen (mail->flags & STATUS_FLAGS_MASK) | MBOX_NONRECENT;
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen ctx->mail.flags = (ctx->mail.flags & ~XSTATUS_FLAGS_MASK) |
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen if (memcmp(ctx->mail.keywords, mail->keywords,