a53d01
--- cyrus-imapd-2.3.7/imap/ctl_cyrusdb.c.rmquota	2005-02-16 22:06:18.000000000 +0100
a53d01
+++ cyrus-imapd-2.3.7/imap/ctl_cyrusdb.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -133,7 +133,7 @@
a53d01
     /* if it is MBTYPE_RESERVED, unset it & call mboxlist_delete */
a53d01
     if(!r && (mbtype & MBTYPE_RESERVE)) {
a53d01
 	if(!r) {
a53d01
-	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1);
a53d01
+	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1, 1);
a53d01
 	    if(r) {
a53d01
 		/* log the error */
a53d01
 		syslog(LOG_ERR,
a53d01
--- cyrus-imapd-2.3.7/imap/ctl_mboxlist.c.rmquota	2006-04-06 17:42:10.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/ctl_mboxlist.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -457,7 +457,7 @@
a53d01
 	    
a53d01
 	    wipe_head = wipe_head->next;
a53d01
 	    
a53d01
-	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1);
a53d01
+	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1, 1);
a53d01
 	    if(ret) {
a53d01
 		fprintf(stderr, "couldn't delete defunct mailbox %s\n",
a53d01
 			me->mailbox);
a53d01
--- cyrus-imapd-2.3.7/imap/imapd.c.rmquota	2006-07-23 12:52:14.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/imapd.c	2006-07-23 12:55:14.000000000 +0200
a53d01
@@ -4985,7 +4985,7 @@
a53d01
 
a53d01
     r = mboxlist_deletemailbox(name, imapd_userisadmin,
a53d01
 			       imapd_userid, imapd_authstate,
a53d01
-			       0, 0, 0);
a53d01
+			       0, 0, 0, 1);
a53d01
     
a53d01
     if (!r) sync_log_mailbox(name);
a53d01
 
a53d01
@@ -5009,6 +5009,12 @@
a53d01
     char *p;
a53d01
     int domainlen = 0;
a53d01
     int sync_lockfd = (-1);
a53d01
+    int keepQuota = 1;
a53d01
+
a53d01
+    if(name && *name == '+') {
a53d01
+	keepQuota = 0;
a53d01
+	name++;
a53d01
+    }
a53d01
 
a53d01
     r = (*imapd_namespace.mboxname_tointernal)(&imapd_namespace, name,
a53d01
 					       imapd_userid, mailboxname);
a53d01
@@ -5067,7 +5073,7 @@
a53d01
 
a53d01
 	r = mboxlist_deletemailbox(mailboxname, imapd_userisadmin,
a53d01
 				   imapd_userid, imapd_authstate, 1-force,
a53d01
-				   localonly, 0);
a53d01
+				   localonly, 0, keepQuota);
a53d01
     }
a53d01
 
a53d01
     /* was it a top-level user mailbox? */
