Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/ctl_cyrusdb.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/ctl_cyrusdb.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/ctl_cyrusdb.c	2006-11-30 19:11:17.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/ctl_cyrusdb.c	2007-02-21 16:34:33.000000000 +0200
9e566a
@@ -133,7 +133,7 @@
38f226
     /* if it is MBTYPE_RESERVED, unset it & call mboxlist_delete */
38f226
     if(!r && (mbtype & MBTYPE_RESERVE)) {
38f226
 	if(!r) {
38f226
-	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1);
38f226
+	    r = mboxlist_deletemailbox(name, 1, NULL, NULL, 0, 0, 1, 1);
38f226
 	    if(r) {
38f226
 		/* log the error */
38f226
 		syslog(LOG_ERR,
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/ctl_mboxlist.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/ctl_mboxlist.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/ctl_mboxlist.c	2007-02-05 20:41:46.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/ctl_mboxlist.c	2007-02-21 16:34:48.000000000 +0200
Tomas Janousek 7515ec
@@ -461,7 +461,7 @@
38f226
 	    
38f226
 	    wipe_head = wipe_head->next;
38f226
 	    
38f226
-	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1);
38f226
+	    ret = mboxlist_deletemailbox(me->mailbox, 1, "", NULL, 0, 1, 1, 1);
Tomas Janousek 7515ec
 	    if(!ret) sync_log_mailbox(me->mailbox);
38f226
 	    if(ret) {
38f226
 		fprintf(stderr, "couldn't delete defunct mailbox %s\n",
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/imapd.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/imapd.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/imapd.c	2007-02-05 20:49:55.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/imapd.c	2007-02-21 16:34:58.000000000 +0200
Tomas Janousek 7515ec
@@ -4983,7 +4983,7 @@
38f226
 
38f226
     r = mboxlist_deletemailbox(name, imapd_userisadmin,
38f226
 			       imapd_userid, imapd_authstate,
38f226
-			       0, 0, 0);
38f226
+			       0, 0, 0, 1);
38f226
     
9e566a
     if (!r) sync_log_mailbox(name);
9e566a
 
Tomas Janousek 7515ec
@@ -5007,6 +5007,12 @@
38f226
     char *p;
38f226
     int domainlen = 0;
9e566a
     int sync_lockfd = (-1);
38f226
+    int keepQuota = 1;
38f226
+
38f226
+    if(name && *name == '+') {
Tomas Janousek 7515ec
+        keepQuota = 0;
Tomas Janousek 7515ec
+        name++;
38f226
+    }
38f226
 
38f226
     r = (*imapd_namespace.mboxname_tointernal)(&imapd_namespace, name,
38f226
 					       imapd_userid, mailboxname);
Tomas Janousek 7515ec
@@ -5065,7 +5071,7 @@
38f226
 
38f226
 	r = mboxlist_deletemailbox(mailboxname, imapd_userisadmin,
9e566a
 				   imapd_userid, imapd_authstate, 1-force,
38f226
-				   localonly, 0);
38f226
+				   localonly, 0, keepQuota);
38f226
     }
38f226
 
38f226
     /* was it a top-level user mailbox? */
Tomas Janousek 7515ec
@@ -6423,6 +6429,7 @@
38f226
 {
38f226
     int newquota = -1;
38f226
     int badresource = 0;
38f226
+    int rmquota = 0;
38f226
     int c;
38f226
     int force = 0;
38f226
     static struct buf arg;
Tomas Janousek 7515ec
@@ -6439,7 +6446,8 @@
38f226
     if (c != ')' || arg.s[0] != '\0') {
38f226
 	for (;;) {
38f226
 	    if (c != ' ') goto badlist;
38f226
-	    if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
38f226
+	    if (strcasecmp(arg.s, "remove") == 0) rmquota = 1;
38f226
+	    else if (strcasecmp(arg.s, "storage") != 0) badresource = 1;
38f226
 	    c = getword(imapd_in, &arg);
38f226
 	    if (c != ' ' && c != ')') goto badlist;
38f226
 	    if (arg.s[0] == '\0') goto badlist;
Tomas Janousek 7515ec
@@ -6508,7 +6516,10 @@
Tomas Janousek 7515ec
 
Tomas Janousek 7515ec
     /* local mailbox */
Tomas Janousek 7515ec
     if (!r || (r == IMAP_MAILBOX_NONEXISTENT)) {
9e566a
-	r = mboxlist_setquota(mailboxname, newquota, force);
Tomas Janousek 7515ec
+        if(!rmquota) 
9e566a
+	    r = mboxlist_setquota(mailboxname, newquota, force);
Tomas Janousek 7515ec
+	else 
9e566a
+	    r = mboxlist_unsetquota(mailboxname);
38f226
     }
38f226
 
9e566a
     imapd_check(NULL, 0, 0);
Tomas Janousek 7515ec
@@ -8221,7 +8232,7 @@
38f226
 	/* note also that we need to remember to let proxyadmins do this */
38f226
 	r = mboxlist_deletemailbox(mailboxname,
38f226
 				   imapd_userisadmin || imapd_userisproxyadmin,
38f226
-				   imapd_userid, imapd_authstate, 0, 1, 0);
38f226
+				   imapd_userid, imapd_authstate, 0, 1, 0, 1);
38f226
 	if(r) syslog(LOG_ERR,
38f226
 		     "Could not delete local mailbox during move of %s",
38f226
 		     mailboxname);
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/mailbox.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mailbox.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/mailbox.c	2007-02-05 20:41:47.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mailbox.c	2007-02-21 16:35:10.000000000 +0200
Tomas Janousek 7515ec
@@ -2745,27 +2745,7 @@
38f226
 
38f226
     seen_delete_mailbox(mailbox);
38f226
 
38f226
-    if (delete_quota_root && !rquota) {
38f226
-	quota_delete(&mailbox->quota, &tid);
38f226
-	free(mailbox->quota.root);
38f226
-	mailbox->quota.root = NULL;
38f226
-    } else if (!rquota) {
38f226
-	/* Free any quota being used by this mailbox */
38f226
-	if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
38f226
-	    mailbox->quota.used -= mailbox->quota_mailbox_used;
38f226
-	}
38f226
-	else {
38f226
-	    mailbox->quota.used = 0;
38f226
-	}
38f226
-	r = quota_write(&mailbox->quota, &tid);
38f226
-	if (r) {
38f226
-	    syslog(LOG_ERR,
9e566a
-		   "LOSTQUOTA: unable to record free of " UQUOTA_T_FMT " bytes in quota %s",
38f226
-		   mailbox->quota_mailbox_used, mailbox->quota.root);
38f226
-	}
38f226
-	else
38f226
-	    quota_commit(&tid);
38f226
-    }
38f226
+    mailbox_updatequota(mailbox,NULL);
38f226
 
Tomas Janousek 7515ec
     /* Flush data (message file) directory */
Tomas Janousek 7515ec
     mailbox_delete_files(mailbox->path);
Tomas Janousek 7515ec
@@ -3392,3 +3372,48 @@
38f226
 	if (*p == '.') *p = '/';
38f226
     }
38f226
 }
