while (rec != NULL) {
index_flags = mail_cache_get_index_flags(index->cache, rec);
if ((index_flags & MAIL_INDEX_FLAG_DIRTY) != 0) {
- if (!mail_cache_update_index_flags(index->cache, rec, index_flags))
+ index_flags &= ~MAIL_INDEX_FLAG_DIRTY;
+ if (!mail_cache_update_index_flags(index->cache,
+ rec, index_flags))
return FALSE;
}
strerror(output->stream_errno));
failed = TRUE;
} else if (input->v_offset < end_offset) {
- /* fsck should have noticed it.. */
+ /* sync should have noticed it.. */
index_set_error(index, "Error rewriting mbox file %s: "
"Unexpected end of file", index->mailbox_path);
failed = TRUE;
static int mbox_write_header(struct mail_index *index,
struct mail_index_record *rec, unsigned int seq,
struct istream *input, struct ostream *output,
- uoff_t end_offset,
uoff_t *hdr_input_size, uoff_t body_size)
{
/* We need to update fields that define message flags. Standard fields
uoff_t offset;
int force_filler;
- if (input->v_offset >= end_offset) {
- /* fsck should have noticed it.. */
- index_set_error(index, "Error rewriting mbox file %s: "
- "Unexpected end of file", index->mailbox_path);
- return FALSE;
- }
-
t_push();
/* parse the header, write the fields we don't want to change */
/* write header, updating flag fields */
if (!mbox_write_header(index, rec, seq, input, output,
- offset, &hdr_size, body_size)) {
+ &hdr_size, body_size)) {
failed = TRUE;
break;
}
MODIFY_REPLACE,
ctx.flags, TRUE))
return FALSE;
+ } else if (rec->msg_flags == ctx.flags) {
+ /* flags are same, it's not dirty anymore */
+ index_flags &= ~MAIL_INDEX_FLAG_DIRTY;
+ mail_cache_update_index_flags(index->cache,
+ rec, index_flags);
} else {
- if (rec->msg_flags != ctx.flags)
- *dirty = TRUE;
+ *dirty = TRUE;
}
/* update location */
unsigned int seq;
int dirty;
+ if (mail_cache_lock(index->cache, FALSE) <= 0)
+ return FALSE;
+ mail_cache_unlock_later(index->cache);
+
mbox_skip_empty_lines(input);
/* first make sure we start with a "From " line. If file is too