a53d01
@@ -6426,6 +6432,7 @@
a53d01
 {
a53d01
     int newquota = -1;
a53d01
     int badresource = 0;
a53d01
+    int rmquota = 0;
a53d01
     int c;
a53d01
     int force = 0;
a53d01
     static struct buf arg;
a53d01
@@ -6442,7 +6449,8 @@
a53d01
     if (c != ')' || arg.s[0] != '\0') {
a53d01
 	for (;;) {
a53d01
 	    if (c != ' ') goto badlist;
a53d01
-	    if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
a53d01
+	    if (strcasecmp(arg.s, "remove") == 0) rmquota = 1;
a53d01
+	    else if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
a53d01
 	    c = getword(imapd_in, &arg);
a53d01
 	    if (c != ' ' && c != ')') goto badlist;
a53d01
 	    if (arg.s[0] == '\0') goto badlist;
a53d01
@@ -6511,7 +6519,10 @@
a53d01
 
a53d01
     /* local mailbox */
a53d01
     if (!r || (r == IMAP_MAILBOX_NONEXISTENT)) {
a53d01
-	r = mboxlist_setquota(mailboxname, newquota, force);
a53d01
+        if (!rmquota)
a53d01
+            r = mboxlist_setquota(mailboxname, newquota, force);
a53d01
+        else
a53d01
+            r = mboxlist_unsetquota(mailboxname);
a53d01
     }
a53d01
 
a53d01
     imapd_check(NULL, 0, 0);
a53d01
@@ -8224,7 +8235,7 @@
a53d01
 	/* note also that we need to remember to let proxyadmins do this */
a53d01
 	r = mboxlist_deletemailbox(mailboxname,
a53d01
 				   imapd_userisadmin || imapd_userisproxyadmin,
a53d01
-				   imapd_userid, imapd_authstate, 0, 1, 0);
a53d01
+				   imapd_userid, imapd_authstate, 0, 1, 0, 1);
a53d01
 	if(r) syslog(LOG_ERR,
a53d01
 		     "Could not delete local mailbox during move of %s",
a53d01
 		     mailboxname);
a53d01
--- cyrus-imapd-2.3.7/imap/mailbox.c.rmquota	2006-06-02 20:55:06.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/mailbox.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -2689,27 +2689,7 @@
a53d01
 
a53d01
     seen_delete_mailbox(mailbox);
a53d01
 
a53d01
-    if (delete_quota_root && !rquota) {
a53d01
-	quota_delete(&mailbox->quota, &tid);
a53d01
-	free(mailbox->quota.root);
a53d01
-	mailbox->quota.root = NULL;
a53d01
-    } else if (!rquota) {
a53d01
-	/* Free any quota being used by this mailbox */
a53d01
-	if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
a53d01
-	    mailbox->quota.used -= mailbox->quota_mailbox_used;
a53d01
-	}
a53d01
-	else {
a53d01
-	    mailbox->quota.used = 0;
a53d01
-	}
a53d01
-	r = quota_write(&mailbox->quota, &tid);
a53d01
-	if (r) {
a53d01
-	    syslog(LOG_ERR,
a53d01
-		   "LOSTQUOTA: unable to record free of " UQUOTA_T_FMT " bytes in quota %s",
a53d01
-		   mailbox->quota_mailbox_used, mailbox->quota.root);
a53d01
-	}
a53d01
-	else
a53d01
-	    quota_commit(&tid);
a53d01
-    }
a53d01
+    mailbox_updatequota(mailbox,NULL);
a53d01
 
a53d01
     /* remove data (message file) directory */
a53d01
     path = mailbox->path;
a53d01
@@ -3331,3 +3311,49 @@
a53d01
 	if (*p == '.') *p = '/';
a53d01
     }
a53d01
 }
a53d01
+
a53d01
+
a53d01
+/* This function is used to update the quota. Can be used to replace
a53d01
+ * identical parts of the code, and can be quite handy some times 
a53d01
+ * The tid is used in order to make possible to make the quota update
a53d01
+ * being a part of a bigger transaction to the quota db */
a53d01
+int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid)
a53d01
+{
a53d01
+    int r = 0, havetid = 0;
a53d01
+    struct txn **ltid = NULL;
a53d01
+
a53d01
+    if(tid) {
a53d01
+        ltid = tid;
a53d01
+        havetid = 1;
a53d01
+    }
a53d01
+    /* Ensure that we are locked */
a53d01
+    if(!mailbox->header_lock_count) return IMAP_INTERNAL;
a53d01
+
a53d01
+
a53d01
+    if(mailbox->quota.root) {
a53d01
+        r = quota_read(&mailbox->quota, ltid, 1);
a53d01
+        if( r == 0 ) {
a53d01
+            if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
a53d01
+                mailbox->quota.used -= mailbox->quota_mailbox_used;
a53d01
+            }
a53d01
+            else {
a53d01
+                mailbox->quota.used = 0;
a53d01
+            }
a53d01
+            r = quota_write(&mailbox->quota, ltid);
a53d01
+            if (r) {
a53d01
+                syslog(LOG_ERR,
a53d01
+                   "LOSTQUOTA: unable to record free of %lu bytes in quota %s",
a53d01
+                   mailbox->quota_mailbox_used, mailbox->quota.root);
a53d01
+            }
a53d01
+            else if(!havetid)
a53d01
+                quota_commit(tid);
a53d01
+        }
a53d01
+        /* It is not a big mistake not to have quota .. just remove from the mailbox */
a53d01
+        else if ( r == IMAP_QUOTAROOT_NONEXISTENT) {
a53d01
+                free(mailbox->quota.root);
a53d01
+                r = 0;
a53d01
+        }
a53d01
+    }
a53d01
+    return r;
a53d01
+}
a53d01
+
a53d01
--- cyrus-imapd-2.3.7/imap/mailbox.h.rmquota	2006-06-02 18:41:57.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/mailbox.h	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -364,6 +364,8 @@
a53d01
 			  struct mailbox *mailboxp);
