changeset 462:67d22b7b0918 HEAD

Added mail_cache_fields and mail_never_cache_fields settings, plus settings cleanup.
author Timo Sirainen <tss@iki.fi>
date Sun, 20 Oct 2002 05:35:51 +0300
parents 00d857873975
children 7434bac55c08
files dovecot-example.conf src/lib-index/mail-index-open.c src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-index/maildir/maildir-rebuild.c src/lib-index/mbox/mbox-rebuild.c src/lib-storage/index/index-storage.c src/master/imap-process.c src/master/settings.c src/master/settings.h
diffstat 10 files changed, 159 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Sun Oct 20 04:36:46 2002 +0300
+++ b/dovecot-example.conf	Sun Oct 20 05:35:51 2002 +0300
@@ -89,6 +89,38 @@
 # allow shell access for users.
 #valid_chroot_dirs = 
 
+# Space-separated list of fields to cache for all mails. Currently these
+# fields are allowed followed by a list of commands they speed up:
+#
+#  Envelope      - FETCH ENVELOPE and SEARCH FROM, TO, CC, BCC, SUBJECT,
+#                  SENTBEFORE, SENTON, SENTSINCE, HEADER MESSAGE-ID,
+#                  HEADER IN-REPLY-TO
+#  Body          - FETCH BODY
+#  Bodystructure - FETCH BODY, BODYSTRUCTURE
+#  MessagePart   - FETCH BODY[1.2.3] (ie. body parts), RFC822.SIZE,
+#                  SEARCH SMALLER, LARGER, also speeds up BODY/BODYSTRUCTURE
+#                  generation. This is always set with mbox mailboxes, and
+#                  also default with Maildir.
+#
+# Different IMAP clients work in different ways, that's why Dovecot by default
+# only caches MessagePart which speeds up most operations. Whenever client
+# does something where caching could be used, the field is automatically marked
+# to be cached later. For example after FETCH BODY the BODY will be cached
+# for all new messages. Normally you should leave this alone, unless you know
+# what most of your IMAP clients are. Caching more fields than needed makes
+# the index files larger and generate useless I/O.
+#
+# With maildir there's one extra optimization - if nothing is cached, indexing
+# the maildir becomes much faster since it's not opening any of the mail files.
+# This could be useful if your IMAP clients access only new mails.
+
+#mail_cache_fields = MessagePart
+
+# Space-separated list of fields that Dovecot should never set to be cached.
+# Useful if you want to save disk space at the cost of more I/O when the fields
+# needed.
+#mail_never_cache_fields = 
+
 # Copy mail to another folders using hard links. This is much faster than
 # actually copying the file. Only problem with it is that if either of the
 # mails are modified directly both will change. This isn't a problem with
--- a/src/lib-index/mail-index-open.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-index/mail-index-open.c	Sun Oct 20 05:35:51 2002 +0300
@@ -359,7 +359,7 @@
 	*dir_unlocked = FALSE;
 	index_path = NULL;
 
-	mail_index_init_header(&hdr);
+	mail_index_init_header(index, &hdr);
 
 	if (index->nodiskspace) {
 		/* don't even bother trying to create it */
@@ -455,7 +455,7 @@
 	return FALSE;
 }
 
