[dovecot-cvs] dovecot/src/imap cmd-copy.c,1.35,1.35.2.1

tss at dovecot.org tss at dovecot.org
Wed Mar 21 21:19:51 EET 2007


Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv16973/imap

Modified Files:
      Tag: branch_1_0
	cmd-copy.c 
Log Message:
When copying/syncing a lot of mails, send "* OK Hang in there" replies to
client every 15 seconds so it doesn't just timeout the connection.



Index: cmd-copy.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/cmd-copy.c,v
retrieving revision 1.35
retrieving revision 1.35.2.1
diff -u -d -r1.35 -r1.35.2.1
--- cmd-copy.c	6 Mar 2006 18:13:54 -0000	1.35
+++ cmd-copy.c	21 Mar 2007 19:19:48 -0000	1.35.2.1
@@ -1,12 +1,32 @@
-/* Copyright (C) 2002 Timo Sirainen */
+/* Copyright (C) 2002-2007 Timo Sirainen */
 
 #include "common.h"
 #include "str.h"
+#include "ostream.h"
 #include "commands.h"
 #include "imap-search.h"
 
-static int fetch_and_copy(struct mailbox_transaction_context *t,
-			  struct mailbox *srcbox,
+#include <time.h>
+
+#define COPY_CHECK_INTERVAL 100
+
+static void client_send_sendalive_if_needed(struct client *client)
+{
+	time_t now;
+
+	if (o_stream_get_buffer_used_size(client->output) != 0)
+		return;
+
+	now = time(NULL);
+	if (now - client->last_output > MAIL_STORAGE_STAYALIVE_SECS) {
+		o_stream_send_str(client->output, "* OK Hang in there..\r\n");
+		o_stream_flush(client->output);
+		client->last_output = now;
+	}
+}
+
+static int fetch_and_copy(struct client *client,
+			  struct mailbox_transaction_context *t,
 			  struct mail_search_arg *search_args)
 {
 	struct mail_search_context *search_ctx;
@@ -14,9 +34,10 @@
 	struct mail_keywords *keywords;
 	const char *const *keywords_list;
 	struct mail *mail;
+	unsigned int copy_count = 0;
 	int ret;
 
-	src_trans = mailbox_transaction_begin(srcbox, 0);
+	src_trans = mailbox_transaction_begin(client->mailbox, 0);
 	search_ctx = mailbox_search_init(src_trans, NULL, search_args, NULL);
 
 	mail = mail_alloc(src_trans, MAIL_FETCH_STREAM_HEADER |
@@ -28,6 +49,9 @@
 			break;
 		}
 
+		if ((++copy_count % COPY_CHECK_INTERVAL) != 0)
+			client_send_sendalive_if_needed(client);
+
 		keywords_list = mail_get_keywords(mail);
 		keywords = strarray_length(keywords_list) == 0 ? NULL :
 			mailbox_keywords_create(t, keywords_list);
@@ -92,7 +116,7 @@
 
 	t = mailbox_transaction_begin(destbox,
 				      MAILBOX_TRANSACTION_FLAG_EXTERNAL);
-	ret = fetch_and_copy(t, client->mailbox, search_arg);
+	ret = fetch_and_copy(client, t, search_arg);
 
 	if (ret <= 0)
 		mailbox_transaction_rollback(&t);



More information about the dovecot-cvs mailing list