a53d01
 extern int mailbox_delete(struct mailbox *mailbox, int delete_quota_root);
a53d01
 
a53d01
+extern int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid);
a53d01
+
a53d01
 extern int mailbox_rename_copy(struct mailbox *oldmailbox, 
a53d01
 			       const char *newname, char *newpartition,
a53d01
 			       bit32 *olduidvalidityp, bit32 *newuidvalidityp,
a53d01
--- cyrus-imapd-2.3.7/imap/mboxlist.c.rmquota	2006-07-23 12:52:14.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/mboxlist.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -99,6 +99,11 @@
a53d01
 static int mboxlist_opensubs();
a53d01
 static void mboxlist_closesubs();
a53d01
 
a53d01
+static int child_cb(char *name,
a53d01
+                    int matchlen __attribute__((unused)),
a53d01
+                    int maycreate __attribute__((unused)),
a53d01
+                    void *rock);
a53d01
+
a53d01
 static int mboxlist_rmquota(const char *name, int matchlen, int maycreate,
a53d01
 			    void *rock);
a53d01
 static int mboxlist_changequota(const char *name, int matchlen, int maycreate,
a53d01
@@ -113,6 +118,7 @@
a53d01
 
a53d01
 struct change_rock {
a53d01
     struct quota *quota;
a53d01
+    struct quota *oldquota;
a53d01
     struct txn **tid;
a53d01
 };
a53d01
 
a53d01
@@ -911,9 +917,9 @@
a53d01
  */
a53d01
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
a53d01
 			   struct auth_state *auth_state, int checkacl,
a53d01
-			   int local_only, int force)
a53d01
+			   int local_only, int force, int keepQuota)
a53d01
 {
a53d01
-    int r;
a53d01
+    int r, has_children = 0;
a53d01
     char *acl;
a53d01
     long access;
a53d01
     struct mailbox mailbox;
a53d01
@@ -924,6 +930,7 @@
a53d01
     int mbtype;
a53d01
     const char *p;
a53d01
     mupdate_handle *mupdate_h = NULL;
a53d01
+    char *quotaroot = NULL;
a53d01
 
a53d01
     if(!isadmin && force) return IMAP_PERMISSION_DENIED;
a53d01
 
a53d01
@@ -1036,13 +1043,44 @@
a53d01
 
a53d01
     if ((r && !force) || isremote) goto done;
a53d01
 
a53d01
-    if (!r || force) r = mailbox_delete(&mailbox, deletequotaroot);
a53d01
+    if (!r || force) {
a53d01
+        /* first we have to keep the previous quota root in order to delete it */
a53d01
+        if(mailbox.quota.root)
a53d01
+                quotaroot = xstrdup(mailbox.quota.root);
a53d01
+	r = mailbox_delete(&mailbox, deletequotaroot);
a53d01
+    }
a53d01
 
a53d01
     /*
a53d01
      * See if we have to remove mailbox's quota root
a53d01
      */
a53d01
-    if (!r && mailbox.quota.root != NULL) {
a53d01
+    if (!r && quotaroot != NULL) {
a53d01
 	/* xxx look for any other mailboxes in this quotaroot */
a53d01
+        /* If we have not asked to remove the quota (default behaviour), we check 
a53d01
+         * whether there are any subfolders beneeth the quota root. If there aren't
a53d01
+         * any subfolders the reasonable thing is to delete the quota */
a53d01
+        if(keepQuota) {
a53d01
+            char pattern[MAX_MAILBOX_PATH+1];
a53d01
+            strlcpy(pattern, quotaroot, sizeof(pattern));
a53d01
+            if (config_virtdomains && name[strlen(name)-1] == '!') {
a53d01
+                strlcat(pattern, "*", sizeof(pattern));
a53d01
+            }
a53d01
+            else {
a53d01
+                strlcat(pattern, ".*", sizeof(pattern));
a53d01
+            }
a53d01
+		/* find if there are subfolders. Then we want to 
a53d01
+		 * keep the existing quota */
a53d01
+            mboxlist_findall(NULL, pattern, isadmin, userid,
a53d01
+                    auth_state, child_cb, (void *) &has_children);
a53d01
+
a53d01
+	    if(!has_children)
a53d01
+                if(!mboxlist_mylookup(quotaroot, NULL, NULL, NULL, NULL, NULL, NULL, 0 ))
a53d01
+		    has_children = 1;
a53d01
+        }
a53d01
+        /* If we want to remove the quota explicitely or the quota root folder has no subfolders
a53d01
+         * we execute the rmquota patch */
a53d01
+        if(!keepQuota || !has_children )
a53d01
+            mboxlist_unsetquota(quotaroot);
a53d01
+        free(quotaroot);
a53d01
     }
a53d01
 
a53d01
  done:
a53d01
@@ -2498,6 +2536,7 @@
a53d01
     if (r) return r;
a53d01
 
a53d01
     crock.quota = "a;
a53d01
+    crock.oldquota = NULL;
a53d01
     crock.tid = &tid;
a53d01
     /* top level mailbox */
a53d01
     if(have_mailbox)
a53d01
@@ -2516,17 +2555,21 @@
a53d01
  */
a53d01
 int mboxlist_unsetquota(const char *root)
a53d01
 {
a53d01
+    char newquota[MAX_MAILBOX_PATH+1];
a53d01
     char pattern[MAX_MAILBOX_PATH+1];
a53d01
     struct quota quota;
a53d01
-    int r=0;
a53d01
+    struct change_rock crock;
a53d01
+    int r=0, k=0;
a53d01
 
a53d01
     if (!root[0] || root[0] == '.' || strchr(root, '/')
a53d01
 	|| strchr(root, '*') || strchr(root, '%') || strchr(root, '?')) {
a53d01
 	return IMAP_MAILBOX_BADNAME;
a53d01
     }
a53d01
+	
a53d01
+    crock.tid=NULL;
a53d01
     
a53d01
     quota.root = (char *) root;
a53d01
-    r = quota_read("a, NULL, 0);
a53d01
+    r = quota_read("a, crock.tid, 0);
a53d01
     if (r == IMAP_QUOTAROOT_NONEXISTENT) {
a53d01
 	/* already unset */
a53d01
 	return 0;
a53d01
@@ -2543,13 +2586,45 @@
a53d01
     }
a53d01
     else
a53d01
 	strlcat(pattern, ".*", sizeof(pattern));
a53d01
-    
a53d01
-    /* top level mailbox */
a53d01
-    mboxlist_rmquota(root, 0, 0, (void *)root);
a53d01
-    /* submailboxes - we're using internal names here */
a53d01
-    mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
a53d01
 
a53d01
-    r = quota_delete("a, NULL);
a53d01
+    r = quota_delete("a, crock.tid);
a53d01
+
a53d01
+    /* If we cannot delete the quota then abort the operation */
a53d01
+    if(!r) {
a53d01
+       /* quota_findroot performs several checks that we can
a53d01
+        * assume that are already done, and don't have to perform
a53d01
+        * them again. One of them is that it returns 1 only if
a53d01
+        * quotaroot exists.
a53d01
+        */
a53d01
+        if(quota_findroot(newquota, sizeof(newquota), root)) {
a53d01
+            struct quota rootquota;
a53d01
+            rootquota.root = newquota;
a53d01
+            k = quota_read(&rootquota, crock.tid, 0);
a53d01
+            if (!k) {
a53d01
+                crock.quota = &rootquota;
a53d01
+                crock.oldquota = "a;
a53d01
+                /* top level mailbox */
a53d01
+                k = mboxlist_changequota(root, 0, 0, &crock);
a53d01
+            }
a53d01
+            /* submailboxes - we're using internal names here */
a53d01
+            if (!k)
a53d01
+                k = mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_changequota, &crock);
a53d01
+            if(!k)
a53d01
+                k = quota_write(&rootquota, crock.tid);
a53d01
+
a53d01
+         }
a53d01
+         else {
a53d01
+           /* top level mailbox */
a53d01
+           mboxlist_rmquota(root, 0, 0, (void *)root);
a53d01
+           /* submailboxes - we're using internal names here */
a53d01
+           mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
a53d01
+       }
a53d01
+    }
a53d01
+
a53d01
+    if(!r && !k)
a53d01
+        quota_commit(crock.tid);
a53d01
+    else
a53d01
+        quota_abort(crock.tid);
a53d01
 
a53d01
     return r;
a53d01
 }
a53d01
@@ -2647,6 +2722,7 @@
a53d01
     struct mailbox mailbox;
a53d01
     struct change_rock *crock = (struct change_rock *) rock;
a53d01
     struct quota *mboxlist_newquota = crock->quota;
a53d01
+    struct quota *mboxlist_oldquota = crock->oldquota;
a53d01
     struct txn **tid = crock->tid;
a53d01
 
a53d01
     assert(rock != NULL);
a53d01
@@ -2664,27 +2740,24 @@
a53d01
     if (r) goto error;
a53d01
 
a53d01
     if (mailbox.quota.root) {
a53d01
-	if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
a53d01
-	    /* Part of a child quota root */
a53d01
-	    mailbox_close(&mailbox);
a53d01
-	    return 0;
a53d01
-	}
a53d01
-
a53d01
-	r = quota_read(&mailbox.quota, tid, 1);
a53d01
-	if (r) goto error;
a53d01
-	if (mailbox.quota.used >= mailbox.quota_mailbox_used) {
a53d01
-	    mailbox.quota.used -= mailbox.quota_mailbox_used;
a53d01
+	if(mboxlist_oldquota) {
a53d01
+	    if (strlen(mailbox.quota.root) > strlen(mboxlist_oldquota->root)) {
a53d01
+		/* Part of a child quota root */
a53d01
+		mailbox_close(&mailbox);
a53d01
+		return 0;
a53d01
+	    }
a53d01
 	}
a53d01
 	else {
a53d01
-	    mailbox.quota.used = 0;
a53d01
-	}
a53d01
-	r = quota_write(&mailbox.quota, tid);
a53d01
-	if (r) {
a53d01
-	    syslog(LOG_ERR,
a53d01
-		   "LOSTQUOTA: unable to record free of " UQUOTA_T_FMT " bytes in quota %s",
a53d01
-		   mailbox.quota_mailbox_used, mailbox.quota.root);
a53d01
+	    if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
a53d01
+		/* Part of a child quota root */
a53d01
+		mailbox_close(&mailbox);
a53d01
+		return 0;
a53d01
+	    }
a53d01
 	}
a53d01
-	free(mailbox.quota.root);
a53d01
+
a53d01
+	r = mailbox_updatequota(&mailbox,tid);
a53d01
+	if (r)
a53d01
+	    goto error;
a53d01
     }
a53d01
 
a53d01
     mailbox.quota.root = xstrdup(mboxlist_newquota->root);
a53d01
@@ -2694,18 +2767,24 @@
a53d01
     mboxlist_newquota->used += mailbox.quota_mailbox_used;
a53d01
     mailbox_close(&mailbox);
a53d01
     return 0;
a53d01
-
a53d01
+ 
a53d01
  error:
a53d01
     mailbox_close(&mailbox);
a53d01
+    syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s. \
a53d01
+                        Command aborted. Run reconstruct to make sure mailboxes \
a53d01
+                         are in consistent state",
a53d01
+           name, mboxlist_newquota->root, error_message(r));
a53d01
+    return 1;
a53d01
  error_noclose:
a53d01
     syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s",
a53d01
-	   name, mboxlist_newquota->root, error_message(r));
a53d01
+           name, mboxlist_newquota->root, error_message(r));
a53d01
 
a53d01
     /* Note, we're a callback, and it's not a huge tragedy if we
a53d01
      * fail, so we don't ever return a failure */
a53d01
     return 0;
a53d01
 }
