]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added struct mail.lookup_abort, which can be used to abort lookups that can't be...
authorTimo Sirainen <tss@iki.fi>
Wed, 29 Apr 2009 01:01:53 +0000 (21:01 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 29 Apr 2009 01:01:53 +0000 (21:01 -0400)
--HG--
branch : HEAD

src/lib-storage/index/cydir/cydir-mail.c
src/lib-storage/index/dbox/dbox-mail.c
src/lib-storage/index/maildir/maildir-mail.c
src/lib-storage/index/mbox/mbox-mail.c
src/lib-storage/index/raw/raw-mail.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.h
src/lib-storage/mail.c

index 548184d9ef5ac0b846881f58b2ee90f072490c10..9e938e09ccd01a2b82540b2f2e6d7e9f5bb2dadf 100644 (file)
@@ -22,6 +22,9 @@ static int cydir_mail_stat(struct mail *mail, struct stat *st_r)
 {
        const char *path;
 
+       if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
+               return mail_set_aborted(mail);
+
        path = cydir_mail_get_path(mail);
        if (stat(path, st_r) < 0) {
                if (errno == ENOENT)
index 8af53b08042c0d051578220460c01d305c211342..2cf76873a5534364d77706c6b206213f150f87de 100644 (file)
@@ -146,6 +146,9 @@ static int dbox_mail_open(struct dbox_mail *mail,
        uint32_t prev_file_id = 0;
        bool deleted;
 
+       if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
+               return mail_set_aborted(_mail);
+
        do {
                if (mail->open_file == NULL) {
                        if (dbox_mail_lookup(mbox, mbox->ibox.view, _mail->seq,
index 66500a45ec0f636e850fcb7a22a94f6130318192..35561293d0a05d36fca7fb7ce05ce95e1ac8e9b8 100644 (file)
@@ -73,6 +73,9 @@ static int maildir_mail_stat(struct mail *mail, struct stat *st)
        const char *path;
        int fd, ret;
 
+       if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
+               return mail_set_aborted(mail);
+
        if (data->access_part != 0 && data->stream == NULL) {
                /* we're going to open the mail anyway */
                struct istream *input;
index 14481de13e0ce800cd453eb2481f7925db92cc41..41b8112294465e32e4ead9ab759692149025249f 100644 (file)
@@ -41,6 +41,9 @@ static int mbox_mail_seek(struct index_mail *mail)
        if (mail->mail.mail.expunged || mbox->syncing)
                return -1;
 
+       if (mail->mail.mail.lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
+               return mail_set_aborted(&mail->mail.mail);
+
        if (mbox->mbox_stream != NULL &&
            istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
                /* clear the corruption by forcing a full resync */
index 2a1736b19677d8aaea1be4a011dd830df5746216..9fc00f17b1432620ff01ec0055a49d572a86d965 100644 (file)
@@ -14,6 +14,9 @@ static int raw_mail_stat(struct mail *mail)
        struct raw_mailbox *mbox = (struct raw_mailbox *)mail->box;
        const struct stat *st;
 
+       if (mail->lookup_abort == MAIL_LOOKUP_ABORT_NOT_IN_CACHE)
+               return mail_set_aborted(mail);
+
        st = i_stream_stat(mbox->input, TRUE);
        if (st == NULL) {
                mail_storage_set_critical(mail->box->storage,
index b5d4e56de0c644071a3208bd50f5ff3f7138cffe..bcde88c8d498a77d1cc1d73631e8d131226ee663 100644 (file)
@@ -385,6 +385,7 @@ bool mail_storage_set_error_from_errno(struct mail_storage *storage);
 
 const char *mail_generate_guid_string(void);
 void mail_generate_guid_128(uint8_t guid[16]);
+int mail_set_aborted(struct mail *mail);
 void mail_set_expunged(struct mail *mail);
 void mailbox_set_deleted(struct mailbox *box);
 
index 8f84f7c320c96ecb598ec537ca245b4b998a9319..b1f0dc66897a4c4fa5e9c8e397288adc03ed8266 100644 (file)
@@ -196,6 +196,15 @@ struct mailbox_sync_rec {
        enum mailbox_sync_type type;
 };
 
+enum mail_lookup_abort {
+       /* Perform everything no matter what it takes */
+       MAIL_LOOKUP_ABORT_NEVER = 0,
+       /* Abort if the operation would require reading message header/body */
+       MAIL_LOOKUP_ABORT_READ_MAIL,
+       /* Abort if the operation can't be done fully using cache file */
+       MAIL_LOOKUP_ABORT_NOT_IN_CACHE
+};
+
 struct mail {
        /* always set */
        struct mailbox *box;
@@ -205,6 +214,8 @@ struct mail {
        unsigned int expunged:1;
        unsigned int has_nuls:1; /* message data is known to contain NULs */
        unsigned int has_no_nuls:1; /* -''- known to not contain NULs */
+
+       enum mail_lookup_abort lookup_abort;
 };
 
 struct mail_storage_callbacks {
index 3437249f29cb6d87d5a6c8170fba7cb6c9f483bc..ddc3d05c18327f6c6a2e3224606017b9a44f15b4 100644 (file)
@@ -152,11 +152,20 @@ int mail_get_header_stream(struct mail *mail,
        return p->v.get_header_stream(mail, headers, stream_r);
 }
 
+int mail_set_aborted(struct mail *mail)
+{
+       mail_storage_set_error(mail->box->storage, MAIL_ERROR_NOTPOSSIBLE,
+                              "Mail field not cached");
+       return -1;
+}
+
 int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
                    struct message_size *body_size, struct istream **stream_r)
 {
        struct mail_private *p = (struct mail_private *)mail;
 
+       if (mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
+               return mail_set_aborted(mail);
        return p->v.get_stream(mail, hdr_size, body_size, stream_r);
 }