changeset 266:757c32a1920d HEAD

expunging last message from mbox duplicated the whole file. appending mail to mbox works now too.
author Timo Sirainen <tss@iki.fi>
date Tue, 17 Sep 2002 04:51:11 +0300
parents d0ba9a65891c
children 54b3b82bd73e
files src/lib-index/mbox/mbox-from.c src/lib-storage/index/mbox/mbox-expunge.c src/lib-storage/index/mbox/mbox-save.c
diffstat 3 files changed, 44 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mbox/mbox-from.c	Tue Sep 17 04:49:45 2002 +0300
+++ b/src/lib-index/mbox/mbox-from.c	Tue Sep 17 04:51:11 2002 +0300
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
+#include "temp-string.h"
 #include "mbox-index.h"
 
 #include <time.h>
@@ -93,55 +94,54 @@
 
 const char *mbox_from_create(const char *sender, time_t time)
 {
+	TempString *str;
 	struct tm *tm;
-	char *ret, *p;
-	size_t len;
 	int year;
 
-	len = strlen(sender);
-	ret = t_malloc(len + 24 + 1);
-	memcpy(ret, sender, len);
+	str = t_string_new(256);
+	t_string_append(str, "From ");
+	t_string_append(str, sender);
+	t_string_append(str, "  ");
 
 	/* we could use simply asctime(), but i18n etc. may break it.
 	   Example: "Thu Nov 29 22:33:52 2001" */
 	tm = localtime(&time);
-	p = ret + len;
 
 	/* week day */
-	strcpy(p, weekdays[tm->tm_wday]); p += 3;
-	*p++ = ' ';
+	t_string_append(str, weekdays[tm->tm_wday]);
+	t_string_append_c(str, ' ');
 
 	/* month */
-	strcpy(p, months[tm->tm_mon]); p += 3;
-	*p++ = ' ';
+	t_string_append(str, months[tm->tm_mon]);
+	t_string_append_c(str, ' ');
 
 	/* day */
-	*p++ = (tm->tm_mday / 10) + '0';
-	*p++ = (tm->tm_mday % 10) + '0';
-	*p++ = ' ';
+	t_string_append_c(str, (tm->tm_mday / 10) + '0');
+	t_string_append_c(str, (tm->tm_mday % 10) + '0');
+	t_string_append_c(str, ' ');
 
 	/* hour */
-	*p++ = (tm->tm_hour / 10) + '0';
-	*p++ = (tm->tm_hour % 10) + '0';
-	*p++ = ':';
+	t_string_append_c(str, (tm->tm_hour / 10) + '0');
+	t_string_append_c(str, (tm->tm_hour % 10) + '0');
+	t_string_append_c(str, ':');
 
 	/* minute */
-	*p++ = (tm->tm_min / 10) + '0';
-	*p++ = (tm->tm_min % 10) + '0';
-	*p++ = ':';
+	t_string_append_c(str, (tm->tm_min / 10) + '0');
+	t_string_append_c(str, (tm->tm_min % 10) + '0');
+	t_string_append_c(str, ':');
 
 	/* second */
-	*p++ = (tm->tm_sec / 10) + '0';
-	*p++ = (tm->tm_sec % 10) + '0';
-	*p++ = ' ';
+	t_string_append_c(str, (tm->tm_sec / 10) + '0');
+	t_string_append_c(str, (tm->tm_sec % 10) + '0');
+	t_string_append_c(str, ' ');
 
 	/* year */
 	year = tm->tm_year + 1900;
-	*p++ = (year / 1000) + '0';
-	*p++ = ((year / 100) % 10) + '0';
-	*p++ = ((year / 10) % 10) + '0';
-	*p++ = (year % 10) + '0';
+	t_string_append_c(str, (year / 1000) + '0');
+	t_string_append_c(str, ((year / 100) % 10) + '0');
+	t_string_append_c(str, ((year / 10) % 10) + '0');
+	t_string_append_c(str, (year % 10) + '0');
 
-	*p++ = '\0';
-	return ret;
+	t_string_append_c(str, '\n');
+	return str->str;
 }
--- a/src/lib-storage/index/mbox/mbox-expunge.c	Tue Sep 17 04:49:45 2002 +0300
+++ b/src/lib-storage/index/mbox/mbox-expunge.c	Tue Sep 17 04:51:11 2002 +0300
@@ -89,6 +89,8 @@
 		seq++;
 	}
 
+	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.. */
 	copy_size = inbuf->size - inbuf->offset;
--- a/src/lib-storage/index/mbox/mbox-save.c	Tue Sep 17 04:49:45 2002 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Tue Sep 17 04:51:11 2002 +0300
@@ -34,14 +34,14 @@
 		return TRUE;
 
 	do {
-		if (lseek(fd, 0, pos-1) < 0)
+		if (lseek(fd, pos-1, SEEK_SET) < 0)
 			break;
 
 		if (read(fd, &ch, 1) != 1)
 			break;
 
 		if (ch != '\n') {
-			if (write_full(fd, &ch, 1) < 0)
+			if (write_full(fd, "\n", 1) < 0)
 				break;
 		}
 
@@ -52,6 +52,16 @@
 	return FALSE;
 }
 
+static int mbox_append_lf(MailStorage *storage, int fd, const char *mbox_path)
+{
+	if (write_full(fd, "\n", 1) < 0) {
+		set_error(storage, mbox_path);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 static int write_from_line(MailStorage *storage, int fd, const char *mbox_path,
 			   time_t internal_date)
 {
@@ -131,7 +141,8 @@
 		    !write_from_line(box->storage, fd, mbox_path,
 				     internal_date) ||
 		    !index_storage_save_into_fd(box->storage, fd, mbox_path,
-						data, data_size)) {
+						data, data_size) ||
+		    !mbox_append_lf(box->storage, fd, mbox_path)) {
 			/* failed, truncate file back to original size */
 			(void)ftruncate(fd, pos);
 			failed = TRUE;