dovecot-1.2: Added struct mail.lookup_abort, which can be used t...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 29 00:21:20 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/5611bba3548b
changeset: 8981:5611bba3548b
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 28 17:20:19 2009 -0400
description:
Added struct mail.lookup_abort, which can be used to abort lookups that can't be done using cache.

diffstat:

8 files changed, 38 insertions(+), 1 deletion(-)
src/lib-storage/index/cydir/cydir-mail.c     |    3 +++
src/lib-storage/index/dbox/dbox-mail.c       |    6 +++++-
src/lib-storage/index/maildir/maildir-mail.c |    3 +++
src/lib-storage/index/mbox/mbox-mail.c       |    3 +++
src/lib-storage/index/raw/raw-mail.c         |    3 +++
src/lib-storage/mail-storage-private.h       |    1 +
src/lib-storage/mail-storage.h               |   11 +++++++++++
src/lib-storage/mail.c                       |    9 +++++++++

diffs (142 lines):

diff -r c8de2237478f -r 5611bba3548b src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -21,6 +21,9 @@ static int cydir_mail_stat(struct mail *
 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) {
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -67,10 +67,14 @@ static int
 static int
 dbox_mail_metadata_seek(struct dbox_mail *mail, struct dbox_file **file_r)
 {
+	struct mail *_mail = &mail->imail.mail.mail;
 	uoff_t offset;
 	bool expunged;
 	int ret;
 
+	if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER)
+		return mail_set_aborted(_mail);
+
 	if (dbox_mail_lookup(mail, &offset, file_r) < 0)
 		return -1;
 
@@ -82,7 +86,7 @@ dbox_mail_metadata_seek(struct dbox_mail
 		return -1;
 	}
 	if (expunged) {
-		mail_set_expunged(&mail->imail.mail.mail);
+		mail_set_expunged(_mail);
 		return -1;
 	}
 	return 0;
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -72,6 +72,9 @@ static int maildir_mail_stat(struct mail
 	struct index_mail_data *data = &((struct index_mail *)mail)->data;
 	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 */
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -40,6 +40,9 @@ static int mbox_mail_seek(struct index_m
 
 	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)) {
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/index/raw/raw-mail.c
--- a/src/lib-storage/index/raw/raw-mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/index/raw/raw-mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -13,6 +13,9 @@ static int raw_mail_stat(struct mail *ma
 {
 	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) {
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/mail-storage-private.h	Tue Apr 28 17:20:19 2009 -0400
@@ -376,6 +376,7 @@ bool mail_storage_set_error_from_errno(s
 bool mail_storage_set_error_from_errno(struct mail_storage *storage);
 
 const char *mail_generate_guid_string(void);
+int mail_set_aborted(struct mail *mail);
 void mail_set_expunged(struct mail *mail);
 void mailbox_set_deleted(struct mailbox *box);
 
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/mail-storage.h	Tue Apr 28 17:20:19 2009 -0400
@@ -213,6 +213,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;
@@ -222,6 +231,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 {
diff -r c8de2237478f -r 5611bba3548b src/lib-storage/mail.c
--- a/src/lib-storage/mail.c	Thu Apr 23 12:01:40 2009 -0400
+++ b/src/lib-storage/mail.c	Tue Apr 28 17:20:19 2009 -0400
@@ -151,11 +151,20 @@ int mail_get_header_stream(struct 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);
 }
 


More information about the dovecot-cvs mailing list