38f226
+
38f226
+/* This function is used to update the quota. Can be used to replace
Tomas Janousek 7515ec
+ * identical parts of the code, and can be quite handy some times
38f226
+ * The tid is used in order to make possible to make the quota update
38f226
+ * being a part of a bigger transaction to the quota db */
38f226
+int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid)
38f226
+{
38f226
+    int r = 0, havetid = 0;
38f226
+    struct txn **ltid = NULL;
38f226
+
38f226
+    if(tid) {
38f226
+        ltid = tid;
38f226
+        havetid = 1;
38f226
+    }
38f226
+    /* Ensure that we are locked */
38f226
+    if(!mailbox->header_lock_count) return IMAP_INTERNAL;
38f226
+
38f226
+
38f226
+    if(mailbox->quota.root) {
38f226
+        r = quota_read(&mailbox->quota, ltid, 1);
38f226
+        if( r == 0 ) {
38f226
+            if (mailbox->quota.used >= mailbox->quota_mailbox_used) {
38f226
+                mailbox->quota.used -= mailbox->quota_mailbox_used;
38f226
+            }
38f226
+            else {
38f226
+                mailbox->quota.used = 0;
38f226
+            }
38f226
+            r = quota_write(&mailbox->quota, ltid);
38f226
+            if (r) {
38f226
+                syslog(LOG_ERR,
38f226
+                   "LOSTQUOTA: unable to record free of %lu bytes in quota %s",
38f226
+                   mailbox->quota_mailbox_used, mailbox->quota.root);
38f226
+            }
38f226
+            else if(!havetid)
9e566a
+                quota_commit(tid);
38f226
+        }
38f226
+        /* It is not a big mistake not to have quota .. just remove from the mailbox */
38f226
+        else if ( r == IMAP_QUOTAROOT_NONEXISTENT) {
38f226
+                free(mailbox->quota.root);
38f226
+                r = 0;
38f226
+        }
38f226
+    }
38f226
+    return r;
38f226
+}
38f226
+
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/mailbox.h cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mailbox.h
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/mailbox.h	2006-11-30 19:11:19.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mailbox.h	2007-02-21 16:35:20.000000000 +0200
Tomas Janousek 7515ec
@@ -364,6 +364,8 @@
38f226
 			  struct mailbox *mailboxp);
