--- org/dovecot-1.0.beta9/src/plugins/quota/quota-maildir.c	2006-06-11 18:28:11.000000000 -0400
+++ dovecot-1.0.beta9/src/plugins/quota/quota-maildir.c	2006-06-22 08:18:20.000000000 -0400
@@ -82,6 +82,7 @@
 
 	len = str_len(path);
 	while ((dp = readdir(dirp)) != NULL) {
+i_error("NEONOVA: Working on %s/%s", dir, dp->d_name);
 		p = strstr(dp->d_name, ",S=");
 		num = (uoff_t)-1;
 		if (p != NULL) {
@@ -94,6 +95,7 @@
 				/* not in expected format, fallback to stat() */
 				num = (uoff_t)-1;
 			} else {
+i_error("NEONOVA: Working on %s/%s - bytes %llu count %llu", dir, dp->d_name, (unsigned long long)*total_bytes, (unsigned long long)*total_count);
 				*total_bytes += num;
 				*total_count += 1;
 			}
@@ -101,6 +103,7 @@
 		if (num == (uoff_t)-1) {
 			struct stat st;
 
+i_error("NEONOVA: Need to run stat() on %s/%s", dir, dp->d_name);
 			str_truncate(path, len);
 			str_append(path, dp->d_name);
 			if (stat(str_c(path), &st) == 0) {
@@ -119,6 +122,7 @@
 					  dir);
 		return -1;
 	}
+	i_error("NEONOVA: complete returning bytes %llu count %llu", (unsigned long long)*total_bytes, (unsigned long long)*total_count);
 	return ret;
 }
 
@@ -211,7 +215,8 @@
 	struct dotlock *dotlock;
 	string_t *str;
 	int fd;
-
+ 
+        i_error("NEONOVA: maildirsize_write(): beginning.");
 	fd = file_dotlock_open(&dotlock_settings, path,
 			       DOTLOCK_CREATE_FLAG_NONBLOCK, &dotlock);
 	if (fd == -1) {
@@ -229,16 +234,19 @@
 	if (root->message_bytes_limit != (uint64_t)-1) {
 		str_printfa(str, "%lluS",
 			    (unsigned long long)root->message_bytes_limit);
+        	i_error("NEONOVA: maildirsize_write(): wrote S limit of %lluS.", (unsigned long long)root->message_bytes_limit);
 	}
 	if (root->message_count_limit != (uint64_t)-1) {
 		if (str_len(str) > 0)
 			str_append_c(str, ',');
 		str_printfa(str, "%lluC",
 			    (unsigned long long)root->message_count_limit);
+        	i_error("NEONOVA: maildirsize_write(): wrote C limit of %lluC.", (unsigned long long)root->message_count_limit);
 	}
 	str_printfa(str, "\n%llu %llu\n",
 		    (unsigned long long)root->total_bytes,
 		    (unsigned long long)root->total_count);
+       	i_error("NEONOVA: maildirsize_write(): wrote usage of %llu %llu.", (unsigned long long)root->total_bytes, (unsigned long long)root->total_count);
 	if (write_full(fd, str_data(str), str_len(str)) < 0) {
 		mail_storage_set_critical(storage,
 			"write_full(%s) failed: %m", path);
@@ -251,6 +259,7 @@
 			"file_dotlock_replace(%s) failed: %m", path);
 		return -1;
 	}
+       	i_error("NEONOVA: maildirsize_write(): returning.");
 	return 0;
 }
 
@@ -268,6 +277,7 @@
 	time_t mtime, last_stamp = 0;
 	int ret = 0;
 
+	i_error("NEONOVA: maildirsize_recalculate(): beginning.");
 	root->total_bytes = root->total_count = 0;
 
 	ctx = maildir_list_init(storage);