a53d01
 
a53d01
+
a53d01
 /* must be called after cyrus_init */
a53d01
 void mboxlist_init(int myflags)
a53d01
 {
a53d01
--- cyrus-imapd-2.3.7/imap/mboxlist.h.rmquota	2006-07-23 12:52:14.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/mboxlist.h	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -125,7 +125,7 @@
a53d01
  * the planet */
a53d01
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
a53d01
 			   struct auth_state *auth_state, int checkacl,
a53d01
-			   int local_only, int force);
a53d01
+			   int local_only, int force, int keepQuota);
a53d01
 
a53d01
 /* Rename/move a mailbox (hierarchical) */
a53d01
 int mboxlist_renamemailbox(char *oldname, char *newname, char *partition, 
a53d01
--- cyrus-imapd-2.3.7/imap/mupdate.c.rmquota	2006-03-15 19:56:31.000000000 +0100
a53d01
+++ cyrus-imapd-2.3.7/imap/mupdate.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -2297,7 +2297,7 @@
a53d01
 	    remote_boxes.head = r->next;
a53d01
 	} else if (ret < 0) {
a53d01
 	    /* Local without corresponding remote, delete it */
a53d01
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
a53d01
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
a53d01
 	    local_boxes.head = l->next;
a53d01
 	} else /* (ret > 0) */ {
a53d01
 	    /* Remote without corresponding local, insert it */
a53d01
@@ -2312,7 +2312,7 @@
a53d01
     if(l && !r) {
a53d01
 	/* we have more deletes to do */
a53d01
 	while(l) {
a53d01
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
a53d01
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
a53d01
 	    local_boxes.head = l->next;
a53d01
 	    l = local_boxes.head;
a53d01
 	}
a53d01
--- cyrus-imapd-2.3.7/imap/nntpd.c.rmquota	2006-05-26 17:50:07.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/nntpd.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -3356,7 +3356,7 @@
a53d01
     /* XXX should we delete right away, or wait until empty? */
a53d01
 
a53d01
     r = mboxlist_deletemailbox(mailboxname, 0,
a53d01
-			       newsmaster, newsmaster_authstate, 1, 0, 0);
a53d01
+			       newsmaster, newsmaster_authstate, 1, 0, 0, 1);
a53d01
 
a53d01
     if (!r) sync_log_mailbox(mailboxname);
a53d01
 
a53d01
--- cyrus-imapd-2.3.7/imap/sync_reset.c.rmquota	2005-12-13 16:31:10.000000000 +0100
a53d01
+++ cyrus-imapd-2.3.7/imap/sync_reset.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -254,7 +254,7 @@
a53d01
     if (r) goto fail;
a53d01
 
a53d01
     for (item = list->head ; item ; item = item->next) {
a53d01
-        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0);
a53d01
+        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0, 1);
a53d01
 
