changeset 2197:6033af323a61 HEAD

Filter internal headers from user visible input stream. Make mailbox_save() use the same header list.
author Timo Sirainen <tss@iki.fi>
date Sun, 20 Jun 2004 09:21:48 +0300
parents 0417cdfa6d88
children f5baee0fc85f
files src/lib-storage/index/mbox/mbox-mail.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-storage.h
diffstat 4 files changed, 25 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-mail.c	Sun Jun 20 09:20:32 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Sun Jun 20 09:21:48 2004 +0300
@@ -7,6 +7,7 @@
 #include "mbox-file.h"
 #include "mbox-sync-private.h"
 #include "istream-raw-mbox.h"
+#include "istream-header-filter.h"
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -121,8 +122,14 @@
 		// FIXME: need to hide the headers
 		raw_stream = mail->ibox->mbox_stream;
 		offset = istream_raw_mbox_get_header_offset(raw_stream);
-		data->stream = i_stream_create_limit(default_pool, raw_stream,
-						     offset, (uoff_t)-1);
+		raw_stream = i_stream_create_limit(default_pool, raw_stream,
+						   offset, (uoff_t)-1);
+		data->stream =
+			i_stream_create_header_filter(default_pool,
+						      raw_stream,
+						      mbox_hide_headers,
+						      mbox_hide_headers_count);
+		i_stream_unref(raw_stream);
 	}
 
 	return index_mail_init_stream(mail, hdr_size, body_size);
--- a/src/lib-storage/index/mbox/mbox-save.c	Sun Jun 20 09:20:32 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Sun Jun 20 09:21:48 2004 +0300
@@ -170,33 +170,8 @@
 		return 1;
 	}
 
-	switch (*name) {
-	case 'C':
-	case 'c':
-		if (strcasecmp(name, "Content-Length") == 0)
-			return 0;
-		break;
-	case 'S':
-	case 's':
-		if (strcasecmp(name, "Status") == 0)
-			return 0;
-		break;
-	case 'X':
-	case 'x':
-		if (strcasecmp(name, "X-UID") == 0)
-			return 0;
-		if (strcasecmp(name, "X-Status") == 0)
-			return 0;
-		if (strcasecmp(name, "X-Keywords") == 0)
-			return 0;
-		if (strcasecmp(name, "X-IMAP") == 0)
-			return 0;
-		if (strcasecmp(name, "X-IMAPbase") == 0)
-			return 0;
-		break;
-	}
-
-	return 1;
+	return bsearch(name, mbox_hide_headers, mbox_hide_headers_count,
+		       sizeof(*mbox_hide_headers), bsearch_strcasecmp) == NULL;
 }
 
 static int mbox_save_init_sync(struct mbox_transaction_context *t)
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sun Jun 20 09:20:32 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sun Jun 20 09:21:48 2004 +0300
@@ -19,6 +19,18 @@
 
 #define CREATE_MODE 0770 /* umask() should limit it more */
 
+/* NOTE: must be sorted for istream-header-filter. */
+const char *mbox_hide_headers[] = {
+	"Content-Length",
+	"Status",
+	"X-IMAP",
+	"X-IMAPbase",
+	"X-Keywords",
+	"X-Status",
+	"X-UID",
+};
+size_t mbox_hide_headers_count = 7;
+
 extern struct mail_storage mbox_storage;
 extern struct mailbox mbox_mailbox;
 
--- a/src/lib-storage/index/mbox/mbox-storage.h	Sun Jun 20 09:20:32 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.h	Sun Jun 20 09:21:48 2004 +0300
@@ -18,6 +18,8 @@
 };
 
 extern struct mail mbox_mail;
+extern const char *mbox_hide_headers[];
+extern size_t mbox_hide_headers_count;
 
 int mbox_set_syscall_error(struct index_mailbox *ibox, const char *function);