Mercurial > dovecot > core-2.2
changeset 600:3b44bc64afd4 HEAD
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 12 Nov 2002 07:27:30 +0200 |
parents | a7691dc0a869 |
children | bfa9ab91eba7 |
files | dovecot-example.conf src/lib-storage/index/Makefile.am src/lib-storage/index/index-mailbox-check.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/index-sync.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-storage.c src/master/imap-process.c src/master/settings.c src/master/settings.h |
diffstat | 11 files changed, 96 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Tue Nov 12 05:58:02 2002 +0200 +++ b/dovecot-example.conf Tue Nov 12 07:27:30 2002 +0200 @@ -123,6 +123,12 @@ #mail_cache_fields = MessagePart +# 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. +#mailbox_check_interval = 30 + # Space-separated list of fields that Dovecot should never set to be cached. # Useful if you want to save disk space at the cost of more I/O when the fields # needed.
--- a/src/lib-storage/index/Makefile.am Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/Makefile.am Tue Nov 12 07:27:30 2002 +0200 @@ -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 \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-storage/index/index-mailbox-check.c Tue Nov 12 07:27:30 2002 +0200 @@ -0,0 +1,53 @@ +/* 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); +}
--- a/src/lib-storage/index/index-storage.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/index-storage.c Tue Nov 12 07:27:30 2002 +0200 @@ -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);
--- a/src/lib-storage/index/index-storage.h Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/index-storage.h Tue Nov 12 07:27:30 2002 +0200 @@ -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; @@ -57,6 +63,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, MailboxSyncCallbacks *callbacks,
--- a/src/lib-storage/index/index-sync.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/index-sync.c Tue Nov 12 07:27:30 2002 +0200 @@ -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; }
--- a/src/lib-storage/index/maildir/maildir-storage.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Tue Nov 12 07:27:30 2002 +0200 @@ -139,8 +139,10 @@ ibox = index_storage_init(storage, &maildir_mailbox, index, name, readonly, fast); - if (ibox != NULL) + if (ibox != NULL) { ibox->expunge_locked = maildir_expunge_locked; + index_mailbox_check_add(ibox, t_strconcat(path, "/new", NULL)); + } return (Mailbox *) ibox; }
--- a/src/lib-storage/index/mbox/mbox-storage.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/lib-storage/index/mbox/mbox-storage.c Tue Nov 12 07:27:30 2002 +0200 @@ -171,8 +171,10 @@ ibox = index_storage_init(storage, &mbox_mailbox, index, name, readonly, fast); - if (ibox != NULL) + if (ibox != NULL) { ibox->expunge_locked = mbox_expunge_locked; + index_mailbox_check_add(ibox, index->mbox_path); + } return (Mailbox *) ibox; }
--- a/src/master/imap-process.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/master/imap-process.c Tue Nov 12 07:27:30 2002 +0200 @@ -119,6 +119,8 @@ set_mail_cache_fields, NULL)); putenv((char *) t_strconcat("MAIL_NEVER_CACHE_FIELDS=", set_mail_never_cache_fields, NULL)); + putenv((char *) t_strdup_printf("MAILBOX_CHECK_INTERVAL=%u", + set_mailbox_check_interval)); if (set_mail_save_crlf) putenv("MAIL_SAVE_CRLF=1");
--- a/src/master/settings.c Tue Nov 12 05:58:02 2002 +0200 +++ b/src/master/settings.c Tue Nov 12 07:27:30 2002 +0200 @@ -39,7 +39,8 @@ { "login_user", SET_STR, &set_login_user }, { "login_dir", SET_STR, &set_login_dir }, { "login_chroot", SET_BOOL,&set_login_chroot }, - { "login_processes_count", SET_INT, &set_login_processes_count }, + { "login_processes_count", + SET_INT, &set_login_processes_count }, { "max_logging_users", SET_INT, &set_max_logging_users }, { "imap_executable", SET_STR, &set_imap_executable }, @@ -53,6 +54,8 @@ { "mail_cache_fields", SET_STR, &set_mail_cache_fields }, { "mail_never_cache_fields", SET_STR, &set_mail_never_cache_fields }, + { "mailbox_check_interval", + SET_INT, &set_mailbox_check_interval }, { "mail_save_crlf", SET_BOOL,&set_mail_save_crlf }, { "maildir_copy_with_hardlinks", SET_BOOL,&set_maildir_copy_with_hardlinks }, @@ -102,6 +105,7 @@ char *set_mail_cache_fields = "MessagePart"; char *set_mail_never_cache_fields = NULL; +unsigned int set_mailbox_check_interval = 30; int set_mail_save_crlf = FALSE; int set_maildir_copy_with_hardlinks = FALSE; int set_maildir_check_content_changes = FALSE;
--- a/src/master/settings.h Tue Nov 12 05:58:02 2002 +0200 +++ b/src/master/settings.h Tue Nov 12 07:27:30 2002 +0200 @@ -37,6 +37,7 @@ extern char *set_mail_cache_fields; extern char *set_mail_never_cache_fields; +extern unsigned int set_mailbox_check_interval; extern int set_mail_save_crlf; extern int set_maildir_copy_with_hardlinks; extern int set_maildir_check_content_changes;