? src/deliver
? src/swig
? src/auth/lmpass.c
? src/auth/start.sh
? src/auth/userdb-checkpassword.c
? src/imap/19700101-030000-1343.in
? src/imap/a
? src/imap/b
? src/imap/log
? src/imap/test.sh
? src/lib/ioloop-poll-buffer.c
? src/lib/test
? src/lib/test.c
? src/lib-index/test
? src/lib-index/test.c
? src/lib-mail/x
? src/lib-storage/index/mbox/diff
? src/master/ssl-init-openssl.c.new
? src/pop3/log
Index: src/lib/failures.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/failures.c,v
retrieving revision 1.25
diff -u -r1.25 failures.c
--- src/lib/failures.c	9 Jul 2004 19:08:35 -0000	1.25
+++ src/lib/failures.c	11 Sep 2004 20:29:23 -0000
@@ -219,6 +219,26 @@
 	va_end(args);
 }
 
+#include <sys/time.h>
+#include <unistd.h>
+void i_debug(const char *format, ...)
+{
+	FILE *f;
+	va_list args;
+	struct timeval tv;
+
+	gettimeofday(&tv, NULL);
+
+	va_start(args, format);
+	t_push();
+	f = fopen(t_strdup_printf("/tmp/dovecot.%d", getpid()), "a+");
+	fprintf(f, "%s.%s PID=%s %s\n", dec2str(tv.tv_sec), dec2str(tv.tv_usec),
+		dec2str(getpid()), t_strdup_vprintf(format, args));
+	fclose(f);
+	t_pop();
+	va_end(args);
+}
+
 void i_set_panic_handler(failure_callback_t *callback __attr_noreturn__)
 {
 	if (callback == NULL)
Index: src/lib/failures.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/failures.h,v
retrieving revision 1.9
diff -u -r1.9 failures.h
--- src/lib/failures.h	10 May 2004 16:05:10 -0000	1.9
+++ src/lib/failures.h	11 Sep 2004 20:29:23 -0000
@@ -22,6 +22,7 @@
 void i_error(const char *format, ...) __attr_format__(1, 2);
 void i_warning(const char *format, ...) __attr_format__(1, 2);
 void i_info(const char *format, ...) __attr_format__(1, 2);
+void i_debug(const char *format, ...) __attr_format__(1, 2);
 
 void i_fatal_status(int status, const char *format, ...)
 	__attr_format__(2, 3) __attr_noreturn__;
Index: src/lib-storage/index/mbox/mbox-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-file.c,v
retrieving revision 1.4
diff -u -r1.4 mbox-file.c
--- src/lib-storage/index/mbox/mbox-file.c	28 Aug 2004 17:41:52 -0000	1.4
+++ src/lib-storage/index/mbox/mbox-file.c	11 Sep 2004 20:29:23 -0000
@@ -95,6 +95,9 @@
 {
 	const void *data;
 	uint64_t offset;
+	const unsigned char *buf;
+	size_t bufsize;
+	uint32_t i;
 	int ret;
 
 	*deleted_r = FALSE;
@@ -122,8 +125,28 @@
 		mail_storage_set_critical(ibox->box.storage,
 			"Cached message offset %s is invalid for mbox file %s",
 			dec2str(offset), ibox->path);
-		mail_index_mark_corrupted(ibox->index);
-		return -1;
+
+		i_stream_seek(ibox->mbox_file_stream, offset - 200);
+		i_stream_read_data(ibox->mbox_file_stream, &buf, &bufsize, 400);
+		i_debug("mbox_file_seek: prev 200 bytes: '%.*s'",
+			(int)I_MIN(bufsize, 200), buf);
+		if (bufsize > 200) {
+			i_debug("mbox_file_seek: next 200 bytes: '%.*s'",
+				(int)I_MIN(bufsize-200, 200), buf + 200);
+		}
+
+		for (i = 1; i <= seq; i++) {
+			if (mail_index_lookup_extra(view, i,
+						    ibox->mbox_extra_idx,
+						    &data) <= 0)
+				continue;
+
+			offset = *((const uint64_t *)data);
+			ret = istream_raw_mbox_seek(ibox->mbox_stream, offset);
+			i_debug("mbox_file_seek: seq=%u, offset=%"PRIuUOFF_T", ret=%d",
+				i, offset, ret);
+		}
+		i_panic("broken");
 	}
 
 	if (ibox->mbox_sync_dirty) {
Index: src/lib-storage/index/mbox/mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.28
diff -u -r1.28 mbox-sync-rewrite.c
--- src/lib-storage/index/mbox/mbox-sync-rewrite.c	23 Aug 2004 07:51:53 -0000	1.28
+++ src/lib-storage/index/mbox/mbox-sync-rewrite.c	11 Sep 2004 20:29:23 -0000
@@ -455,6 +455,9 @@
 			mails[idx].space = padding_per_mail;
 		}
 
+		i_debug("mbox_sync_rewrite: seq=%u, space_diff=%"PRIuUOFF_T,
+			first_seq + idx, space_diff);
+
 		idx--;
 		if (mails[idx].space <= 0 &&
 		    (mails[idx].flags & MBOX_EXPUNGED) == 0) {
@@ -489,6 +492,8 @@
 
 		mails[idx+1].from_offset += space_diff;
 		mails[idx+1].offset += space_diff;
+		i_debug("mbox_sync_rewrite: seq=%u new from_offset=%"PRIuUOFF_T,
+			first_seq + idx + 1, mails[idx+1].from_offset);
 
 		if ((mails[idx+1].flags & MBOX_DIRTY_SPACE) != 0) {
                         mails[idx+1].flags &= ~MBOX_DIRTY_SPACE;
Index: src/lib-storage/index/mbox/mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.85
diff -u -r1.85 mbox-sync.c
--- src/lib-storage/index/mbox/mbox-sync.c	11 Sep 2004 20:20:25 -0000	1.85
+++ src/lib-storage/index/mbox/mbox-sync.c	11 Sep 2004 20:29:24 -0000
@@ -126,6 +126,9 @@
 	mail_ctx->mail.offset =
 		istream_raw_mbox_get_header_offset(sync_ctx->input);
 
+	i_debug("mbox_sync_read_next_mail: seq=%u, from_offset=%"PRIuUOFF_T,
+		mail_ctx->seq, mail_ctx->mail.from_offset);
+
 	if (mail_ctx->seq == 1)
 		sync_ctx->seen_first_mail = TRUE;
 	if (mail_ctx->seq > 1 && sync_ctx->dest_first_mail) {
@@ -342,10 +345,17 @@
 		}
 
 		if (data != NULL &&
-		    *((const uint64_t *)data) == mail->from_offset)
+		    *((const uint64_t *)data) == mail->from_offset) {
+			i_debug("mbox_sync_update_from_offset: "
+				"seq=%u unchanged (%"PRIuUOFF_T")",
+				sync_ctx->seq, mail->from_offset);
 			return 0;
+		}
 	}
 
+	i_debug("mbox_sync_update_from_offset: seq=%u %"PRIuUOFF_T,
+		sync_ctx->seq, mail->from_offset);
+
 	offset = mail->from_offset;
 	mail_index_update_extra_rec(sync_ctx->t, sync_ctx->idx_seq,
 				    sync_ctx->ibox->mbox_extra_idx, &offset);
@@ -485,6 +495,8 @@
 			continue;
 
 		offset = mails[idx].from_offset;
+		i_debug("update_from_offsets: seq=%u, offset=%llu",
+			mails[idx].idx_seq, offset);
 		mail_index_update_extra_rec(sync_ctx->t, mails[idx].idx_seq,
 					    extra_idx, &offset);
 	}