38f226
 extern int mailbox_delete(struct mailbox *mailbox, int delete_quota_root);
38f226
 
38f226
+extern int mailbox_updatequota(struct mailbox *mailbox, struct txn **tid);
38f226
+
38f226
 extern int mailbox_rename_copy(struct mailbox *oldmailbox, 
9e566a
 			       const char *newname, char *newpartition,
38f226
 			       bit32 *olduidvalidityp, bit32 *newuidvalidityp,
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/mboxlist.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mboxlist.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/mboxlist.c	2007-02-05 20:41:47.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mboxlist.c	2007-02-21 16:35:29.000000000 +0200
Tomas Janousek 7515ec
@@ -95,6 +95,12 @@
38f226
 static int mboxlist_opensubs();
38f226
 static void mboxlist_closesubs();
38f226
 
38f226
+static int child_cb(char *name,
38f226
+                    int matchlen __attribute__((unused)),
38f226
+                    int maycreate __attribute__((unused)),
38f226
+                    void *rock);
38f226
+
Tomas Janousek 7515ec
+
38f226
 static int mboxlist_rmquota(const char *name, int matchlen, int maycreate,
38f226
 			    void *rock);
38f226
 static int mboxlist_changequota(const char *name, int matchlen, int maycreate,
Tomas Janousek 7515ec
@@ -102,6 +108,7 @@
38f226
 
38f226
 struct change_rock {
38f226
     struct quota *quota;
38f226
+    struct quota *oldquota;
38f226
     struct txn **tid;
38f226
 };
38f226
 
Tomas Janousek 7515ec
@@ -889,9 +896,9 @@
38f226
  */
38f226
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
38f226
 			   struct auth_state *auth_state, int checkacl,
38f226
-			   int local_only, int force)
38f226
+			   int local_only, int force, int keepQuota)
38f226
 {
38f226
-    int r;
38f226
+    int r, has_children = 0;
38f226
     char *acl;
38f226
     long access;
38f226
     struct mailbox mailbox;
Tomas Janousek 7515ec
@@ -902,6 +909,7 @@
9e566a
     int mbtype;
38f226
     const char *p;
38f226
     mupdate_handle *mupdate_h = NULL;
38f226
+    char *quotaroot = NULL;
38f226
 
38f226
     if(!isadmin && force) return IMAP_PERMISSION_DENIED;
38f226
 
Tomas Janousek 7515ec
@@ -1014,15 +1022,47 @@
38f226
 
38f226
     if ((r && !force) || isremote) goto done;
38f226
 
38f226
-    if (!r || force) r = mailbox_delete(&mailbox, deletequotaroot);
38f226
+    if (!r || force) {
38f226
+        /* first we have to keep the previous quota root in order to delete it */
38f226
+        if(mailbox.quota.root)
38f226
+                quotaroot = xstrdup(mailbox.quota.root);
Tomas Janousek 7515ec
+        r = mailbox_delete(&mailbox, deletequotaroot);
38f226
+    }
Tomas Janousek 7515ec
+
38f226
 
38f226
     /*
38f226
      * See if we have to remove mailbox's quota root
38f226
      */
38f226
-    if (!r && mailbox.quota.root != NULL) {
Tomas Janousek 7515ec
-	/* xxx look for any other mailboxes in this quotaroot */
38f226
+    if (!r && quotaroot != NULL) {
Tomas Janousek 7515ec
+        /* xxx look for any other mailboxes in this quotaroot */
Tomas Janousek 7515ec
+        /* If we have not asked to remove the quota (default behaviour), we check
38f226
+         * whether there are any subfolders beneeth the quota root. If there aren't
38f226
+         * any subfolders the reasonable thing is to delete the quota */
38f226
+        if(keepQuota) {
38f226
+            char pattern[MAX_MAILBOX_PATH+1];
38f226
+            strlcpy(pattern, quotaroot, sizeof(pattern));
38f226
+            if (config_virtdomains && name[strlen(name)-1] == '!') {
38f226
+                strlcat(pattern, "*", sizeof(pattern));
38f226
+            }
38f226
+            else {
38f226
+                strlcat(pattern, ".*", sizeof(pattern));
Tomas Janousek 7515ec
+            }   
Tomas Janousek 7515ec
+                /* find if there are subfolders. Then we want to
Tomas Janousek 7515ec
+                 * keep the existing quota */
38f226
+            mboxlist_findall(NULL, pattern, isadmin, userid,
38f226
+                    auth_state, child_cb, (void *) &has_children);
38f226
+
Tomas Janousek 7515ec
+            if(!has_children)
Tomas Janousek 7515ec
+                if(!mboxlist_mylookup(quotaroot, NULL, NULL, NULL, NULL, NULL, 0, 1))
Tomas Janousek 7515ec
+                    has_children = 1;
38f226
+        }
38f226
+        /* If we want to remove the quota explicitely or the quota root folder has no subfolders
38f226
+         * we execute the rmquota patch */
38f226
+        if(!keepQuota || !has_children )
38f226
+            mboxlist_unsetquota(quotaroot);
38f226
+        free(quotaroot);
38f226
     }
Tomas Janousek 7515ec
-
Tomas Janousek 7515ec
+    
38f226
  done:
Tomas Janousek 7515ec
     if(r && tid && !force) {
Tomas Janousek 7515ec
 	/* Abort the transaction if it is still in progress */
Tomas Janousek 7515ec
@@ -2483,6 +2523,7 @@
38f226
     if (r) return r;
38f226
 
38f226
     crock.quota = "a;
38f226
+    crock.oldquota = NULL;
38f226
     crock.tid = &tid;
38f226
     /* top level mailbox */
38f226
     if(have_mailbox)
Tomas Janousek 7515ec
@@ -2501,15 +2542,19 @@
38f226
  */
38f226
 int mboxlist_unsetquota(const char *root)
38f226
 {
38f226
+    char newquota[MAX_MAILBOX_PATH+1];
38f226
     char pattern[MAX_MAILBOX_PATH+1];
38f226
     struct quota quota;
38f226
-    int r=0;
38f226
+    struct change_rock crock;
38f226
+    int r=0, k=0;
38f226
 
38f226
     if (!root[0] || root[0] == '.' || strchr(root, '/')
38f226
 	|| strchr(root, '*') || strchr(root, '%') || strchr(root, '?')) {
38f226
 	return IMAP_MAILBOX_BADNAME;
38f226
     }
38f226
     
Tomas Janousek 7515ec
+    crock.tid=NULL;
Tomas Janousek 7515ec
+    
38f226
     quota.root = (char *) root;
Tomas Janousek 7515ec
     r = quota_read("a, NULL, 0);
38f226
     if (r == IMAP_QUOTAROOT_NONEXISTENT) {
Tomas Janousek 7515ec
@@ -2534,9 +2579,47 @@
Tomas Janousek 7515ec
     /* submailboxes - we're using internal names here */
Tomas Janousek 7515ec
     mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
38f226
 
38f226
-    r = quota_delete("a, NULL);
38f226
+    r = quota_delete("a, crock.tid);
38f226
+
38f226
+    /* If we cannot delete the quota then abort the operation */
38f226
+    if(!r) {
38f226
+       /* quota_findroot performs several checks that we can
38f226
+        * assume that are already done, and don't have to perform
38f226
+        * them again. One of them is that it returns 1 only if
38f226
+        * quotaroot exists.
38f226
+        */
38f226
+        if(quota_findroot(newquota, sizeof(newquota), root)) {
38f226
+            struct quota rootquota;
38f226
+            rootquota.root = newquota;
38f226
+            k = quota_read(&rootquota, crock.tid, 0);
38f226
+            if (!k) {
38f226
+                crock.quota = &rootquota;
38f226
+                crock.oldquota = "a;
38f226
+                /* top level mailbox */
38f226
+                k = mboxlist_changequota(root, 0, 0, &crock);
38f226
+            }
38f226
+            /* submailboxes - we're using internal names here */
38f226
+            if (!k)
38f226
+                k = mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_changequota, &crock);
38f226
+            if(!k)
38f226
+                k = quota_write(&rootquota, crock.tid);
38f226
+
38f226
+         }
38f226
+         else {
38f226
+           /* top level mailbox */
38f226
+           mboxlist_rmquota(root, 0, 0, (void *)root);
38f226
+           /* submailboxes - we're using internal names here */
38f226
+           mboxlist_findall(NULL, pattern, 1, 0, 0, mboxlist_rmquota, (void *)root);
38f226
+       }
38f226
+    }
38f226
+
38f226
+    if(!r && !k)
38f226
+        quota_commit(crock.tid);
38f226
+    else
38f226
+        quota_abort(crock.tid);
38f226
 
38f226
     return r;
Tomas Janousek 7515ec
+
38f226
 }
Tomas Janousek 7515ec
 
Tomas Janousek 7515ec
 /*
Tomas Janousek 7515ec
@@ -2632,6 +2715,7 @@
38f226
     struct mailbox mailbox;
38f226
     struct change_rock *crock = (struct change_rock *) rock;
38f226
     struct quota *mboxlist_newquota = crock->quota;
38f226
+    struct quota *mboxlist_oldquota = crock->oldquota;
38f226
     struct txn **tid = crock->tid;
38f226
 
38f226
     assert(rock != NULL);
Tomas Janousek 7515ec
@@ -2649,27 +2733,24 @@
38f226
     if (r) goto error;
38f226
 
38f226
     if (mailbox.quota.root) {
38f226
-	if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
38f226
-	    /* Part of a child quota root */
38f226
-	    mailbox_close(&mailbox);
38f226
-	    return 0;
38f226
-	}
38f226
-
38f226
-	r = quota_read(&mailbox.quota, tid, 1);
38f226
-	if (r) goto error;
38f226
-	if (mailbox.quota.used >= mailbox.quota_mailbox_used) {
38f226
-	    mailbox.quota.used -= mailbox.quota_mailbox_used;
Tomas Janousek 7515ec
-	}
Tomas Janousek 7515ec
-	else {
38f226
-	    mailbox.quota.used = 0;
38f226
-	}
38f226
-	r = quota_write(&mailbox.quota, tid);
38f226
-	if (r) {
38f226
-	    syslog(LOG_ERR,
9e566a
-		   "LOSTQUOTA: unable to record free of " UQUOTA_T_FMT " bytes in quota %s",
38f226
-		   mailbox.quota_mailbox_used, mailbox.quota.root);
Tomas Janousek 7515ec
-	}
38f226
-	free(mailbox.quota.root);
Tomas Janousek 7515ec
+        if(mboxlist_oldquota) {
Tomas Janousek 7515ec
+            if (strlen(mailbox.quota.root) > strlen(mboxlist_oldquota->root)) {
Tomas Janousek 7515ec
+                /* Part of a child quota root */
Tomas Janousek 7515ec
+                mailbox_close(&mailbox);
Tomas Janousek 7515ec
+                return 0;
Tomas Janousek 7515ec
+            }
Tomas Janousek 7515ec
+        }
Tomas Janousek 7515ec
+        else {
Tomas Janousek 7515ec
+            if (strlen(mailbox.quota.root) >= strlen(mboxlist_newquota->root)) {
Tomas Janousek 7515ec
+                /* Part of a child quota root */
Tomas Janousek 7515ec
+                mailbox_close(&mailbox);
Tomas Janousek 7515ec
+                return 0;
Tomas Janousek 7515ec
+            }
Tomas Janousek 7515ec
+        }
38f226
+
Tomas Janousek 7515ec
+        r = mailbox_updatequota(&mailbox,tid);
Tomas Janousek 7515ec
+        if (r)
Tomas Janousek 7515ec
+            goto error;
38f226
     }
38f226
 
38f226
     mailbox.quota.root = xstrdup(mboxlist_newquota->root);
Tomas Janousek 7515ec
@@ -2682,6 +2763,11 @@
Tomas Janousek 7515ec
 
38f226
  error:
38f226
     mailbox_close(&mailbox);
38f226
+    syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s. \
38f226
+                        Command aborted. Run reconstruct to make sure mailboxes \
38f226
+                         are in consistent state",
38f226
+           name, mboxlist_newquota->root, error_message(r));
38f226
+    return 1;
38f226
  error_noclose:
38f226
     syslog(LOG_ERR, "LOSTQUOTA: unable to change quota root for %s to %s: %s",
Tomas Janousek 7515ec
 	   name, mboxlist_newquota->root, error_message(r));
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/mboxlist.h cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mboxlist.h
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/mboxlist.h	2006-11-30 19:11:19.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mboxlist.h	2007-02-21 16:35:34.000000000 +0200
Tomas Janousek 7515ec
@@ -126,7 +126,7 @@
38f226
  * the planet */
38f226
 int mboxlist_deletemailbox(const char *name, int isadmin, char *userid, 
38f226
 			   struct auth_state *auth_state, int checkacl,
38f226
-			   int local_only, int force);
38f226
+			   int local_only, int force, int keepQuota);
38f226
 
38f226
 /* Rename/move a mailbox (hierarchical) */
38f226
 int mboxlist_renamemailbox(char *oldname, char *newname, char *partition, 
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/mupdate.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mupdate.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/mupdate.c	2007-01-31 16:10:05.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/mupdate.c	2007-02-21 16:35:44.000000000 +0200
Tomas Janousek 7515ec
@@ -2313,7 +2313,7 @@
38f226
 	    remote_boxes.head = r->next;
38f226
 	} else if (ret < 0) {
38f226
 	    /* Local without corresponding remote, delete it */
38f226
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
38f226
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
38f226
 	    local_boxes.head = l->next;
38f226
 	} else /* (ret > 0) */ {
38f226
 	    /* Remote without corresponding local, insert it */
Tomas Janousek 7515ec
@@ -2328,7 +2328,7 @@
38f226
     if(l && !r) {
38f226
 	/* we have more deletes to do */
38f226
 	while(l) {
38f226
-	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0);
38f226
+	    mboxlist_deletemailbox(l->mailbox, 1, "", NULL, 0, 0, 0, 1);
38f226
 	    local_boxes.head = l->next;
38f226
 	    l = local_boxes.head;
38f226
 	}
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/nntpd.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/nntpd.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/nntpd.c	2007-02-05 20:49:56.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/nntpd.c	2007-02-21 16:35:53.000000000 +0200
Tomas Janousek 7515ec
@@ -3358,7 +3358,7 @@
38f226
     /* XXX should we delete right away, or wait until empty? */
38f226
 
38f226
     r = mboxlist_deletemailbox(mailboxname, 0,
38f226
-			       newsmaster, newsmaster_authstate, 1, 0, 0);
38f226
+			       newsmaster, newsmaster_authstate, 1, 0, 0, 1);
38f226
 
9e566a
     if (!r) sync_log_mailbox(mailboxname);
9e566a
 
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/sync_reset.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/sync_reset.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/sync_reset.c	2006-11-30 19:11:20.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/sync_reset.c	2007-02-22 13:23:41.000000000 +0200
Tomas Janousek 7515ec
@@ -258,7 +258,7 @@
9e566a
     if (r) goto fail;
9e566a
 
9e566a
     for (item = list->head ; item ; item = item->next) {
9e566a
-        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0);
9e566a
+        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0, 1);
9e566a
 
9e566a
         if (r) goto fail;
9e566a
     }
