# HG changeset patch # User Timo Sirainen # Date 1032777740 -10800 # Node ID d66aa1f1fb2d886bf3980c0faf02ce9c3b051a9a # Parent c6c0e376008f8dc865a382013cf3da255aa94046 Added fast-flag for mailbox opening, which doesn't do any index compressing or cache updating. This flag is set when mailbox is opened by APPEND, COPY or STATUS (ie. not SELECT/EXAMINE). diff -r c6c0e376008f -r d66aa1f1fb2d src/imap/cmd-append.c --- a/src/imap/cmd-append.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/imap/cmd-append.c Mon Sep 23 13:42:20 2002 +0300 @@ -113,7 +113,7 @@ return TRUE; box = client->storage->open_mailbox(client->storage, - mailbox, FALSE); + mailbox, FALSE, TRUE); if (box == NULL) { client_send_storage_error(client); return TRUE; diff -r c6c0e376008f -r d66aa1f1fb2d src/imap/cmd-copy.c --- a/src/imap/cmd-copy.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/imap/cmd-copy.c Mon Sep 23 13:42:20 2002 +0300 @@ -20,7 +20,7 @@ return TRUE; destbox = client->storage->open_mailbox(client->storage, - mailbox, FALSE); + mailbox, FALSE, TRUE); if (destbox == NULL) { client_send_storage_error(client); return TRUE; diff -r c6c0e376008f -r d66aa1f1fb2d src/imap/cmd-select.c --- a/src/imap/cmd-select.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/imap/cmd-select.c Mon Sep 23 13:42:20 2002 +0300 @@ -47,7 +47,8 @@ client->mailbox->close(client->mailbox); client->mailbox = client->storage->open_mailbox(client->storage, - mailbox, readonly); + mailbox, readonly, + FALSE); if (client->mailbox == NULL) { client_send_storage_error(client); return TRUE; diff -r c6c0e376008f -r d66aa1f1fb2d src/imap/cmd-status.c --- a/src/imap/cmd-status.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/imap/cmd-status.c Mon Sep 23 13:42:20 2002 +0300 @@ -63,7 +63,7 @@ } else { /* open the mailbox */ box = client->storage->open_mailbox(client->storage, - mailbox, FALSE); + mailbox, FALSE, TRUE); if (box == NULL) return FALSE; } diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-index/mail-index-open.c --- a/src/lib-index/mail-index-open.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-index/mail-index-open.c Mon Sep 23 13:42:20 2002 +0300 @@ -152,7 +152,7 @@ return TRUE; } -static int index_open_and_fix(MailIndex *index, int update_recent) +static int index_open_and_fix(MailIndex *index, int update_recent, int fast) { int rebuild; @@ -200,7 +200,7 @@ return FALSE; } - if (index->header->flags & MAIL_INDEX_FLAG_COMPRESS) { + if (fast && (index->header->flags & MAIL_INDEX_FLAG_COMPRESS)) { /* remove deleted blocks from index file */ if (!mail_index_compress(index)) return FALSE; @@ -216,13 +216,13 @@ if (!index->sync(index)) return FALSE; - if (index->header->flags & MAIL_INDEX_FLAG_CACHE_FIELDS) { + if (fast && (index->header->flags & MAIL_INDEX_FLAG_CACHE_FIELDS)) { /* need to update cached fields */ if (!mail_index_update_cache(index)) return FALSE; } - if (index->header->flags & MAIL_INDEX_FLAG_COMPRESS_DATA) { + if (fast && (index->header->flags & MAIL_INDEX_FLAG_COMPRESS_DATA)) { /* remove unused space from index data file. keep after cache_fields which may move data and create unused space.. */ @@ -240,7 +240,7 @@ } static int mail_index_open_file(MailIndex *index, const char *path, - int update_recent) + int update_recent, int fast) { MailIndexHeader hdr; int fd; @@ -276,7 +276,7 @@ index->filepath = i_strdup(path); index->indexid = hdr.indexid; - if (!index_open_and_fix(index, update_recent)) { + if (!index_open_and_fix(index, update_recent, fast)) { mail_index_close(index); return FALSE; } @@ -477,7 +477,7 @@ hdr->next_uid = 1; } -int mail_index_open(MailIndex *index, int update_recent) +int mail_index_open(MailIndex *index, int update_recent, int fast) { const char *name, *path; @@ -491,20 +491,20 @@ return FALSE; path = t_strconcat(index->dir, "/", name, NULL); - if (!mail_index_open_file(index, path, update_recent)) + if (!mail_index_open_file(index, path, update_recent, fast)) return FALSE; index->opened = TRUE; return TRUE; } -int mail_index_open_or_create(MailIndex *index, int update_recent) +int mail_index_open_or_create(MailIndex *index, int update_recent, int fast) { int failed, dir_unlocked; i_assert(!index->opened); - if (mail_index_open(index, update_recent)) + if (mail_index_open(index, update_recent, fast)) return TRUE; /* index wasn't found or it was broken. lock the directory and check @@ -513,7 +513,7 @@ if (!mail_index_lock_dir(index, MAIL_LOCK_EXCLUSIVE)) return FALSE; - if (mail_index_open(index, update_recent)) { + if (mail_index_open(index, update_recent, fast)) { dir_unlocked = FALSE; failed = FALSE; } else { diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-index/mail-index.h --- a/src/lib-index/mail-index.h Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-index/mail-index.h Mon Sep 23 13:42:20 2002 +0300 @@ -165,8 +165,9 @@ (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size) struct _MailIndex { - int (*open)(MailIndex *index, int update_recent); - int (*open_or_create)(MailIndex *index, int update_recent); + /* If fast is TRUE, compressing and cache updates are not performed. */ + int (*open)(MailIndex *index, int update_recent, int fast); + int (*open_or_create)(MailIndex *index, int update_recent, int fast); /* Free index from memory. */ void (*free)(MailIndex *index); @@ -355,8 +356,8 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0 /* defaults - same as above but prefixed with mail_index_. */ -int mail_index_open(MailIndex *index, int update_recent); -int mail_index_open_or_create(MailIndex *index, int update_recent); +int mail_index_open(MailIndex *index, int update_recent, int fast); +int mail_index_open_or_create(MailIndex *index, int update_recent, int fast); int mail_index_set_lock(MailIndex *index, MailLockType lock_type); int mail_index_try_lock(MailIndex *index, MailLockType lock_type); int mail_index_fsck(MailIndex *index); diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-storage/index/index-storage.c --- a/src/lib-storage/index/index-storage.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-storage/index/index-storage.c Mon Sep 23 13:42:20 2002 +0300 @@ -8,14 +8,14 @@ IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box, MailIndex *index, const char *name, - int readonly) + int readonly, int fast) { IndexMailbox *ibox; i_assert(name != NULL); /* open the index first */ - if (!index->open_or_create(index, !readonly)) { + if (!index->open_or_create(index, !readonly, fast)) { mail_storage_set_internal_error(storage); index->free(index); return NULL; diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-storage/index/index-storage.h --- a/src/lib-storage/index/index-storage.h Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-storage/index/index-storage.h Mon Sep 23 13:42:20 2002 +0300 @@ -26,7 +26,7 @@ IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box, MailIndex *index, const char *name, - int readonly); + int readonly, int fast); void index_storage_close(Mailbox *box); int index_storage_sync_if_possible(IndexMailbox *ibox); diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-storage/index/maildir/maildir-storage.c --- a/src/lib-storage/index/maildir/maildir-storage.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-storage/index/maildir/maildir-storage.c Mon Sep 23 13:42:20 2002 +0300 @@ -123,7 +123,7 @@ } static Mailbox *maildir_open(MailStorage *storage, const char *name, - int readonly) + int readonly, int fast) { IndexMailbox *ibox; const char *path; @@ -131,7 +131,8 @@ path = t_strconcat(storage->dir, "/.", name, NULL); ibox = index_storage_init(storage, &maildir_mailbox, - maildir_index_alloc(path), name, readonly); + maildir_index_alloc(path), name, readonly, + fast); if (ibox != NULL) ibox->expunge_locked = maildir_expunge_locked; return (Mailbox *) ibox; @@ -150,7 +151,7 @@ } static Mailbox *maildir_open_mailbox(MailStorage *storage, const char *name, - int readonly) + int readonly, int fast) { struct stat st; char path[1024]; @@ -161,7 +162,7 @@ if (strcmp(name, "INBOX") == 0) { if (!verify_inbox(storage, storage->dir)) return NULL; - return maildir_open(storage, "INBOX", readonly); + return maildir_open(storage, "INBOX", readonly, fast); } if (!maildir_is_valid_name(storage, name)) { @@ -174,7 +175,7 @@ /* exists - make sure the required directories are also there */ (void)create_maildir(path, TRUE); - return maildir_open(storage, name, readonly); + return maildir_open(storage, name, readonly, fast); } else if (errno == ENOENT) { mail_storage_set_error(storage, "Mailbox doesn't exist: %s", name); diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-storage/index/mbox/mbox-storage.c --- a/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 23 13:42:20 2002 +0300 @@ -149,7 +149,8 @@ (void)create_mbox_index_dirs(path, TRUE); } -static Mailbox *mbox_open(MailStorage *storage, const char *name, int readonly) +static Mailbox *mbox_open(MailStorage *storage, const char *name, + int readonly, int fast) { IndexMailbox *ibox; const char *path, *index_dir; @@ -162,14 +163,14 @@ ibox = index_storage_init(storage, &mbox_mailbox, mbox_index_alloc(index_dir, path), - name, readonly); + name, readonly, fast); if (ibox != NULL) ibox->expunge_locked = mbox_expunge_locked; return (Mailbox *) ibox; } static Mailbox *mbox_open_mailbox(MailStorage *storage, const char *name, - int readonly) + int readonly, int fast) { struct stat st; char path[1024]; @@ -180,7 +181,7 @@ if (strcasecmp(name, "INBOX") == 0) { /* make sure inbox exists */ verify_inbox(storage); - return mbox_open(storage, "inbox", readonly); + return mbox_open(storage, "inbox", readonly, fast); } if (!mbox_is_valid_name(storage, name)) { @@ -193,7 +194,7 @@ /* exists - make sure the required directories are also there */ (void)create_mbox_index_dirs(path, TRUE); - return mbox_open(storage, name, readonly); + return mbox_open(storage, name, readonly, fast); } else if (errno == ENOENT) { mail_storage_set_error(storage, "Mailbox doesn't exist: %s", name); diff -r c6c0e376008f -r d66aa1f1fb2d src/lib-storage/mail-storage.h --- a/src/lib-storage/mail-storage.h Mon Sep 23 13:30:21 2002 +0300 +++ b/src/lib-storage/mail-storage.h Mon Sep 23 13:42:20 2002 +0300 @@ -71,9 +71,11 @@ int (*autodetect)(const char *data); /* Open a mailbox. If readonly is TRUE, mailbox must not be - modified in any way even when it's asked. */ + modified in any way even when it's asked. If fast is TRUE, + any extra time consuming operations shouldn't be performed + (eg. when opening mailbox just for STATUS). */ Mailbox *(*open_mailbox)(MailStorage *storage, const char *name, - int readonly); + int readonly, int fast); /* name is allowed to contain multiple new hierarchy levels */ int (*create_mailbox)(MailStorage *storage, const char *name);