[dovecot-cvs] dovecot/src/pop3 client.c, 1.44, 1.45 client.h, 1.9, 1.10 commands.c, 1.35, 1.36 common.h, 1.6, 1.7 main.c, 1.18, 1.19

cras at dovecot.org cras at dovecot.org
Wed Dec 15 22:05:21 EET 2004


Update of /var/lib/cvs/dovecot/src/pop3
In directory talvi:/tmp/cvs-serv24921/src/pop3

Modified Files:
	client.c client.h commands.c common.h main.c 
Log Message:
Added pop3_uidl_format setting.



Index: client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/client.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- client.c	4 Dec 2004 18:51:26 -0000	1.44
+++ client.c	15 Dec 2004 20:05:19 -0000	1.45
@@ -37,16 +37,15 @@
 static void client_input(void *context);
 static int client_output(void *context);
 
-static int sync_mailbox(struct mailbox *box)
+static int sync_mailbox(struct mailbox *box, struct mailbox_status *status)
 {
 	struct mailbox_sync_context *ctx;
         struct mailbox_sync_rec sync_rec;
-	struct mailbox_status status;
 
 	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
 	while (mailbox_sync_next(ctx, &sync_rec) > 0)
 		;
-	return mailbox_sync_deinit(ctx, &status);
+	return mailbox_sync_deinit(ctx, status);
 }
 
 static int init_mailbox(struct client *client)
@@ -54,6 +53,7 @@
 	struct mail_search_arg search_arg;
         struct mailbox_transaction_context *t;
 	struct mail_search_context *ctx;
+        struct mailbox_status status;
 	struct mail *mail;
 	buffer_t *message_sizes_buf;
 	int i, failed;
