dovecot-2.0: Added struct mail.lookup_abort, which can be used t...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 29 04:08:54 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/03a5f5cf6b4c
changeset: 9161:03a5f5cf6b4c
user: Timo Sirainen <tss at iki.fi>
date: Tue Apr 28 21:01:53 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, 36 insertions(+)
src/lib-storage/index/cydir/cydir-mail.c | 3 +++
src/lib-storage/index/dbox/dbox-mail.c | 3 +++
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 (128 lines):
diff -r 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-mail.c Tue Apr 28 21:01:53 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 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-mail.c Tue Apr 28 21:01:53 2009 -0400
@@ -145,6 +145,9 @@ static int dbox_mail_open(struct dbox_ma
struct mail *_mail = &mail->imail.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) {
diff -r 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-mail.c Tue Apr 28 21:01:53 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 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-mail.c Tue Apr 28 21:01:53 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 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/index/raw/raw-mail.c
--- a/src/lib-storage/index/raw/raw-mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/index/raw/raw-mail.c Tue Apr 28 21:01:53 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 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/mail-storage-private.h Tue Apr 28 21:01:53 2009 -0400
@@ -385,6 +385,7 @@ bool mail_storage_set_error_from_errno(s
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);
diff -r 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/mail-storage.h Tue Apr 28 21:01:53 2009 -0400
@@ -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 {
diff -r 1cd9808147e3 -r 03a5f5cf6b4c src/lib-storage/mail.c
--- a/src/lib-storage/mail.c Thu Apr 23 20:01:18 2009 -0400
+++ b/src/lib-storage/mail.c Tue Apr 28 21:01:53 2009 -0400
@@ -152,11 +152,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