-void mail_index_init_header(MailIndexHeader *hdr)
+void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr)
 {
 	memset(hdr, 0, sizeof(MailIndexHeader));
 	hdr->compat_data[0] = MAIL_INDEX_VERSION;
@@ -471,7 +471,7 @@
 	hdr->flags = MAIL_INDEX_FLAG_REBUILD;
 
 	/* set the fields we always want to cache */
-	hdr->cache_fields |= FIELD_TYPE_LOCATION | FIELD_TYPE_MESSAGEPART;
+	hdr->cache_fields |= index->default_cache_fields;
 
 	hdr->used_file_size = sizeof(MailIndexHeader);
 	hdr->uid_validity = ioloop_time;
--- a/src/lib-index/mail-index.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-index/mail-index.c	Sun Oct 20 05:35:51 2002 +0300
@@ -606,6 +606,8 @@
 {
 	i_assert(index->lock_type != MAIL_LOCK_UNLOCK);
 
+	field &= ~index->never_cache_fields;
+
 	/* first check if the field even could be in the file */
 	if ((index->set_cache_fields & field) != field) {
 		if ((index->header->cache_fields & field) == 0) {
--- a/src/lib-index/mail-index.h	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-index/mail-index.h	Sun Oct 20 05:35:51 2002 +0300
@@ -311,6 +311,7 @@
 
 	char *dir; /* directory where to place the index files */
 	char *filepath; /* index file path */
+	MailField default_cache_fields, never_cache_fields;
 	unsigned int indexid;
 	unsigned int sync_id;
 
@@ -351,7 +352,8 @@
 #define MAIL_INDEX_PRIVATE_FILL \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
-	0, 0, 0, 0, 0, 0, 0, 0, 0 \
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+	0
 
 /* defaults - same as above but prefixed with mail_index_. */
 int mail_index_open(MailIndex *index, int update_recent, int fast);
@@ -391,7 +393,7 @@
 
 /* INTERNAL: */
 int mail_index_mmap_update(MailIndex *index);
-void mail_index_init_header(MailIndexHeader *hdr);
+void mail_index_init_header(MailIndex *index, MailIndexHeader *hdr);
 void mail_index_close(MailIndex *index);
 int mail_index_fmsync(MailIndex *index, size_t size);
 int mail_index_verify_hole_range(MailIndex *index);
--- a/src/lib-index/maildir/maildir-rebuild.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-index/maildir/maildir-rebuild.c	Sun Oct 20 05:35:51 2002 +0300
@@ -20,9 +20,12 @@
 		return FALSE;
 
 	/* reset the header */
-	mail_index_init_header(index->header);
+	mail_index_init_header(index, index->header);
 	index->mmap_used_length = index->header->used_file_size;
 
+	/* require these fields */
+	index->header->cache_fields |= FIELD_TYPE_LOCATION;
+
 	/* update indexid, which also means that our state has completely
 	   changed */
 	index->indexid = index->header->indexid;
--- a/src/lib-index/mbox/mbox-rebuild.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-index/mbox/mbox-rebuild.c	Sun Oct 20 05:35:51 2002 +0300
@@ -24,11 +24,12 @@
 		return FALSE;
 
 	/* reset the header */
-	mail_index_init_header(index->header);
+	mail_index_init_header(index, index->header);
 	index->mmap_used_length = index->header->used_file_size;
 
-	/* we require MD5 to be cached */
-	index->header->cache_fields |= FIELD_TYPE_MD5;
+	/* require these fields */
+	index->header->cache_fields |= FIELD_TYPE_LOCATION |
+		FIELD_TYPE_MESSAGEPART | FIELD_TYPE_MD5;
 
 	/* update indexid, which also means that our state has completely
 	   changed */
--- a/src/lib-storage/index/index-storage.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/lib-storage/index/index-storage.c	Sun Oct 20 05:35:51 2002 +0300
@@ -6,6 +6,7 @@
 #include "mail-custom-flags.h"
 #include "index-storage.h"
 
+#include <stdlib.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
@@ -75,6 +76,71 @@
 	i_assert(0);
 }
 
+static MailField get_cache_fields(const char *fields)
+{
+	static const char *field_names[] = {
+		"Location",
+		"Envelope",
+		"Body",
+		"Bodystructure",
+		"MD5",
+		"MessagePart",
+		NULL
+	};
+
+	char *const *arr;
+	MailField ret;
+	int i;
+
+	if (fields == NULL || *fields == '\0')
+		return 0;
+
+	ret = 0;
+	for (arr = t_strsplit(fields, " ,"); *arr != NULL; arr++) {
+		if (*arr == '\0')
+			continue;
+
+		for (i = 0; field_names[i] != NULL; i++) {
+			if (strcasecmp(field_names[i], *arr) == 0) {
+				ret |= 1 << i;
+				break;
+			}
+		}
+		if (field_names[i] == NULL) {
+			i_error("Invalid cache field name '%s', ignoring ",
+				*arr);
+		}
+	}
+
+	return ret;
+}
+
+static MailField get_default_cache_fields(void)
+{
+	static MailField ret = 0;
+	static int ret_set = FALSE;
+
+	if (ret_set)
+		return ret;
+
+	ret = get_cache_fields(getenv("MAIL_CACHE_FIELDS"));
+	ret_set = TRUE;
+	return ret;
+}
+
+static MailField get_never_cache_fields(void)
+{
+	static MailField ret = 0;
+	static int ret_set = FALSE;
+
+	if (ret_set)
+		return ret;
+
+	ret = get_cache_fields(getenv("MAIL_NEVER_CACHE_FIELDS"));
+	ret_set = TRUE;
+	return ret;
+}
+
 IndexMailbox *index_storage_init(MailStorage *storage, Mailbox *box,
 				 MailIndex *index, const char *name,
 				 int readonly, int fast)
@@ -88,6 +154,10 @@
 	do {
 		if (!index->opened) {
 			/* open the index first */
+			index->default_cache_fields =
+				get_default_cache_fields();
+			index->never_cache_fields =
+				get_never_cache_fields();
 			if (!index->open_or_create(index, !readonly, fast))
 				break;
 		}
--- a/src/master/imap-process.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/master/imap-process.c	Sun Oct 20 05:35:51 2002 +0300
@@ -114,6 +114,10 @@
 	}
 
 	putenv((char *) t_strconcat("HOME=", home, NULL));
+	putenv((char *) t_strconcat("MAIL_CACHE_FIELDS=",
+				    set_mail_cache_fields, NULL));
+	putenv((char *) t_strconcat("MAIL_NEVER_CACHE_FIELDS=",
+				    set_mail_never_cache_fields, NULL));
 
 	if (set_maildir_copy_with_hardlinks)
 		putenv("COPY_WITH_HARDLINKS=1");
--- a/src/master/settings.c	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/master/settings.c	Sun Oct 20 05:35:51 2002 +0300
@@ -26,6 +26,15 @@
 	{ "log_path",		SET_STR, &set_log_path },
 	{ "log_timestamp",	SET_STR, &set_log_timestamp },
 
+	{ "imap_port",		SET_INT, &set_imap_port },
+	{ "imaps_port",		SET_INT, &set_imaps_port },
+	{ "imap_listen",	SET_STR, &set_imap_listen },
+	{ "imaps_listen",	SET_STR, &set_imaps_listen },
+	{ "ssl_cert_file",	SET_STR, &set_ssl_cert_file },
+	{ "ssl_key_file",	SET_STR, &set_ssl_key_file },
+	{ "disable_plaintext_auth",
+				SET_BOOL,&set_disable_plaintext_auth },
+
 	{ "login_executable",	SET_STR, &set_login_executable },
 	{ "login_user",		SET_STR, &set_login_user },
 	{ "login_dir",		SET_STR, &set_login_dir },
@@ -36,18 +45,13 @@
 	{ "imap_executable",	SET_STR, &set_imap_executable },
 	{ "valid_chroot_dirs",	SET_STR, &set_valid_chroot_dirs },
 	{ "max_imap_processes",	SET_INT, &set_max_imap_processes },
-	{ "imap_listen",	SET_STR, &set_imap_listen },
-	{ "imaps_listen",	SET_STR, &set_imaps_listen },
-	{ "imap_port",		SET_INT, &set_imap_port },
-	{ "imaps_port",		SET_INT, &set_imaps_port },
-	{ "ssl_cert_file",	SET_STR, &set_ssl_cert_file },
-	{ "ssl_key_file",	SET_STR, &set_ssl_key_file },
-	{ "disable_plaintext_auth",
-				SET_BOOL,&set_disable_plaintext_auth },
 	{ "first_valid_uid",	SET_INT, &set_first_valid_uid },
 	{ "last_valid_uid",	SET_INT, &set_last_valid_uid },
 	{ "first_valid_gid",	SET_INT, &set_first_valid_gid },
 	{ "last_valid_gid",	SET_INT, &set_last_valid_gid },
+	{ "mail_cache_fields",	SET_STR, &set_mail_cache_fields },
+	{ "mail_never_cache_fields",
+				SET_STR, &set_mail_never_cache_fields },
 	{ "maildir_copy_with_hardlinks",
 				SET_BOOL,&set_maildir_copy_with_hardlinks },
 	{ "maildir_check_content_changes",
@@ -63,6 +67,16 @@
 char *set_log_path = NULL;
 char *set_log_timestamp = DEFAULT_FAILURE_STAMP_FORMAT;
 
+/* general */
+unsigned int set_imap_port = 143;
+unsigned int set_imaps_port = 993;
+char *set_imap_listen = NULL;
+char *set_imaps_listen = NULL;
+
+char *set_ssl_cert_file = "/etc/ssl/certs/imapd.pem";
+char *set_ssl_key_file = "/etc/ssl/private/imapd.pem";
+int set_disable_plaintext_auth = FALSE;
+
 /* login */
 char *set_login_executable = PKG_LIBDIR "/imap-login";
 char *set_login_user = "imapd";
@@ -80,18 +94,11 @@
 char *set_valid_chroot_dirs = NULL;
 unsigned int set_max_imap_processes = 1024;
 
-char *set_imap_listen = NULL;
-char *set_imaps_listen = NULL;
-unsigned int set_imap_port = 143;
-unsigned int set_imaps_port = 993;
-
-char *set_ssl_cert_file = "/etc/ssl/certs/imapd.pem";
-char *set_ssl_key_file = "/etc/ssl/private/imapd.pem";
-int set_disable_plaintext_auth = FALSE;
-
 unsigned int set_first_valid_uid = 500, set_last_valid_uid = 0;
 unsigned int set_first_valid_gid = 1, set_last_valid_gid = 0;
 
+char *set_mail_cache_fields = "MessagePart";
+char *set_mail_never_cache_fields = NULL;
 int set_maildir_copy_with_hardlinks = FALSE;
 int set_maildir_check_content_changes = FALSE;
 int set_overwrite_incompatible_index = FALSE;
--- a/src/master/settings.h	Sun Oct 20 04:36:46 2002 +0300
+++ b/src/master/settings.h	Sun Oct 20 05:35:51 2002 +0300
@@ -5,6 +5,16 @@
 extern char *set_log_path;
 extern char *set_log_timestamp;
 
+/* general */
+extern unsigned int set_imap_port;
+extern unsigned int set_imaps_port;
+extern char *set_imap_listen;
+extern char *set_imaps_listen;
+
+extern char *set_ssl_cert_file;
+extern char *set_ssl_key_file;
+extern int set_disable_plaintext_auth;
+
 /* login */
 extern char *set_login_executable;
 extern char *set_login_user;
@@ -21,18 +31,11 @@
 extern char *set_valid_chroot_dirs;
 extern unsigned int set_max_imap_processes;
 
-extern char *set_imap_listen;
-extern char *set_imaps_listen;
-extern unsigned int set_imap_port;
-extern unsigned int set_imaps_port;
-
-extern char *set_ssl_cert_file;
-extern char *set_ssl_key_file;
-extern int set_disable_plaintext_auth;
-
 extern unsigned int set_first_valid_uid, set_last_valid_uid;
 extern unsigned int set_first_valid_gid, set_last_valid_gid;
 
+extern char *set_mail_cache_fields;
+extern char *set_mail_never_cache_fields;
 extern int set_maildir_copy_with_hardlinks;
 extern int set_maildir_check_content_changes;
 extern int set_overwrite_incompatible_index;