@@ -64,10 +64,11 @@
 	search_arg.type = SEARCH_ALL;
 
 	for (i = 0; i < 2; i++) {
-		if (sync_mailbox(client->mailbox) < 0) {
+		if (sync_mailbox(client->mailbox, &status) < 0) {
 			client_send_storage_error(client);
 			break;
 		}
+		client->uid_validity = status.uidvalidity;
 
 		t = mailbox_transaction_begin(client->mailbox, FALSE);
 		ctx = mailbox_search_init(t, NULL, &search_arg, NULL,
@@ -152,6 +153,8 @@
 	flags = 0;
 	if (no_flag_updates)
 		flags |= MAILBOX_OPEN_KEEP_RECENT;
+	if ((uidl_keymask & UIDL_MD5) != 0)
+		flags |= MAILBOX_OPEN_KEEP_HEADER_MD5;
 	client->mailbox = mailbox_open(storage, "INBOX", flags);
 	if (client->mailbox == NULL) {
 		i_error("Couldn't open INBOX: %s",

Index: client.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/client.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- client.h	10 Oct 2004 16:25:06 -0000	1.9
+++ client.h	15 Dec 2004 20:05:19 -0000	1.10
@@ -22,6 +22,7 @@
 	time_t last_input, last_output;
 	unsigned int bad_counter;
 
+	unsigned int uid_validity;
 	unsigned int messages_count;
 	unsigned int deleted_count;
 	uoff_t *message_sizes;

Index: commands.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/commands.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- commands.c	7 Dec 2004 01:19:10 -0000	1.35
+++ commands.c	15 Dec 2004 20:05:19 -0000	1.36
@@ -4,6 +4,7 @@
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
+#include "var-expand.h"
 #include "message-size.h"
 #include "mail-storage.h"
 #include "mail-search.h"
@@ -478,10 +479,23 @@
 
 static int list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
 {
+	static struct var_expand_table static_tab[] = {
+		{ 'v', NULL },
+		{ 'u', NULL },
+		{ 'm', NULL },
+		{ '\0', NULL }
+	};
+	struct var_expand_table *tab;
 	struct mail *mail;
-	const char *uid_str;
+	string_t *str;
 	int ret, found = FALSE;
 
+	tab = t_malloc(sizeof(static_tab));
+	memcpy(tab, static_tab, sizeof(static_tab));
+	tab[0].value = t_strdup_printf("%u", client->uid_validity);
+
+	str = str_new(default_pool, 128);
+
 	while ((mail = mailbox_search_next(ctx->search_ctx)) != NULL) {
 		if (client->deleted) {
 			uint32_t idx = mail->seq - 1;
@@ -489,21 +503,34 @@
 			    (1 << (idx % CHAR_BIT)))
 				continue;
 		}
-
-		uid_str = mail->get_special(mail, MAIL_FETCH_UID_STRING);
 		found = TRUE;
 
-		ret = client_send_line(client, ctx->message == 0 ?
-				       "%u %s" : "+OK %u %s",
-				       mail->seq, uid_str);
+		t_push();
+		if ((uidl_keymask & UIDL_UID) != 0)
+			tab[1].value = dec2str(mail->uid);
+		if ((uidl_keymask & UIDL_MD5) != 0) {
+			tab[2].value =
+				mail->get_special(mail, MAIL_FETCH_HEADER_MD5);
+		}
+
+		str_truncate(str, 0);
+		str_printfa(str, ctx->message == 0 ? "%u " : "+OK %u ",
+			    mail->seq);
+		var_expand(str, uidl_format, tab);
+
+		ret = client_send_line(client, "%s", str_c(str));
+		t_pop();
+
 		if (ret < 0)
 			break;
 		if (ret == 0 && ctx->message == 0) {
 			/* output is being buffered, continue when there's
 			   more space */
+			str_free(str);
 			return 0;
 		}
 	}
+	str_free(str);
 
 	/* finished */
 	(void)mailbox_search_deinit(ctx->search_ctx);
@@ -527,6 +554,7 @@
 cmd_uidl_init(struct client *client, unsigned int message)
 {
         struct cmd_uidl_context *ctx;
+	enum mail_fetch_field wanted_fields;
 
 	ctx = i_new(struct cmd_uidl_context, 1);
 
@@ -539,8 +567,13 @@
 		ctx->search_arg.value.seqset = &ctx->seqset;
 	}
 
+	wanted_fields = 0;
+	if ((uidl_keymask & UIDL_MD5) != 0)
+		wanted_fields |= MAIL_FETCH_HEADER_MD5;
+
 	ctx->search_ctx = mailbox_search_init(client->trans, NULL,
-					      &ctx->search_arg, NULL, 0, NULL);
+					      &ctx->search_arg, NULL,
+					      wanted_fields, NULL);
 	if (message == 0) {
 		client->cmd = cmd_uidl_callback;
 		client->cmd_context = ctx;

Index: common.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/common.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- common.h	7 Dec 2004 01:19:10 -0000	1.6
+++ common.h	15 Dec 2004 20:05:19 -0000	1.7
@@ -9,9 +9,17 @@
 	WORKAROUND_OE_NS_EOH			= 0x02
 };
 
+enum uidl_keys {
+	UIDL_UIDVALIDITY	= 0x01,
+	UIDL_UID		= 0x02,
+	UIDL_MD5		= 0x04
+};
+
 extern struct ioloop *ioloop;
 extern enum client_workarounds client_workarounds;
 extern int enable_last_command, no_flag_updates;
+extern const char *uidl_format;
+extern enum uidl_keys uidl_keymask;
 
 extern void (*hook_mail_storage_created)(struct mail_storage **storage);
 extern void (*hook_client_created)(struct client **client);

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/pop3/main.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- main.c	7 Dec 2004 01:19:10 -0000	1.18
+++ main.c	15 Dec 2004 20:05:19 -0000	1.19
@@ -9,6 +9,7 @@
 #include "process-title.h"
 #include "randgen.h"
 #include "module-dir.h"
+#include "var-expand.h"
 #include "mail-storage.h"
 
 #include <stdio.h>
@@ -40,6 +41,8 @@
 enum client_workarounds client_workarounds = 0;
 int enable_last_command = FALSE;
 int no_flag_updates = FALSE;
+const char *uidl_format;
+enum uidl_keys uidl_keymask;
 
 static void sig_quit(int signo __attr_unused__)
 {
@@ -68,6 +71,28 @@
 	}
 }
 
+static enum uidl_keys parse_uidl_keymask(const char *format)
+{
+	enum uidl_keys mask = 0;
+
+	for (; *format != '\0'; format++) {
+		if (format[0] == '%' && format[1] != '\0') {
+			switch (var_get_key(++format)) {
+			case 'v':
+				mask |= UIDL_UIDVALIDITY;
+				break;
+			case 'u':
+				mask |= UIDL_UID;
+				break;
+			case 'm':
+				mask |= UIDL_MD5;
+				break;
+			}
+		}
+	}
+	return mask;
+}
+
 static void open_logfile(void)
 {
 	const char *user;
@@ -139,6 +164,11 @@
 	enable_last_command = getenv("POP3_ENABLE_LAST") != NULL;
 	no_flag_updates = getenv("POP3_NO_FLAG_UPDATES") != NULL;
 
+	uidl_format = getenv("POP3_UIDL_FORMAT");
+	if (uidl_format == NULL)
+		uidl_format = "%v.%u";
+	uidl_keymask = parse_uidl_keymask(uidl_format);
+
 	storage = mail_storage_create_with_data(mail, getenv("USER"));
 	if (storage == NULL) {
 		/* failed */



More information about the dovecot-cvs mailing list