dovecot-1.2: virtual: Don't assert-crash if trying to access an ...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 26 08:54:44 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/73d6117770c7
changeset: 9092:73d6117770c7
user:      Timo Sirainen <tss at iki.fi>
date:      Tue May 26 01:54:36 2009 -0400
description:
virtual: Don't assert-crash if trying to access an expunged mail.

diffstat:

1 file changed, 49 insertions(+), 5 deletions(-)
src/plugins/virtual/virtual-mail.c |   54 ++++++++++++++++++++++++++++++++----

diffs (174 lines):

diff -r abad454e99bb -r 73d6117770c7 src/plugins/virtual/virtual-mail.c
--- a/src/plugins/virtual/virtual-mail.c	Tue May 26 01:53:50 2009 -0400
+++ b/src/plugins/virtual/virtual-mail.c	Tue May 26 01:54:36 2009 -0400
@@ -16,6 +16,9 @@ struct virtual_mail {
 	struct mail *backend_mail;
 	/* all allocated mails */
 	ARRAY_DEFINE(backend_mails, struct mail *);
+
+	/* mail is lost if backend_mail doesn't point to correct mail */
+	unsigned int lost:1;
 };
 
 struct mail *
@@ -119,8 +122,7 @@ static void virtual_mail_set_seq(struct 
 	vmail->backend_mail = backend_mail_find(vmail, bbox->box);
 	if (vmail->backend_mail == NULL)
 		virtual_mail_set_backend_mail(mail, bbox);
-	if (!mail_set_uid(vmail->backend_mail, vrec->real_uid))
-		i_unreached();
+	vmail->lost = !mail_set_uid(vmail->backend_mail, vrec->real_uid);
 	memset(&vmail->imail.data, 0, sizeof(vmail->imail.data));
 	p_clear(vmail->imail.data_pool);
 
@@ -128,9 +130,15 @@ static void virtual_mail_set_seq(struct 
 	mail->seq = seq;
 	mail_index_lookup_uid(mbox->ibox.view, seq, &mail->uid);
 
-	mail->expunged = vmail->backend_mail->expunged;
-	mail->has_nuls = vmail->backend_mail->has_nuls;
-	mail->has_no_nuls = vmail->backend_mail->has_no_nuls;
+	if (!vmail->lost) {
+		mail->expunged = vmail->backend_mail->expunged;
+		mail->has_nuls = vmail->backend_mail->has_nuls;
+		mail->has_no_nuls = vmail->backend_mail->has_no_nuls;
+	} else {
+		mail->expunged = TRUE;
+		mail->has_nuls = FALSE;
+		mail->has_no_nuls = FALSE;
+	}
 }
 
 static bool virtual_mail_set_uid(struct mail *mail, uint32_t uid)
@@ -145,11 +153,22 @@ static bool virtual_mail_set_uid(struct 
 	return TRUE;
 }
 
+static int virtual_mail_handle_lost(struct virtual_mail *vmail)
+{
+	if (!vmail->lost)
+		return 0;
+
+	mail_set_expunged(&vmail->imail.mail.mail);
+	return -1;
+}
+
 static int
 virtual_mail_get_parts(struct mail *mail, const struct message_part **parts_r)
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_parts(vmail->backend_mail, parts_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -166,6 +185,8 @@ virtual_mail_get_date(struct mail *mail,
 	if (timezone_r == NULL)
 		timezone_r = &tz;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_date(vmail->backend_mail, date_r, timezone_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -177,6 +198,8 @@ static int virtual_mail_get_received_dat
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_received_date(vmail->backend_mail, date_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -188,6 +211,8 @@ static int virtual_mail_get_save_date(st
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_save_date(vmail->backend_mail, date_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -199,6 +224,8 @@ static int virtual_mail_get_virtual_mail
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_virtual_size(vmail->backend_mail, size_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -210,6 +237,8 @@ static int virtual_mail_get_physical_siz
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_physical_size(vmail->backend_mail, size_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
 		return -1;
@@ -224,6 +253,8 @@ virtual_mail_get_first_header(struct mai
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 	struct mail_private *p = (struct mail_private *)vmail->backend_mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (p->v.get_first_header(vmail->backend_mail, field,
 				  decode_to_utf8, value_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
@@ -239,6 +270,8 @@ virtual_mail_get_headers(struct mail *ma
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 	struct mail_private *p = (struct mail_private *)vmail->backend_mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (p->v.get_headers(vmail->backend_mail, field,
 			     decode_to_utf8, value_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
@@ -255,6 +288,9 @@ virtual_mail_get_header_stream(struct ma
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 	struct mailbox_header_lookup_ctx *backend_headers;
 	int ret;
+
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 
 	backend_headers = mailbox_header_lookup_init(vmail->backend_mail->box,
 						     headers->headers);
@@ -275,6 +311,8 @@ virtual_mail_get_stream(struct mail *mai
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (mail_get_stream(vmail->backend_mail, hdr_size, body_size,
 			    stream_r) < 0) {
 		virtual_box_copy_error(mail->box, vmail->backend_mail->box);
@@ -290,6 +328,8 @@ virtual_mail_get_special(struct mail *ma
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 	struct mailbox *box = vmail->backend_mail->box;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return -1;
 	if (field == MAIL_FETCH_MAILBOX_NAME) {
 		*value_r = p_strconcat(vmail->imail.data_pool,
 				       box->storage->ns->prefix,
@@ -307,6 +347,8 @@ static void virtual_mail_expunge(struct 
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return;
 	mail_expunge(vmail->backend_mail);
 }
 
@@ -315,6 +357,8 @@ virtual_mail_set_cache_corrupted(struct 
 {
 	struct virtual_mail *vmail = (struct virtual_mail *)mail;
 
+	if (virtual_mail_handle_lost(vmail) < 0)
+		return;
 	mail_set_cache_corrupted(vmail->backend_mail, field);
 }
 


More information about the dovecot-cvs mailing list