dovecot-2.1-pigeonhole: lib-sieve: made sure that modified messa...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Sat Dec 17 00:40:42 EET 2011


details:   http://hg.rename-it.nl/dovecot-2.1-pigeonhole/rev/a8780b39f887
changeset: 1578:a8780b39f887
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Fri Dec 16 23:40:34 2011 +0100
description:
lib-sieve: made sure that modified messages are not stored in the source mailbox when it was opened read-only.
This is currently only relevant for the sieve-filter tool to avoid duplicating messages in the
source folder. This can happen when the messages are modified (e.g. by the editheader extension) and the
source folder is opened read-only, thus preventing deletion of the original message.

diffstat:

 src/lib-sieve/edit-mail.c     |  32 ++++++++++++++++++++------------
 src/lib-sieve/sieve-actions.c |  23 +++++++++++++++++++----
 2 files changed, 39 insertions(+), 16 deletions(-)

diffs (106 lines):

diff -r a2d645ca6e32 -r a8780b39f887 src/lib-sieve/edit-mail.c
--- a/src/lib-sieve/edit-mail.c	Mon Dec 12 21:27:59 2011 +0100
+++ b/src/lib-sieve/edit-mail.c	Fri Dec 16 23:40:34 2011 +0100
@@ -405,6 +405,10 @@
 
 struct mail *edit_mail_get_mail(struct edit_mail *edmail)
 {
+	/* Return wrapped mail when nothing is modified yet */
+	if ( !edmail->modified )
+		return &edmail->wrapped->mail;
+
 	return &edmail->mail.mail;
 }
 
@@ -1337,17 +1341,21 @@
 {
 	struct edit_mail *edmail = (struct edit_mail *)mail;
 
-	switch (field) {
-	case MAIL_FETCH_GUID:
-		/* This is in essence a new message */
-		*value_r = "";
-		return 0;
-	case MAIL_FETCH_UIDL_FILE_NAME:
-		/* Prevent hardlink copying */
-		*value_r = "";
-		return 0;
-	default:
-		break;
+	if ( edmail->modified ) {
+		/* Block certain fields when modified */
+
+		switch (field) {
+		case MAIL_FETCH_GUID:
+			/* This is in essence a new message */
+			*value_r = "";
+			return 0;
+		case MAIL_FETCH_UIDL_FILE_NAME:
+			/* Prevent hardlink copying */
+			*value_r = "";
+			return 0;
+		default:
+			break;
+		}
 	}
 
 	return edmail->wrapped->v.get_special(&edmail->wrapped->mail, field, value_r);
@@ -1357,7 +1365,7 @@
 {
 	struct edit_mail *edmail = (struct edit_mail *)mail;
 
-	return edmail->wrapped->v.get_real_mail(&edmail->wrapped->mail);
+	return edit_mail_get_mail(edmail);
 }
 
 static void edit_mail_update_flags
diff -r a2d645ca6e32 -r a8780b39f887 src/lib-sieve/sieve-actions.c
--- a/src/lib-sieve/sieve-actions.c	Mon Dec 12 21:27:59 2011 +0100
+++ b/src/lib-sieve/sieve-actions.c	Fri Dec 16 23:40:34 2011 +0100
@@ -467,7 +467,8 @@
 	struct act_store_transaction *trans = 
 		(struct act_store_transaction *) tr_context;
 	struct mail *mail =	( action->mail != NULL ?
-		action->mail : aenv->msgdata->mail );	
+		action->mail : aenv->msgdata->mail );
+	struct mail *real_mail = mail_get_real_mail(mail);
 	struct mail_save_context *save_ctx;
 	struct mail_keywords *keywords = NULL;
 	bool result = TRUE;
@@ -483,12 +484,14 @@
 		return FALSE;
 
 	/* If the message originates from the target mailbox, only update the flags 
-	 * and keywords 
+	 * and keywords (if not read-only)
 	 */
-	if ( mailbox_backends_equal(trans->box, mail->box) ) {
+	if ( mailbox_backends_equal(trans->box, mail->box) ||
+		(real_mail != mail && mailbox_backends_equal(trans->box, real_mail->box)) )
+		{
 		trans->redundant = TRUE;
 
-		if ( trans->flags_altered ) {
+		if ( trans->flags_altered && !mailbox_is_readonly(mail->box) ) {
 			keywords = act_store_keywords_create
 				(aenv, &trans->keywords, mail->box);
 
@@ -501,6 +504,18 @@
 		}
 
 		return TRUE;
+
+	/* If the message is modified, only store it in the source mailbox when it is
+	 * not opened read-only. Mail structs of modified messages have their own
+	 * mailbox, unrelated to the orignal mail, so this case needs to be handled
+	 * separately.
+	 */
+	} else if ( mail != aenv->msgdata->mail
+		&& mailbox_is_readonly(aenv->msgdata->mail->box) 
+		&& ( mailbox_backends_equal(trans->box, aenv->msgdata->mail->box) ) ) {
+
+		trans->redundant = TRUE;
+		return TRUE;
 	}
 
 	/* Mark attempt to store in default mailbox */


More information about the dovecot-cvs mailing list