a53d01
         if (r) goto fail;
a53d01
     }
a53d01
@@ -270,7 +270,7 @@
a53d01
     if (r) goto fail;
a53d01
 
a53d01
     for (item = list->head ; item ; item = item->next) {
a53d01
-        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0);
a53d01
+        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0, 1);
a53d01
 
a53d01
         if (r) goto fail;
a53d01
     }
a53d01
@@ -278,7 +278,7 @@
a53d01
 
a53d01
     /* Nuke inbox (recursive nuke possible?) */
a53d01
     snprintf(buf, sizeof(buf)-1, "user.%s", user);
a53d01
-    r = mboxlist_deletemailbox(buf, 1, "cyrus", sync_authstate, 1, 0, 0);
a53d01
+    r = mboxlist_deletemailbox(buf, 1, "cyrus", sync_authstate, 1, 0, 0, 1);
a53d01
     if (r && (r != IMAP_MAILBOX_NONEXISTENT)) goto fail;
a53d01
 
a53d01
     if ((r=user_deletedata(user, sync_userid, sync_authstate, 1)))
a53d01
--- cyrus-imapd-2.3.7/imap/sync_server.c.rmquota	2006-06-12 20:56:42.000000000 +0200
a53d01
+++ cyrus-imapd-2.3.7/imap/sync_server.c	2006-07-23 12:52:14.000000000 +0200
a53d01
@@ -1576,7 +1576,7 @@
a53d01
 
