[dovecot-cvs] dovecot/src/lib-storage/index index-mailbox-check.c,1.3,1.4 index-storage.c,1.27,1.28 index-storage.h,1.31,1.32 index-sync.c,1.23,1.24

cras at procontrol.fi cras at procontrol.fi
Fri Feb 14 12:46:46 EET 2003


Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv6296/src/lib-storage/index

Modified Files:
	index-mailbox-check.c index-storage.c index-storage.h 
	index-sync.c 
Log Message:
Support for IDLE extension.



Index: index-mailbox-check.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-mailbox-check.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- index-mailbox-check.c	27 Jan 2003 01:44:34 -0000	1.3
+++ index-mailbox-check.c	14 Feb 2003 10:46:44 -0000	1.4
@@ -7,47 +7,65 @@
 #include <stdlib.h>
 #include <sys/stat.h>
 
-static int check_interval = -1;
-
 static void check_timeout(void *context)
 {
 	struct index_mailbox *ibox = context;
+	struct index_autosync_file *file;
 	struct stat st;
+	int synced, sync_expunges;
 
-	if (ioloop_time - ibox->last_check < check_interval)
+	/* check changes only when we can also notify of new mail */
+	if ((unsigned int) (ioloop_time - ibox->sync_last_check) <
+	    ibox->min_newmail_notify_interval)
 		return;
 
-	ibox->last_check = ioloop_time;
-	if (stat(ibox->check_path, &st) == 0 &&
-	    ibox->check_file_stamp != st.st_mtime) {
-		ibox->check_file_stamp = st.st_mtime;
-		ibox->box.sync(&ibox->box, FALSE);
+	ibox->sync_last_check = ioloop_time;
+
+	synced = FALSE;
+	sync_expunges = ibox->autosync_type != MAILBOX_SYNC_NO_EXPUNGES;
+
+	for (file = ibox->autosync_files; file != NULL; file = file->next) {
+		if (stat(file->path, &st) == 0 &&
+		    file->last_stamp != st.st_mtime) {
+			file->last_stamp = st.st_mtime;
+			if (!synced) {
+				ibox->box.sync(&ibox->box, sync_expunges);
+				synced = TRUE;
+			}
+		}
 	}
 }
 
 void index_mailbox_check_add(struct index_mailbox *ibox, const char *path)
 {
-	const char *str;
+	struct index_autosync_file *file;
 	struct stat st;
 
-	if (check_interval < 0) {
-		str = getenv("MAILBOX_CHECK_INTERVAL");
-		check_interval = str == NULL ? 0 : atoi(str);
-		if (check_interval < 0)
-			check_interval = 0;
-	}
+	file = i_new(struct index_autosync_file, 1);
+	file->path = i_strdup(path);
+	file->last_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime;
 
-	if (check_interval == 0)
-		return;
+	file->next = ibox->autosync_files;
+        ibox->autosync_files = file;
 
-	ibox->check_path = i_strdup(path);
-	ibox->check_file_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime;
-	ibox->check_to = timeout_add(1000, check_timeout, ibox);
+	if (ibox->autosync_to == NULL)
+		ibox->autosync_to = timeout_add(1000, check_timeout, ibox);
 }
 
-void index_mailbox_check_remove(struct index_mailbox *ibox)
+void index_mailbox_check_remove_all(struct index_mailbox *ibox)
 {
-	if (ibox->check_to != NULL)
-		timeout_remove(ibox->check_to);
-	i_free(ibox->check_path);
+	struct index_autosync_file *file;
+
+	while (ibox->autosync_files != NULL) {
+		file = ibox->autosync_files;
+		ibox->autosync_files = file->next;
+
+                i_free(file->path);
+		i_free(file);
+	}
+
+	if (ibox->autosync_to != NULL) {
+		timeout_remove(ibox->autosync_to);
+		ibox->autosync_to = NULL;
+	}
 }

Index: index-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- index-storage.c	12 Feb 2003 12:07:52 -0000	1.27
+++ index-storage.c	14 Feb 2003 10:46:44 -0000	1.28
@@ -276,7 +276,7 @@
 {
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
 
-	index_mailbox_check_remove(ibox);
+	index_mailbox_check_remove_all(ibox);
 	if (ibox->index != NULL)
 		index_storage_unref(ibox->index);
 

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- index-storage.h	12 Feb 2003 12:07:52 -0000	1.31
+++ index-storage.h	14 Feb 2003 10:46:44 -0000	1.32
@@ -5,6 +5,13 @@
 #include "mail-index.h"
 #include "index-mail.h"
 
+struct index_autosync_file {
+	struct index_autosync_file *next;
+
+	char *path;
+	time_t last_stamp;
+};
+
 struct index_mailbox {
 	struct mailbox box;
 
@@ -14,10 +21,11 @@
 
 	struct mail_index *index;
 
-	char *check_path;
-	struct timeout *check_to;
-	time_t check_file_stamp;
-	time_t last_check;
+	struct timeout *autosync_to;
+        struct index_autosync_file *autosync_files;
+	enum mailbox_sync_type autosync_type;
+	time_t sync_last_check;
+	unsigned int min_newmail_notify_interval;
 
 	struct index_mail fetch_mail; /* fetch_uid() or fetch_seq() */
 	unsigned int synced_messages_count;
@@ -64,7 +72,7 @@
 		       struct istream *input, struct ostream *output);
 
 void index_mailbox_check_add(struct index_mailbox *ibox, const char *path);
-void index_mailbox_check_remove(struct index_mailbox *ibox);
+void index_mailbox_check_remove_all(struct index_mailbox *ibox);
 
 /* mailbox methods: */
 void index_storage_set_callbacks(struct mail_storage *storage,

Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- index-sync.c	10 Jan 2003 11:29:24 -0000	1.23
+++ index-sync.c	14 Feb 2003 10:46:44 -0000	1.24
@@ -214,7 +214,7 @@
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
 	int ret;
 
-	ibox->last_check = ioloop_time;
+	ibox->sync_last_check = ioloop_time;
 
 	if (!index_storage_sync_and_lock(ibox, FALSE, MAIL_LOCK_UNLOCK))
 		return FALSE;




More information about the dovecot-cvs mailing list