mbox-sync-update.c revision 33ae95df45c9b5ec51332a6b39eb5322038686b9
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#include "lib.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "buffer.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "str.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "message-parser.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "mbox-sync-private.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void status_flags_append(struct mbox_sync_mail_context *ctx,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen const struct mbox_flag_type *flags_list)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen int i;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; flags_list[i].chr != 0; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & flags_list[i].flag) != 0)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, flags_list[i].chr);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
0db42260be85e797aa9909a29b20296996f52e75Timo Sirainen}
0db42260be85e797aa9909a29b20296996f52e75Timo Sirainen
0db42260be85e797aa9909a29b20296996f52e75Timo Sirainenstatic void status_flags_replace(struct mbox_sync_mail_context *ctx, size_t pos,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen const struct mbox_flag_type *flags_list)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen unsigned char *data;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen size_t size;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen int i, need, have;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->header_first_change > pos)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->header_first_change = pos;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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 need++;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
46e917c9fa05cbe7bddf805d3a9838b61e3960e1Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* how many bytes do we have now? */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen data = buffer_get_modifyable_data(ctx->header, &size);
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek for (have = 0; pos < size; pos++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (data[pos] == '\n')
46e917c9fa05cbe7bddf805d3a9838b61e3960e1Timo Sirainen break;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* see if this is unknown flag for us */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; flags_list[i].chr != 0; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (flags_list[i].chr == data[pos])
b49aa341d28c0eec1229e30baa2f89d5bae52ff8Phil Carmody break;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (flags_list[i].chr != 0)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen have++;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen else {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* save this one */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen data[pos-have] = data[pos];
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen pos -= have;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (need < have)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_delete(ctx->header, pos, have-need);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen else if (need > have) {
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch buffer_copy(ctx->header, pos + (need-have),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->header, pos, (size_t)-1);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
0ca3b9cb0f2a322a25ce7f229dc3d3a0b46be17bTimo Sirainen for (i = 0; i < MBOX_HDR_COUNT; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[i] > pos &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[i] != (size_t)-1)
7a88e726e7300fb0273cb4e55b43c27fbd90bdbdTimo Sirainen ctx->hdr_pos[i] += need - have;
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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 Sirainen *data++ = flags_list[i].chr;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainenstatic void keywords_append(struct mbox_sync_mail_context *ctx,
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainen keywords_mask_t keywords)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen // FIXME
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_add_missing_headers(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen size_t old_hdr_size, new_hdr_size;
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen int i, have_keywords;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen old_hdr_size = ctx->body_offset - ctx->hdr_offset;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen new_hdr_size = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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 str_printfa(ctx->header, "X-IMAPbase: %u %u",
56aa97d74071f3a2987140c2ff1cfd5a59cb35aaTimo Sirainen ctx->sync_ctx->base_uid_validity,
56aa97d74071f3a2987140c2ff1cfd5a59cb35aaTimo Sirainen ctx->sync_ctx->next_uid-1);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen //FIXME:keywords_append(ctx, all_keywords);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, '\n');
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen i_assert(ctx->sync_ctx->base_uid_validity != 0);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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 }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->hdr_pos[MBOX_HDR_STATUS] == (size_t)-1 &&
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen (ctx->mail.flags & STATUS_FLAGS_MASK) != 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.flags |= MBOX_NONRECENT;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->hdr_pos[MBOX_HDR_STATUS] = str_len(ctx->header);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append(ctx->header, "Status: ");
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen status_flags_append(ctx, mbox_status_flags);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, '\n');
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append(ctx->header, "X-Status: ");
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek status_flags_append(ctx, mbox_xstatus_flags);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, '\n');
8c909e451d14075c05d90382cf8eebc4e354f569Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen have_keywords = FALSE;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->mail.keywords[i] != 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen have_keywords = TRUE;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen break;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
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_append(ctx->header, "X-Keywords: ");
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen keywords_append(ctx, ctx->mail.keywords);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, '\n');
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->content_length == (uoff_t)-1) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_printfa(ctx->header, "Content-Length: %"PRIuUOFF_T"\n",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.body_size);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (str_len(ctx->header) != new_hdr_size) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->header_first_change == (size_t)-1)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->header_first_change = new_hdr_size;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->header_last_change = (size_t)-1;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.space -= str_len(ctx->header) - new_hdr_size;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->mail.space > 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* we should rewrite this header, so offset
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen must be broken if it's used anymore. */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.offset = (uoff_t)-1;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen } else {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen /* we don't have enough space for this header, change
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen offset to point back to beginning of headers */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.offset = ctx->hdr_offset;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (ctx->have_eoh)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen str_append_c(ctx->header, '\n');
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_status(struct mbox_sync_mail_context *ctx)
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek{
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 Sirainen mbox_status_flags);
bdb026e2dc8a7c77585ed5ba489f0056df8074d4Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_xstatus(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
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],
16cb5d65265dd0b216542803fd80c4b999ae118eTimo Sirainen mbox_xstatus_flags);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
60d1fdf2c17fd0c7020234590dbd73da81c3ce8fTimo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic void mbox_sync_update_xkeywords(struct mbox_sync_mail_context *ctx)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen // FIXME
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipekvoid mbox_sync_update_header(struct mbox_sync_mail_context *ctx,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen buffer_t *syncs_buf)
c69a177207ed18d0f0210347430a60957136bd6cJosef 'Jeff' Sipek{
5cdb246858f37469fe61351dbc147dabbdde342cTimo Sirainen const struct mail_index_sync_rec *sync;
5cdb246858f37469fe61351dbc147dabbdde342cTimo Sirainen size_t size, i;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen uint8_t old_flags;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen keywords_mask_t old_keywords;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen sync = buffer_get_data(syncs_buf, &size);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen size /= sizeof(*sync);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if (size != 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen old_flags = ctx->mail.flags;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen memcpy(old_keywords, ctx->mail.keywords, sizeof(old_keywords));
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen for (i = 0; i < size; i++) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mail_index_sync_flags_apply(&sync[i], &ctx->mail.flags,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.keywords);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((old_flags & STATUS_FLAGS_MASK) !=
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen (ctx->mail.flags & STATUS_FLAGS_MASK))
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mbox_sync_update_status(ctx);
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen if ((old_flags & XSTATUS_FLAGS_MASK) !=
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen (ctx->mail.flags & XSTATUS_FLAGS_MASK))
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen mbox_sync_update_xstatus(ctx);
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen if (memcmp(old_keywords, ctx->mail.keywords,
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen INDEX_KEYWORDS_BYTE_COUNT) != 0)
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen mbox_sync_update_xkeywords(ctx);
5d4a0dac041964a04405bc6b94de51315ca917afTimo Sirainen } else {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen if ((ctx->mail.flags & MBOX_NONRECENT) == 0) {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.flags |= MBOX_NONRECENT;
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen mbox_sync_update_status(ctx);
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen }
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen }
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen
95d62f8d6d281cc488dc4f488d4388701e559012Josef 'Jeff' Sipek mbox_sync_add_missing_headers(ctx);
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen ctx->updated = TRUE;
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen}
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainenvoid mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen const struct mbox_sync_mail *mail)
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen{
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen if ((ctx->mail.flags & STATUS_FLAGS_MASK) !=
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen (mail->flags & STATUS_FLAGS_MASK) ||
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen (ctx->mail.flags & MBOX_NONRECENT) == 0) {
050acc3755ccc5bcf261a6de3250164a54a0b6f3Timo Sirainen ctx->mail.flags = (ctx->mail.flags & ~STATUS_FLAGS_MASK) |
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen (mail->flags & STATUS_FLAGS_MASK) | MBOX_NONRECENT;
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen mbox_sync_update_status(ctx);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen }
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen if ((ctx->mail.flags & XSTATUS_FLAGS_MASK) !=
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen (mail->flags & XSTATUS_FLAGS_MASK)) {
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen ctx->mail.flags = (ctx->mail.flags & ~XSTATUS_FLAGS_MASK) |
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen (mail->flags & XSTATUS_FLAGS_MASK);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen mbox_sync_update_xstatus(ctx);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen }
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen if (memcmp(ctx->mail.keywords, mail->keywords,
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen INDEX_KEYWORDS_BYTE_COUNT) != 0) {
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen memcpy(ctx->mail.keywords, mail->keywords,
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen INDEX_KEYWORDS_BYTE_COUNT);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen mbox_sync_update_xkeywords(ctx);
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen }
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen
cf35bb040d505e2fc333470850c65029992778a4Timo Sirainen i_assert(ctx->mail.uid == 0 || ctx->mail.uid == mail->uid);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen ctx->mail.uid = mail->uid;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen mbox_sync_add_missing_headers(ctx);
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen