[dovecot-cvs] dovecot/src/plugins/quota quota-private.h, 1.7, 1.8 quota-storage.c, 1.6, 1.7

tss-movial at dovecot.org tss-movial at dovecot.org
Tue May 9 14:57:52 EEST 2006


Update of /var/lib/cvs/dovecot/src/plugins/quota
In directory talvi:/tmp/cvs-serv603/plugins/quota

Modified Files:
	quota-private.h quota-storage.c 
Log Message:
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
save_init() instead of being in save_finish(). This way you can request
wanted fields from the mail while it's being saved.

With maildir the message is being parsed at the same time as it's being
saved, and the results are stored into cache file.



Index: quota-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-private.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- quota-private.h	6 Mar 2006 15:48:33 -0000	1.7
+++ quota-private.h	9 May 2006 11:57:49 -0000	1.8
@@ -88,6 +88,7 @@
 
 	array_t ARRAY_DEFINE(root_transactions,
 			     struct quota_root_transaction_context *);
+	struct mail *mail;
 };
 
 struct quota_root_transaction_context {

Index: quota-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-storage.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- quota-storage.c	1 Mar 2006 09:15:03 -0000	1.6
+++ quota-storage.c	9 May 2006 11:57:49 -0000	1.7
@@ -75,6 +75,8 @@
 		return -1;
 	} else {
 		(void)quota_transaction_commit(qt);
+		if (qt->mail != NULL)
+			mail_free(&qt->mail);
 		return 0;
 	}
 }
@@ -86,6 +88,9 @@
 	struct quota_transaction_context *qt = QUOTA_CONTEXT(ctx);
 
 	qbox->super.transaction_rollback(ctx);
+
+	if (qt->mail != NULL)
+		mail_free(&qt->mail);
 	quota_transaction_rollback(qt);
 }
 
@@ -134,26 +139,25 @@
 	   enum mail_flags flags, struct mail_keywords *keywords,
 	   struct mail *dest_mail)
 {
+	struct quota_transaction_context *qt = QUOTA_CONTEXT(t);
 	struct quota_mailbox *qbox = QUOTA_CONTEXT(t->box);
-	struct mail *copy_dest_mail;
-	int ret;
 
-	if (dest_mail != NULL)
-		copy_dest_mail = dest_mail;
-	else
-                copy_dest_mail = mail_alloc(t, MAIL_FETCH_PHYSICAL_SIZE, NULL);
+	if (dest_mail == NULL) {
+		/* we always want to know the mail size */
+		if (qt->mail == NULL) {
+			qt->mail = mail_alloc(t, MAIL_FETCH_PHYSICAL_SIZE,
+					      NULL);
+		}
+		dest_mail = qt->mail;
+	}
 
 	qbox->save_hack = FALSE;
-	if (qbox->super.copy(t, mail, flags, keywords, copy_dest_mail) < 0)
+	if (qbox->super.copy(t, mail, flags, keywords, dest_mail) < 0)
 		return -1;
 
 	/* if copying used saving internally, we already checked the quota
 	   and set qbox->save_hack = TRUE. */
-	ret = qbox->save_hack ? 0 : quota_check(t, copy_dest_mail);
-
-	if (copy_dest_mail != dest_mail)
-		mail_free(&copy_dest_mail);
-	return ret;
+	return qbox->save_hack ? 0 : quota_check(t, dest_mail);
 }
 
 static int
@@ -161,8 +165,7 @@
 		enum mail_flags flags, struct mail_keywords *keywords,
 		time_t received_date, int timezone_offset,
 		const char *from_envelope, struct istream *input,
-		bool want_mail __attr_unused__,
-		struct mail_save_context **ctx_r)
+		struct mail *dest_mail, struct mail_save_context **ctx_r)
 {
 	struct quota_transaction_context *qt = QUOTA_CONTEXT(t);
 	struct quota_mailbox *qbox = QUOTA_CONTEXT(t->box);
@@ -194,35 +197,29 @@
 		}
 	}
 
-	/* note that we set want_mail = TRUE in here. */
+	if (dest_mail == NULL) {
+		/* we always want to know the mail size */
+		if (qt->mail == NULL) {
+			qt->mail = mail_alloc(t, MAIL_FETCH_PHYSICAL_SIZE,
+					      NULL);
+		}
+		dest_mail = qt->mail;
+	}
+
 	return qbox->super.save_init(t, flags, keywords, received_date,
 				     timezone_offset, from_envelope,
-				     input, TRUE, ctx_r);
+				     input, dest_mail, ctx_r);
 }
 
-static int quota_save_finish(struct mail_save_context *ctx,
-			     struct mail *dest_mail)
+static int quota_save_finish(struct mail_save_context *ctx)
 {
 	struct quota_mailbox *qbox = QUOTA_CONTEXT(ctx->transaction->box);
-	struct mail *save_dest_mail;
-	int ret;
 
-	if (dest_mail != NULL)
-		save_dest_mail = dest_mail;
-	else {
-		save_dest_mail = mail_alloc(ctx->transaction,
-					    MAIL_FETCH_PHYSICAL_SIZE, NULL);
-	}
-
-	if (qbox->super.save_finish(ctx, save_dest_mail) < 0)
+	if (qbox->super.save_finish(ctx) < 0)
 		return -1;
 
 	qbox->save_hack = TRUE;
-	ret = quota_check(ctx->transaction, save_dest_mail);
-
-	if (save_dest_mail != dest_mail)
-		mail_free(&save_dest_mail);
-	return ret;
+	return quota_check(ctx->transaction, ctx->dest_mail);
 }
 
 static struct mailbox *



More information about the dovecot-cvs mailing list