@@ -498,9 +510,13 @@
 		mail_ctx->mail.body_size;
 	mail_ctx->mail.body_size = 0;
 
+	i_debug("mbox_sync_handle_expunge: seq=%u, space=%"PRIuUOFF_T,
+		mail_ctx->seq, mail_ctx->mail.space);
+
 	if (mail_ctx->sync_ctx->dest_first_mail) {
 		/* expunging first message, fix space to contain next
 		   message's \n header too since it will be removed. */
+		i_debug("mbox_sync_handle_expunge:  - dest_first_mail");
 		mail_ctx->mail.space++;
 	}
 
@@ -519,6 +535,8 @@
 	if (sync_ctx->expunged_space > 0 && sync_ctx->need_space_seq == 0) {
 		/* move the header backwards to fill expunged space */
 		move_diff = -sync_ctx->expunged_space;
+		i_debug("mbox_sync_handle_header: seq=%u, move_diff=%lld",
+			mail_ctx->seq, (long long)move_diff);
 
 		/* read the From-line before rewriting overwrites it */
 		if (mbox_read_from_line(mail_ctx) < 0)
@@ -534,6 +552,10 @@
 			   new location */
 			mail_ctx->mail.from_offset += move_diff;
 			mail_ctx->mail.offset += move_diff;
+			i_debug("mbox_sync_handle_header: seq=%u, "
+				"moving backwards rewrite successful. "
+				"new from_offset=%"PRIuUOFF_T, mail_ctx->seq,
+				mail_ctx->mail.from_offset);
 			if (mbox_write_from_line(mail_ctx) < 0)
 				return -1;
 		}
@@ -558,6 +580,10 @@
 			/* create dummy message to describe the expunged data */
 			struct mbox_sync_mail mail;
 
+			i_debug("mbox_sync_handle_header: seq=%u, "
+				"creating dummy expunged message at "
+				"offset=%"PRIuUOFF_T, mail_ctx->seq,
+				mail_ctx->mail.from_offset);
 			memset(&mail, 0, sizeof(mail));
 			mail.flags = MBOX_EXPUNGED;
 			mail.offset = mail_ctx->mail.from_offset -
@@ -618,6 +644,8 @@
 	uoff_t old_offset;
 	int ret, deleted;
 
