dovecot-1.1: Getting "next message's offset" was broken if a new...
dovecot at dovecot.org
dovecot at dovecot.org
Sun May 4 21:55:45 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/80d827b411c8
changeset: 7489:80d827b411c8
user: Timo Sirainen <tss at iki.fi>
date: Sun May 04 21:55:41 2008 +0300
description:
Getting "next message's offset" was broken if a new message had been added
recently. This broke message size calculations.
diffstat:
1 file changed, 28 insertions(+), 13 deletions(-)
src/lib-storage/index/mbox/mbox-mail.c | 41 +++++++++++++++++++++-----------
diffs (58 lines):
diff -r 9bef11f4faf6 -r 80d827b411c8 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c Sun May 04 21:54:27 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c Sun May 04 21:55:41 2008 +0300
@@ -170,26 +170,41 @@ mbox_mail_get_next_offset(struct index_m
mbox_mail_get_next_offset(struct index_mail *mail, uoff_t *next_offset_r)
{
struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
- struct mail *_mail = &mail->mail.mail;
+ struct mail_index_view *view;
const struct mail_index_header *hdr;
+ uint32_t seq;
+ int trailer_size;
+ bool ret;
hdr = mail_index_get_header(mail->trans->trans_view);
- if (_mail->seq >= hdr->messages_count) {
- if (_mail->seq != hdr->messages_count) {
- /* we're appending a new message */
- return FALSE;
- }
-
+ if (mail->mail.mail.seq > hdr->messages_count) {
+ /* we're appending a new message */
+ return FALSE;
+ }
+
+ /* We can't really trust trans_view. The next message may already be
+ expugned from it. hdr.sync_size may also be updated, but
+ hdr.messages_count not. So refresh the index to get the latest
+ changes and get the next message's offset using a new view. */
+ (void)mail_index_refresh(mail->ibox->index);
+
+ view = mail_index_view_open(mail->ibox->index);
+ hdr = mail_index_get_header(view);
+ if (!mail_index_lookup_seq(view, mail->mail.mail.uid, &seq))
+ i_panic("Message unexpectedly expunged from index");
+
+ if (seq == hdr->messages_count) {
/* last message, use the synced mbox size */
- int trailer_size;
-
trailer_size = (mbox->storage->storage.flags &
MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? 2 : 1;
*next_offset_r = hdr->sync_size - trailer_size;
- return TRUE;
- }
- return mbox_file_lookup_offset(mbox, mail->trans->trans_view,
- _mail->seq + 1, next_offset_r);
+ ret = TRUE;
+ } else {
+ ret = mbox_file_lookup_offset(mbox, view, seq + 1,
+ next_offset_r) > 0;
+ }
+ mail_index_view_close(&view);
+ return ret;
}
static int mbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
More information about the dovecot-cvs
mailing list