changeset 267:54b3b82bd73e HEAD

Handle 1-bytes mbox files (just \n) without any warnings, and expunging all mails now doesn't write the \n.
author Timo Sirainen <tss@iki.fi>
date Tue, 17 Sep 2002 06:01:25 +0300
parents 757c32a1920d
children 7cb03d43a0ea
files src/lib-index/mbox/mbox-append.c src/lib-index/mbox/mbox-fsck.c src/lib-storage/index/mbox/mbox-expunge.c
diffstat 3 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mbox/mbox-append.c	Tue Sep 17 04:51:11 2002 +0300
+++ b/src/lib-index/mbox/mbox-append.c	Tue Sep 17 06:01:25 2002 +0300
@@ -168,7 +168,8 @@
 
 int mbox_index_append(MailIndex *index, IOBuffer *inbuf)
 {
-	if (inbuf->offset == inbuf->size) {
+	if (inbuf->offset == inbuf->size ||
+	    inbuf->offset+1 == inbuf->size) {
 		/* no new data */
 		return TRUE;
 	}
--- a/src/lib-index/mbox/mbox-fsck.c	Tue Sep 17 04:51:11 2002 +0300
+++ b/src/lib-index/mbox/mbox-fsck.c	Tue Sep 17 06:01:25 2002 +0300
@@ -195,8 +195,9 @@
 	if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE))
 		return FALSE;
 
-	/* first make sure we start with a "From " line. */
-	if (io_buffer_read_data_blocking(inbuf, &data, &size, 5) < 0 ||
+	/* first make sure we start with a "From " line. If file is too
+	   small, we'll just treat it as empty mbox file. */
+	if (io_buffer_read_data_blocking(inbuf, &data, &size, 5) > 0 &&
 	    strncmp(data, "From ", 5) != 0) {
 		index_set_error(index, "File isn't in mbox format: %s",
 				index->mbox_path);
--- a/src/lib-storage/index/mbox/mbox-expunge.c	Tue Sep 17 04:51:11 2002 +0300
+++ b/src/lib-storage/index/mbox/mbox-expunge.c	Tue Sep 17 06:01:25 2002 +0300
@@ -92,9 +92,13 @@
 	io_buffer_skip(inbuf, end_offset - inbuf->offset);
 
 	/* copy the rest as well, should be only \n but someone might
-	   as well just appended more data.. */
+	   as well just appended more data.. but if we've deleted all mail,
+	   don't write the only \n there. */
 	copy_size = inbuf->size - inbuf->offset;
-	return io_buffer_send_iobuffer(outbuf, inbuf, copy_size) > 0;
+	if (outbuf->offset == 0 && copy_size == 1)
+		return TRUE;
+	else
+		return io_buffer_send_iobuffer(outbuf, inbuf, copy_size) > 0;
 }
 
 int mbox_expunge_locked(IndexMailbox *ibox,