changeset 314:d2a305fa0ec2 HEAD

mbox ignored message flags for APPEND.
author Timo Sirainen <tss@iki.fi>
date Tue, 24 Sep 2002 20:38:37 +0300
parents df941be7c6b0
children f07ad72a1c7e
files src/lib-storage/index/mbox/mbox-save.c
diffstat 1 files changed, 59 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-save.c	Tue Sep 24 19:52:22 2002 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Tue Sep 24 20:38:37 2002 +0300
@@ -15,7 +15,7 @@
 
 static char my_hostdomain[256] = "";
 
-static void set_error(MailStorage *storage, const char *mbox_path)
+static int set_error(MailStorage *storage, const char *mbox_path)
 {
 	if (errno == ENOSPC)
 		mail_storage_set_error(storage, "Not enough disk space");
@@ -23,6 +23,8 @@
 		mail_storage_set_critical(storage, "Error writing to "
 					  "mbox file %s: %m", mbox_path);
 	}
+
+	return FALSE;
 }
 
 static int mbox_check_ending_lf(MailStorage *storage, int fd, off_t pos,
@@ -48,16 +50,13 @@
 		return TRUE;
 	} while (0);
 
-	set_error(storage, mbox_path);
-	return FALSE;
+	return set_error(storage, mbox_path);
 }
 
 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;
-	}
+	if (write_full(fd, "\n", 1) < 0)
+		return set_error(storage, mbox_path);
 
 	return TRUE;
 }
@@ -89,9 +88,57 @@
 	line = mbox_from_create(sender, internal_date);
 	len = strlen(line);
 
-	if (write_full(fd, line, len) < 0) {
-		set_error(storage, mbox_path);
-		return FALSE;
+	if (write_full(fd, line, len) < 0)
+		return set_error(storage, mbox_path);
+
+	return TRUE;
+}
+
+static int write_flags(MailStorage *storage, int fd, const char *mbox_path,
+		       MailFlags flags, const char *custom_flags[])
+{
+	const char *str;
+	unsigned int field;
+	int i;
+
+	if (flags == 0)
+		return TRUE;
+
+	if (flags & MAIL_SEEN) {
+		if (write_full(fd, "Status: R\n", 10) < 0)
+			return set_error(storage, mbox_path);
+	}
+
+	if (flags & (MAIL_ANSWERED|MAIL_DRAFT|MAIL_FLAGGED|MAIL_DELETED)) {
+		str = t_strconcat("X-Status: ",
+				  (flags & MAIL_ANSWERED) ? "A" : "",
+				  (flags & MAIL_DRAFT) ? "D" : "",
+				  (flags & MAIL_FLAGGED) ? "F" : "",
+				  (flags & MAIL_DELETED) ? "T" : "",
+				  "\n", NULL);
+
+		if (write_full(fd, str, strlen(str)) < 0)
+			return set_error(storage, mbox_path);
+	}
+
+	if (flags & MAIL_CUSTOM_FLAGS_MASK) {
+		if (write_full(fd, "X-Keywords:", 11) < 0)
+			return set_error(storage, mbox_path);
+
+		field = 1 << MAIL_CUSTOM_FLAG_1_BIT;
+		for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++, field <<= 1) {
+			if ((flags & field) && custom_flags[i] != NULL) {
+				if (write_full(fd, " ", 1) < 0)
+					return set_error(storage, mbox_path);
+
+				if (write_full(fd, custom_flags[i],
+					       strlen(custom_flags[i])) < 0)
+					return set_error(storage, mbox_path);
+			}
+		}
+
+		if (write_full(fd, "\n", 1) < 0)
+			return set_error(storage, mbox_path);
 	}
 
 	return TRUE;
@@ -140,6 +187,8 @@
 		if (!mbox_check_ending_lf(box->storage, fd, pos, mbox_path) ||
 		    !write_from_line(box->storage, fd, mbox_path,
 				     internal_date) ||
+		    !write_flags(box->storage, fd, mbox_path, flags,
+				 custom_flags) ||
 		    !index_storage_save_into_fd(box->storage, fd, mbox_path,
 						data, data_size) ||
 		    !mbox_append_lf(box->storage, fd, mbox_path)) {