Tomas Janousek 7515ec
@@ -274,7 +274,7 @@
9e566a
     if (r) goto fail;
9e566a
 
9e566a
     for (item = list->head ; item ; item = item->next) {
9e566a
-        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0);
9e566a
+        r=mboxlist_deletemailbox(item->name, 1, NULL, sync_authstate, 1, 0, 0, 1);
9e566a
 
9e566a
         if (r) goto fail;
9e566a
     }
Tomas Janousek 7515ec
@@ -282,7 +282,7 @@
9e566a
 
9e566a
     /* Nuke inbox (recursive nuke possible?) */
9e566a
     snprintf(buf, sizeof(buf)-1, "user.%s", user);
9e566a
-    r = mboxlist_deletemailbox(buf, 1, "cyrus", sync_authstate, 1, 0, 0);
9e566a
+    r = mboxlist_deletemailbox(buf, 1, "cyrus", sync_authstate, 1, 0, 0, 1);
9e566a
     if (r && (r != IMAP_MAILBOX_NONEXISTENT)) goto fail;
9e566a
 
9e566a
     if ((r=user_deletedata(user, sync_userid, sync_authstate, 1)))
Tomas Janousek 7515ec
diff -Naur cyrus-imapd-2.3.8/imap/sync_server.c cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/sync_server.c
Tomas Janousek 7515ec
--- cyrus-imapd-2.3.8/imap/sync_server.c	2006-11-30 19:11:20.000000000 +0200
Tomas Janousek 7515ec
+++ cyrus-imapd-2.3.8-rmquota+deletemailbox.uncompiled/imap/sync_server.c	2007-02-22 13:24:17.000000000 +0200
Tomas Janousek 7515ec
@@ -1581,7 +1581,7 @@
9e566a
 
