]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: require MAIL_STORAGE_CLASS_FLAG_STUBS when caching
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Tue, 22 Nov 2016 15:21:24 +0000 (10:21 -0500)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 23 Nov 2016 11:38:01 +0000 (13:38 +0200)
If we are going to be using the storage for caching, we should check that
the storage actually supports mail stubs.

src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index cb268cc187a464f66022aec0dec07d8bb146b04a..2c4ce1d7305bd6208e67a50703ca5f33d18ba043 100644 (file)
@@ -405,7 +405,8 @@ struct mail_storage sdbox_storage = {
        .class_flags = MAIL_STORAGE_CLASS_FLAG_FILE_PER_MSG |
                MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUIDS |
                MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS |
-               MAIL_STORAGE_CLASS_FLAG_BINARY_DATA,
+               MAIL_STORAGE_CLASS_FLAG_BINARY_DATA |
+               MAIL_STORAGE_CLASS_FLAG_STUBS,
 
        .v = {
                 NULL,
index 9874152aa5155c05cf6cb14b6d5621754fc9e227..39b738ff9918ef8bd1cb17ba55a3764899fdedcb 100644 (file)
@@ -81,7 +81,9 @@ enum mail_storage_class_flags {
        MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUID128 = 0x200,
        /* Storage deletes all files internally - mailbox list's
           delete_mailbox() shouldn't delete anything itself. */
-       MAIL_STORAGE_CLASS_FLAG_NO_LIST_DELETES = 0x400
+       MAIL_STORAGE_CLASS_FLAG_NO_LIST_DELETES = 0x400,
+       /* Storage supports stubs (used for caching purposes). */
+       MAIL_STORAGE_CLASS_FLAG_STUBS = 0x800,
 };
 
 struct mail_binary_cache {
index 5167a6d87bbc65e48e1d0b18a5a23112da05728f..6963c50c70006d49700a7c63d1b41effcd4ab68b 100644 (file)
@@ -1157,6 +1157,14 @@ static bool mailbox_try_undelete(struct mailbox *box)
 
 int mailbox_open(struct mailbox *box)
 {
+       /* check that the storage supports stubs if require them */
+       if (((box->flags & MAILBOX_FLAG_USE_STUBS) != 0) &&
+           ((box->storage->storage_class->class_flags & MAIL_STORAGE_CLASS_FLAG_STUBS) == 0)) {
+               mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
+                                      "Mailbox does not support mail stubs");
+               return -1;
+       }
+
        if (mailbox_open_full(box, NULL) < 0) {
                if (!box->mailbox_deleted)
                        return -1;