@@ -292,9 +302,11 @@
 	path = maildirsize_get_path(storage);
 	if (ret == 0) {
 		/* maildir didn't change, we can write the maildirsize file */
+		i_error("NEONOVA: maildirsize_recalculate(): going to write the new maildirsize.");
 		ret = maildirsize_write(root, storage, path);
 	}
 	if (ret != 0) {
+		i_error("NEONOVA: maildirsize_recalculate(): forcing a rebuild later on maildirsize - unlink().");
 		/* make sure it gets rebuilt later */
 		if (unlink(path) < 0 && errno != ENOENT && errno != ESTALE) {
 			mail_storage_set_critical(storage,
@@ -317,8 +329,12 @@
 	const char *const *limit;
 	char *pos;
 
-	if (*lines == NULL)
+	i_error("NEONOVA: maildirsize_parse(): beginning.");
+
+	if (*lines == NULL) {
+		i_error("NEONOVA: maildirsize_parse(): *lines is NULL.");
 		return -1;
+	}
 
 	/* first line contains the limits. 0 value mean unlimited. */
 	message_bytes_limit = (uint64_t)-1;
@@ -343,30 +359,37 @@
 		/* we don't know the limits, use whatever the file says */
 		root->message_bytes_limit = message_bytes_limit;
 		root->message_count_limit = message_count_limit;
+		i_error("NEONOVA: maildirsize_parse(): using limits from maildirsize.");
 	} else if (root->message_bytes_limit != message_bytes_limit ||
 		   root->message_count_limit != message_count_limit) {
 		/* we know the limits and they've changed.
 		   the file must be rewritten. */
+		i_error("NEONOVA: maildirsize_parse(): limits have changed.");
 		return 0;
 	}
 
 	/* rest of the lines contains <bytes> <count> diffs */
 	total_bytes = 0; total_count = 0;
 	for (lines++; **lines != '\0'; lines++, line_count++) {
-		if (sscanf(*lines, "%lld %d", &bytes_diff, &count_diff) != 2)
+		if (sscanf(*lines, "%lld %d", &bytes_diff, &count_diff) != 2) {
+			i_error("NEONOVA: maildirsize_parse(): sscanf() failed.");
 			return -1;
-
+		}
 		total_bytes += bytes_diff;
 		total_count += count_diff;
+		i_error("NEONOVA: maildirsize_parse(): read total bytes %d count %d", (int)total_bytes, (int)total_count);
 	}
 	/* we end always with LF, which shows up as empty last line. there
 	   should be no other empty lines */
-	if (lines[1] != NULL)
+	if (lines[1] != NULL) {
+		i_error("NEONOVA: maildirsize_parse(): lines[1] != NULL");
 		return -1;
+	}
 
 	if (total_bytes < 0 || total_count < 0) {
 		/* corrupted */
 		return -1;
+		i_error("NEONOVA: maildirsize_parse(): maildirsize corrupted.");
 	}
 
 	if ((uint64_t)total_bytes > root->message_bytes_limit ||
@@ -396,6 +419,7 @@
 	unsigned int size;
 	int fd, ret;
 
+	i_error("NEONOVA: starting maildirsize_read()");
 	t_push();
 	path = maildirsize_get_path(storage);
 	if (root->fd != -1) {
@@ -419,6 +443,7 @@
 		return ret;
 	}
 
+	i_error("NEONOVA: maildirsize_read() in stage 2.");
 	/* @UNSAFE */
 	size = 0;
 	while (size < sizeof(buf)-1 &&
@@ -435,9 +460,11 @@
 		/* error / recalculation needed. */
 		(void)close(fd);
 		t_pop();
+		i_error("NEONOVA: maildirsize_read() recalculation needed.");
 		return ret < 0 ? -1 : 0;
 	}
 
+	i_error("NEONOVA: maildirsize_read() maildirsize is usable.");
 	/* file is smaller than 5120 bytes, which means we can use it */
 	root->total_bytes = root->total_count = 0;
 
@@ -452,9 +479,11 @@
 		/* broken file / need recalculation */
 		(void)close(root->fd);
 		root->fd = -1;
+		i_error("NEONOVA: maildirsize_read() maildirsize is broken.");
 		ret = 0;
 	}
 	t_pop();
+	i_error("NEONOVA: maildirsize_read() returning.");
 	return ret;
 }
 
@@ -462,17 +491,20 @@
 				struct mail_storage *storage)
 {
 	int ret;
+	i_error("NEONOVA: maildirquota_refresh() starting.");
 
 	ret = maildirsize_read(root, storage);
 	if (ret == 0) {
 		if (root->message_bytes_limit == (uint64_t)-1 &&
 		    root->message_count_limit == (uint64_t)-1) {
 			/* no quota */
+			i_error("NEONOVA: maildirquota_refresh() determined quotas are off..");
 			return 0;
 		}
 
 		ret = maildirsize_recalculate(root, storage);
 	}
+	i_error("NEONOVA: maildirquota_refresh() returning.");
 	return ret < 0 ? -1 : 0;
 }
 