9e566a
     for (item = list->head ; item ; item = item->next) {
9e566a
         r=mboxlist_deletemailbox(item->name, sync_userisadmin, sync_userid,
9e566a
-				 sync_authstate, 0, 0, 1);
9e566a
+				 sync_authstate, 0, 0, 1, 1);
9e566a
 
9e566a
         if (r) goto fail;
9e566a
     }
Tomas Janousek 7515ec
@@ -1591,7 +1591,7 @@
9e566a
     (sync_namespacep->mboxname_tointernal)(sync_namespacep, "INBOX",
9e566a
 					   user, buf);
9e566a
     r = mboxlist_deletemailbox(buf, sync_userisadmin, sync_userid,
9e566a
-			       sync_authstate, 0, 0, 1);
9e566a
+			       sync_authstate, 0, 0, 1, 1);
9e566a
     if (r && (r != IMAP_MAILBOX_NONEXISTENT)) goto fail;
9e566a
 
9e566a
     if ((r=user_deletedata(user, sync_userid, sync_authstate, 1)))
Tomas Janousek 7515ec
@@ -2526,7 +2526,7 @@
9e566a
 
9e566a
     /* Delete with admin priveleges */
9e566a
     r = mboxlist_deletemailbox(name, sync_userisadmin, sync_userid,
9e566a
-			       sync_authstate, 0, 0, 1);
9e566a
+			       sync_authstate, 0, 0, 1, 1);
9e566a
 
9e566a
     if (r)
9e566a
         prot_printf(sync_out, "NO Failed to delete %s: %s\r\n",