a53d01
     for (item = list->head ; item ; item = item->next) {
a53d01
         r=mboxlist_deletemailbox(item->name, sync_userisadmin, sync_userid,
a53d01
-				 sync_authstate, 0, 0, 1);
a53d01
+				 sync_authstate, 0, 0, 1, 1);
a53d01
 
a53d01
         if (r) goto fail;
a53d01
     }
a53d01
@@ -1586,7 +1586,7 @@
a53d01
     (sync_namespacep->mboxname_tointernal)(sync_namespacep, "INBOX",
a53d01
 					   user, buf);
a53d01
     r = mboxlist_deletemailbox(buf, sync_userisadmin, sync_userid,
a53d01
-			       sync_authstate, 0, 0, 1);
a53d01
+			       sync_authstate, 0, 0, 1, 1);
a53d01
     if (r && (r != IMAP_MAILBOX_NONEXISTENT)) goto fail;
a53d01
 
a53d01
     if ((r=user_deletedata(user, sync_userid, sync_authstate, 1)))
a53d01
@@ -2508,7 +2508,7 @@
a53d01
 
a53d01
     /* Delete with admin priveleges */
a53d01
     r = mboxlist_deletemailbox(name, sync_userisadmin, sync_userid,
a53d01
-			       sync_authstate, 0, 0, 1);
a53d01
+			       sync_authstate, 0, 0, 1, 1);
a53d01
 
a53d01
     if (r)
a53d01
         prot_printf(sync_out, "NO Failed to delete %s: %s\r\n",