+	i_debug("mbox_sync_seek_to_seq: %u", seq);
+
 	if (seq == 0) {
 		if (istream_raw_mbox_seek(ibox->mbox_stream, 0) < 0) {
 			mail_storage_set_error(ibox->box.storage,
@@ -686,6 +714,10 @@
 
 	messages_count = mail_index_view_get_message_count(sync_ctx->sync_view);
 
+	i_debug("mbox_sync_loop: have_more=%d, partial=%d, min_message_count=%d",
+		mail_index_sync_have_more(sync_ctx->index_sync_ctx),
+		partial, min_message_count);
+
 	if (!mail_index_sync_have_more(sync_ctx->index_sync_ctx) ||
 	    (!partial && min_message_count != 0)) {
 		ret = mbox_sync_seek_to_seq(sync_ctx, partial ?
@@ -1011,10 +1043,12 @@
 			/* file is fully synced */
 			sync_ctx->ibox->mbox_sync_dirty = FALSE;
 			min_msg_count = 0;
+			i_debug("mbox_sync_do: mbox is synced");
 		} else if ((flags & MBOX_SYNC_UNDIRTY) != 0) {
 			/* we want to do full syncing */
 			min_msg_count = (uint32_t)-1;
 			sync_ctx->ibox->mbox_sync_dirty = TRUE;
+			i_debug("mbox_sync_do: do full syncing");
 		} else {
 			/* see if we can delay syncing the whole file.
 			   normally we only notice expunges and appends
@@ -1022,6 +1056,7 @@
 			partial = TRUE;
 			min_msg_count = (uint32_t)-1;
 			sync_ctx->ibox->mbox_sync_dirty = TRUE;
+			i_debug("mbox_sync_do: do partial syncing");
 		}
 	}
 
@@ -1032,6 +1067,7 @@
 			return -1;
 
 		/* partial syncing didn't work, do it again */
+		i_debug("mbox_sync_do: --- partial syncing didn't work. restart.");
 		mbox_sync_restart(sync_ctx);
 		if (mbox_sync_loop(sync_ctx, &mail_ctx,
 				   (uint32_t)-1, FALSE) < 0)
@@ -1071,6 +1107,8 @@
 	if ((uint32_t)st.st_mtime == hdr->sync_stamp &&
 	    (uint64_t)st.st_size == hdr->sync_size) {
 		/* fully synced */
+		if (ibox->mbox_sync_dirty)
+			i_debug("mbox_sync_has_changed: undirty");
 		ibox->mbox_sync_dirty = FALSE;
 		return 0;
 	}
@@ -1120,6 +1158,8 @@
 	if (!ibox->mbox_do_dirty_syncs)
 		flags |= MBOX_SYNC_UNDIRTY;
 
+	i_debug("mbox_sync: flags=%x", flags);
+
 	if ((flags & MBOX_SYNC_LOCK_READING) != 0) {
 		if (mbox_lock(ibox, F_RDLCK, &lock_id) <= 0)
 			return -1;
@@ -1130,10 +1170,11 @@
 	else {
 		int leave_dirty = (flags & MBOX_SYNC_UNDIRTY) == 0;
 		if ((changed = mbox_sync_has_changed(ibox, leave_dirty)) < 0) {
-			if ((flags & MBOX_SYNC_LOCK_READING) != 0)
+ 			if ((flags & MBOX_SYNC_LOCK_READING) != 0)
 				(void)mbox_unlock(ibox, lock_id);
 			return -1;
 		}
+		i_debug("mbox_sync: changed=%d", changed);
 	}
 
 	if ((flags & MBOX_SYNC_LOCK_READING) != 0) {
@@ -1173,6 +1214,7 @@
 			mail_storage_set_index_error(ibox);
 		if (lock_id != 0)
 			(void)mbox_unlock(ibox, lock_id);
+		i_debug("mbox_sync: nothing to sync from index");
 		return ret;
 	}
 
@@ -1187,6 +1229,7 @@
 			mail_storage_set_index_error(ibox);
 			return -1;
 		}
+		i_debug("mbox_sync: nothing to do");
 		return 0;
 	}
 
@@ -1226,6 +1269,7 @@
 
 	if (mbox_sync_do(&sync_ctx, flags) < 0)
 		ret = -1;
+	i_debug("mbox_sync: --- %d", ret);
 
 	if (ret < 0)
 		mail_index_transaction_rollback(sync_ctx.t);
@@ -1251,6 +1295,7 @@
 		/* rewrite X-IMAPbase header. do it after mail_index_sync_end()
 		   so previous transactions have been committed. */
 		/* FIXME: ugly .. */
+		i_debug("mbox_sync: rewrite x-imapbase");
 		ret = mail_index_sync_begin(ibox->index,
 					    &sync_ctx.index_sync_ctx,
 					    &sync_ctx.sync_view,
@@ -1275,6 +1320,7 @@
 				ret = -1;
 			}
 		}
+		i_debug("mbox_sync: ---2");
 	}
 
 	if (ret == 0 && ibox->mbox_lock_type == F_WRLCK) {
