[dovecot-cvs] dovecot/src/lib-storage/index index-mailbox-check.c,NONE,1.1 Makefile.am,1.4,1.5 index-storage.c,1.19,1.20 index-storage.h,1.20,1.21 index-sync.c,1.19,1.20

cras at procontrol.fi cras at procontrol.fi
Tue Nov 12 07:27:32 EET 2002


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

Modified Files:
	Makefile.am index-storage.c index-storage.h index-sync.c 
Added Files:
	index-mailbox-check.c 
Log Message:
mailbox_check_interval setting: Dovecot can notify client of new mail in
selected mailbox soon after it's received. This setting specifies the
minimum interval in seconds between new mail notifications to client -
internally they may be checked more or less often. Setting this to 0
disables the checking.



--- NEW FILE: index-mailbox-check.c ---
/* Copyright (C) 2002 Timo Sirainen */

#include "lib.h"
#include "ioloop.h"
#include "index-storage.h"

#include <stdlib.h>
#include <sys/stat.h>

static int check_interval = -1;

static void check_timeout(void *context, Timeout timeout __attr_unused__)
{
	IndexMailbox *ibox = context;
	struct stat st;

	if (ioloop_time - ibox->last_check < check_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);
	}
}

void index_mailbox_check_add(IndexMailbox *ibox, const char *path)
{
	const char *str;
	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;
	}

	if (check_interval == 0)
		return;

	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);
}

void index_mailbox_check_remove(IndexMailbox *ibox)
{
	if (ibox->check_to != NULL)
		timeout_remove(ibox->check_to);
	i_free(ibox->check_path);
}

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.am	21 Sep 2002 06:36:18 -0000	1.4
+++ Makefile.am	12 Nov 2002 05:27:30 -0000	1.5
@@ -14,6 +14,7 @@
 	index-expunge.c \
 	index-fetch.c \
 	index-fetch-section.c \
+	index-mailbox-check.c \
 	index-messageset.c \
 	index-msgcache.c \
 	index-save.c \

Index: index-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- index-storage.c	2 Nov 2002 20:10:21 -0000	1.19
+++ index-storage.c	12 Nov 2002 05:27:30 -0000	1.20
@@ -195,6 +195,7 @@
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
 
+	index_mailbox_check_remove(ibox);
 	imap_msgcache_free(ibox->cache);
 	index_storage_unref(ibox->index);
 	i_free(box->name);

Index: index-storage.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- index-storage.h	4 Nov 2002 04:47:40 -0000	1.20
+++ index-storage.h	12 Nov 2002 05:27:30 -0000	1.21
@@ -19,6 +19,12 @@
 
 	MailIndex *index;
 	ImapMessageCache *cache;
+
+	char *check_path;
+	Timeout check_to;
+	time_t check_file_stamp;
+	time_t last_check;
+
 	unsigned int synced_messages_count;
 
 	unsigned int sent_diskspace_warning:1;
@@ -56,6 +62,9 @@
 
 int index_msgcache_open(ImapMessageCache *cache, MailIndex *index,
 			MailIndexRecord *rec, ImapCacheField fields);
+
+void index_mailbox_check_add(IndexMailbox *ibox, const char *path);
+void index_mailbox_check_remove(IndexMailbox *ibox);
 
 /* Mailbox methods: */
 void index_storage_set_sync_callbacks(Mailbox *box,

Index: index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sync.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- index-sync.c	4 Nov 2002 04:47:40 -0000	1.19
+++ index-sync.c	12 Nov 2002 05:27:30 -0000	1.20
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
+#include "ioloop.h"
 #include "index-storage.h"
 #include "mail-index-util.h"
 #include "mail-modifylog.h"
@@ -204,22 +205,25 @@
 int index_storage_sync(Mailbox *box, int sync_expunges)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
-	int failed;
+	int ret;
+
+	ibox->last_check = ioloop_time;
 
 	if (!index_storage_sync_and_lock(ibox, FALSE, MAIL_LOCK_UNLOCK))
 		return FALSE;
 
-	if (!sync_expunges) {
-		/* FIXME: we could still send flag changes */
-		failed = FALSE;
-	} else {
-		failed = !index_storage_sync_modifylog(ibox, FALSE);
-	}
+	/* FIXME: we could sync flags always, but expunges in the middle
+	   could make it a bit more difficult and slower */
+	if (sync_expunges ||
+	    mail_modifylog_get_expunge_count(ibox->index->modifylog) == 0)
+		ret = index_storage_sync_modifylog(ibox, FALSE);
+	else
+		ret = TRUE;
 
 	index_storage_sync_size(ibox);
 
 	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_UNLOCK))
 		return mail_storage_set_index_error(ibox);
 
-	return !failed;
+	return ret;
 }




More information about the dovecot-cvs mailing list