[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-save.c, 1.75,
1.76 mbox-sync-parse.c, 1.35, 1.36 mbox-sync-private.h, 1.45,
1.46 mbox-sync-update.c, 1.28, 1.29 mbox-sync.c, 1.142, 1.143
cras at dovecot.org
cras at dovecot.org
Tue Mar 29 22:27:40 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv30549/lib-storage/index/mbox
Modified Files:
mbox-save.c mbox-sync-parse.c mbox-sync-private.h
mbox-sync-update.c mbox-sync.c
Log Message:
Recent flag handling cleanups. Added some comments.
Index: mbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- mbox-save.c 29 Mar 2005 13:33:08 -0000 1.75
+++ mbox-save.c 29 Mar 2005 19:27:37 -0000 1.76
@@ -203,10 +203,12 @@
{
int i;
+ flags ^= MBOX_NONRECENT_KLUDGE;
for (i = 0; flags_list[i].chr != 0; i++) {
if ((flags & flags_list[i].flag) != 0)
str_append_c(str, flags_list[i].chr);
}
+ flags ^= MBOX_NONRECENT_KLUDGE;
}
static void mbox_save_append_flag_headers(string_t *str, enum mail_flags flags)
@@ -364,8 +366,7 @@
ibox->mbox_ext_idx, &offset, NULL);
ctx->next_uid++;
}
- mbox_save_append_flag_headers(ctx->headers,
- save_flags ^ MBOX_NONRECENT);
+ mbox_save_append_flag_headers(ctx->headers, save_flags);
mbox_save_append_keyword_headers(ctx, keywords);
str_append_c(ctx->headers, '\n');
Index: mbox-sync-parse.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mbox-sync-parse.c 18 Jan 2005 23:18:14 -0000 1.35
+++ mbox-sync-parse.c 29 Mar 2005 19:27:37 -0000 1.36
@@ -26,7 +26,7 @@
struct mbox_flag_type mbox_status_flags[] = {
{ 'R', MAIL_SEEN },
- { 'O', MBOX_NONRECENT },
+ { 'O', MBOX_NONRECENT_KLUDGE },
{ 0, 0 }
};
@@ -83,10 +83,12 @@
{
size_t i;
+ ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
for (i = 0; i < hdr->full_value_len; i++) {
ctx->mail.flags |=
mbox_flag_find(flags_list, hdr->full_value[i]);
}
+ ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
}
static int parse_status(struct mbox_sync_mail_context *ctx,
@@ -318,6 +320,7 @@
int i, ret;
ctx->hdr_offset = ctx->mail.offset;
+ ctx->mail.flags = MAIL_RECENT; /* default to having recent flag */
ctx->header_first_change = (size_t)-1;
ctx->header_last_change = 0;
Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- mbox-sync-private.h 29 Mar 2005 10:30:20 -0000 1.45
+++ mbox-sync-private.h 29 Mar 2005 19:27:37 -0000 1.46
@@ -27,10 +27,13 @@
MBOX_HDR_COUNT
};
-#define MBOX_NONRECENT MAIL_RECENT /* kludgy */
+/* kludgy. swap MAIL_RECENT with MBOX_NONRECENT_KLUDGE when writing Status
+ header, because 'O' flag means non-recent but internally we want to use
+ recent flag. */
+#define MBOX_NONRECENT_KLUDGE MAIL_RECENT
#define MBOX_EXPUNGED 0x40
-#define STATUS_FLAGS_MASK (MAIL_SEEN|MBOX_NONRECENT)
+#define STATUS_FLAGS_MASK (MAIL_SEEN|MBOX_NONRECENT_KLUDGE)
#define XSTATUS_FLAGS_MASK (MAIL_ANSWERED|MAIL_FLAGGED|MAIL_DRAFT|MAIL_DELETED)
extern struct mbox_flag_type mbox_status_flags[];
extern struct mbox_flag_type mbox_xstatus_flags[];
@@ -135,6 +138,7 @@
uoff_t end_offset, off_t move_diff, uoff_t extra_space,
uint32_t first_seq, uint32_t last_seq);
+void mbox_sync_apply_index_syncs(array_t *syncs_arr, uint8_t *flags);
int mbox_sync_seek(struct mbox_sync_context *sync_ctx, uoff_t from_offset);
int mbox_move(struct mbox_sync_context *sync_ctx,
uoff_t dest, uoff_t source, uoff_t size);
Index: mbox-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- mbox-sync-update.c 27 Mar 2005 11:25:47 -0000 1.28
+++ mbox-sync-update.c 29 Mar 2005 19:27:37 -0000 1.29
@@ -14,10 +14,13 @@
{
int i;
+ /* kludgy kludgy */
+ ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
for (i = 0; flags_list[i].chr != 0; i++) {
if ((ctx->mail.flags & flags_list[i].flag) != 0)
str_append_c(ctx->header, flags_list[i].chr);
}
+ ctx->mail.flags ^= MBOX_NONRECENT_KLUDGE;
}
void mbox_sync_move_buffer(struct mbox_sync_mail_context *ctx,
@@ -273,20 +276,7 @@
if (count != 0) {
old_keywords_idx = ctx->mail.keywords_idx;
-
- for (i = 0; i < count; i++) {
- if (syncs[i].type == MAIL_INDEX_SYNC_TYPE_FLAGS) {
- mail_index_sync_flags_apply(&syncs[i],
- &ctx->mail.flags);
- }
-
- // FIXME: keywords
- }
-
- /* keep our old recent flag. especially because we use it
- negatively as non-recent */
- ctx->mail.flags = (ctx->mail.flags & ~MAIL_RECENT) |
- (old_flags & MAIL_RECENT);
+ mbox_sync_apply_index_syncs(syncs_arr, &ctx->mail.flags);
if ((old_flags & XSTATUS_FLAGS_MASK) !=
(ctx->mail.flags & XSTATUS_FLAGS_MASK))
@@ -297,7 +287,7 @@
}
if (!ctx->sync_ctx->ibox->keep_recent)
- ctx->mail.flags |= MBOX_NONRECENT;
+ ctx->mail.flags &= ~MAIL_RECENT;
if ((old_flags & STATUS_FLAGS_MASK) !=
(ctx->mail.flags & STATUS_FLAGS_MASK))
@@ -314,11 +304,11 @@
{
if ((ctx->mail.flags & STATUS_FLAGS_MASK) !=
(mail->flags & STATUS_FLAGS_MASK) ||
- (ctx->mail.flags & MBOX_NONRECENT) == 0) {
+ (ctx->mail.flags & MAIL_RECENT) != 0) {
ctx->mail.flags = (ctx->mail.flags & ~STATUS_FLAGS_MASK) |
(mail->flags & STATUS_FLAGS_MASK);
if (!ctx->sync_ctx->ibox->keep_recent)
- ctx->mail.flags |= MBOX_NONRECENT;
+ ctx->mail.flags &= ~MAIL_RECENT;
mbox_sync_update_status(ctx);
}
if ((ctx->mail.flags & XSTATUS_FLAGS_MASK) !=
Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -d -r1.142 -r1.143
--- mbox-sync.c 29 Mar 2005 13:33:08 -0000 1.142
+++ mbox-sync.c 29 Mar 2005 19:27:37 -0000 1.143
@@ -127,7 +127,7 @@
mail_ctx->content_length);
i_assert(mail_ctx->mail.body_size < OFF_T_MAX);
- if ((mail_ctx->mail.flags & MBOX_NONRECENT) == 0 && !mail_ctx->pseudo) {
+ if ((mail_ctx->mail.flags & MAIL_RECENT) != 0 && !mail_ctx->pseudo) {
if (!sync_ctx->ibox->keep_recent) {
/* need to add 'O' flag to Status-header */
mail_ctx->need_rewrite = TRUE;
@@ -205,7 +205,7 @@
return 0;
}
-static void mbox_sync_apply_index_syncs(array_t *syncs_arr, uint8_t *flags)
+void mbox_sync_apply_index_syncs(array_t *syncs_arr, uint8_t *flags)
{
ARRAY_SET_TYPE(syncs_arr, struct mail_index_sync_rec);
const struct mail_index_sync_rec *syncs;
@@ -342,15 +342,16 @@
struct mbox_sync_mail *mail = &mail_ctx->mail;
uint8_t idx_flags, mbox_flags;
+ mbox_flags = mail->flags & MAIL_FLAGS_MASK;
+
+ if (mail_ctx->dirty)
+ mbox_flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
+ else if (!sync_ctx->delay_writes)
+ mbox_flags &= ~MAIL_INDEX_MAIL_FLAG_DIRTY;
+
if (rec == NULL) {
/* new message */
mail_index_append(sync_ctx->t, mail->uid, &sync_ctx->idx_seq);
- mbox_flags = mail->flags & (MAIL_FLAGS_MASK^MAIL_RECENT);
- if (mail_ctx->dirty)
- mbox_flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
- if (sync_ctx->ibox->keep_recent &&
- (mail->flags & MBOX_NONRECENT) == 0)
- mbox_flags |= MAIL_RECENT;
mail_index_update_flags(sync_ctx->t, sync_ctx->idx_seq,
MODIFY_REPLACE, mbox_flags);
@@ -360,29 +361,26 @@
mail_ctx->hdr_md5_sum, NULL);
}
} else {
- /* see if flags changed */
+ /* see if we need to update flags in index file. the flags in
+ sync records are automatically applied to rec->flags at the
+ end of index syncing, so calculate those new flags first */
idx_flags = rec->flags;
mbox_sync_apply_index_syncs(&sync_ctx->syncs, &idx_flags);
if ((idx_flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) {
- /* flags are dirty, ignore whatever was in the file.
- but remove recent flag if needed. */
- mbox_flags = idx_flags;
- if (!sync_ctx->ibox->keep_recent)
- mbox_flags &= ~MAIL_RECENT;
+ /* flags are dirty. ignore whatever was in the mbox,
+ but update recent flag state if needed. */
+ mbox_flags &= MAIL_RECENT;
+ mbox_flags |= idx_flags & ~MAIL_RECENT;
} else {
- mbox_flags = (rec->flags & ~MAIL_FLAGS_MASK) |
- (mail->flags & MAIL_FLAGS_MASK);
- mbox_flags ^= MAIL_RECENT;
+ /* keep index's internal flags */
+ mbox_flags &= MAIL_FLAGS_MASK;
+ mbox_flags |= idx_flags & ~MAIL_FLAGS_MASK;
}
- if (mail_ctx->dirty)
- mbox_flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
- else if (!sync_ctx->delay_writes)
- mbox_flags &= ~MAIL_INDEX_MAIL_FLAG_DIRTY;
-
if ((idx_flags & ~MAIL_INDEX_MAIL_FLAG_DIRTY) ==
(mbox_flags & ~MAIL_INDEX_MAIL_FLAG_DIRTY)) {
+ /* all flags are same, except possibly dirty flag */
if (idx_flags != mbox_flags) {
/* dirty flag state changed */
int dirty = (mbox_flags &
@@ -394,6 +392,7 @@
}
} else if ((idx_flags & ~MAIL_RECENT) !=
(mbox_flags & ~MAIL_RECENT)) {
+ /* flags other than MAIL_RECENT have changed */
mail_index_update_flags(sync_ctx->t, sync_ctx->idx_seq,
MODIFY_REPLACE, mbox_flags);
} else if (((idx_flags ^ mbox_flags) & MAIL_RECENT) != 0) {
More information about the dovecot-cvs
mailing list