dovecot-2.0: pop3: Added pop3_fast_size_lookups setting.

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 1 18:39:15 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/c172f2a384f5
changeset: 12221:c172f2a384f5
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 01 16:39:11 2010 +0100
description:
pop3: Added pop3_fast_size_lookups setting.

diffstat:

 doc/example-config/conf.d/20-pop3.conf |   7 +++
 src/pop3/pop3-client.c                 |  41 ++++++++++++++++++++-
 src/pop3/pop3-settings.c               |   2 +
 src/pop3/pop3-settings.h               |   1 +
 4 files changed, 50 insertions(+), 1 deletions(-)

diffs (105 lines):

diff -r d48456c46a49 -r c172f2a384f5 doc/example-config/conf.d/20-pop3.conf
--- a/doc/example-config/conf.d/20-pop3.conf	Fri Oct 01 16:19:10 2010 +0100
+++ b/doc/example-config/conf.d/20-pop3.conf	Fri Oct 01 16:39:11 2010 +0100
@@ -19,6 +19,13 @@
   # Keep the mailbox locked for the entire POP3 session.
   #pop3_lock_session = no
 
+  # POP3 requires message sizes to be listed as if they had CR+LF linefeeds.
+  # Many POP3 servers violate this by returning the sizes with LF linefeeds,
+  # because it's faster to get. When this setting is enabled, Dovecot still
+  # tries to do the right thing first, but if that requires opening the
+  # message, it fallbacks to the easier (but incorrect) size.
+  #pop3_fast_size_lookups = no
+
   # POP3 UIDL (unique mail identifier) format to use. You can use following
   # variables, along with the variable modifiers described in
   # doc/wiki/Variables.txt (e.g. %Uf for the filename in uppercase)
diff -r d48456c46a49 -r c172f2a384f5 src/pop3/pop3-client.c
--- a/src/pop3/pop3-client.c	Fri Oct 01 16:19:10 2010 +0100
+++ b/src/pop3/pop3-client.c	Fri Oct 01 16:39:11 2010 +0100
@@ -64,6 +64,45 @@
 	}
 }
 
+static int
+pop3_mail_get_size(struct client *client, struct mail *mail, uoff_t *size_r)
+{
+	struct mail_storage *storage;
+	enum mail_error error;
+	int ret;
+
+	if (!client->set->pop3_fast_size_lookups)
+		return mail_get_virtual_size(mail, size_r);
+
+	/* first try to get the virtual size */
+	mail->lookup_abort = MAIL_LOOKUP_ABORT_READ_MAIL;
+	ret = mail_get_virtual_size(mail, size_r);
+	mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER;
+	if (ret == 0)
+		return 0;
+
+	storage = mailbox_get_storage(mail->box);
+	(void)mail_storage_get_last_error(storage, &error);
+	if (error != MAIL_ERROR_NOTPOSSIBLE)
+		return -1;
+
+	/* virtual size not available with a fast lookup.
+	   fallback to trying the physical size */
+	mail->lookup_abort = MAIL_LOOKUP_ABORT_READ_MAIL;
+	ret = mail_get_physical_size(mail, size_r);
+	mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER;
+	if (ret == 0)
+		return 0;
+
+	(void)mail_storage_get_last_error(storage, &error);
+	if (error != MAIL_ERROR_NOTPOSSIBLE)
+		return -1;
+
+	/* no way to quickly get the size. fallback to doing a slow virtual
+	   size lookup */
+	return mail_get_virtual_size(mail, size_r);
+}
+
 static int read_mailbox(struct client *client, uint32_t *failed_uid_r)
 {
         struct mailbox_status status;
@@ -94,7 +133,7 @@
 
 	mail = mail_alloc(t, MAIL_FETCH_VIRTUAL_SIZE, NULL);
 	while (mailbox_search_next(ctx, mail)) {
-		if (mail_get_virtual_size(mail, &size) < 0) {
+		if (pop3_mail_get_size(client, mail, &size) < 0) {
 			ret = mail->expunged ? 0 : -1;
 			*failed_uid_r = mail->uid;
 			break;
diff -r d48456c46a49 -r c172f2a384f5 src/pop3/pop3-settings.c
--- a/src/pop3/pop3-settings.c	Fri Oct 01 16:19:10 2010 +0100
+++ b/src/pop3/pop3-settings.c	Fri Oct 01 16:39:11 2010 +0100
@@ -68,6 +68,7 @@
 	DEF(SET_BOOL, pop3_reuse_xuidl),
 	DEF(SET_BOOL, pop3_save_uidl),
 	DEF(SET_BOOL, pop3_lock_session),
+	DEF(SET_BOOL, pop3_fast_size_lookups),
 	DEF(SET_STR, pop3_client_workarounds),
 	DEF(SET_STR, pop3_logout_format),
 
@@ -83,6 +84,7 @@
 	.pop3_reuse_xuidl = FALSE,
 	.pop3_save_uidl = FALSE,
 	.pop3_lock_session = FALSE,
+	.pop3_fast_size_lookups = FALSE,
 	.pop3_client_workarounds = "",
 	.pop3_logout_format = "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s"
 };
diff -r d48456c46a49 -r c172f2a384f5 src/pop3/pop3-settings.h
--- a/src/pop3/pop3-settings.h	Fri Oct 01 16:19:10 2010 +0100
+++ b/src/pop3/pop3-settings.h	Fri Oct 01 16:39:11 2010 +0100
@@ -20,6 +20,7 @@
 	bool pop3_reuse_xuidl;
 	bool pop3_save_uidl;
 	bool pop3_lock_session;
+	bool pop3_fast_size_lookups;
 	const char *pop3_client_workarounds;
 	const char *pop3_logout_format;
 


More information about the dovecot-cvs mailing list