Mercurial > dovecot > core-2.2
changeset 325:ba058497efa9 HEAD
Send RECENT after all EXISTS replies. Check for new mail in mailbox after
each FETCH, STORE and SEARCH commands and notify about it with EXISTS.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 28 Sep 2002 12:51:13 +0300 |
parents | b7f6772b91ff |
children | b79b6da2f84a |
files | src/imap/cmd-fetch.c src/imap/cmd-search.c src/imap/cmd-store.c src/imap/commands-util.c src/imap/commands-util.h src/lib-storage/index/index-status.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/mail-storage.h |
diffstat | 10 files changed, 72 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/cmd-fetch.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/imap/cmd-fetch.c Sat Sep 28 12:51:13 2002 +0300 @@ -269,6 +269,7 @@ if (client->mailbox->fetch(client->mailbox, &data, client->outbuf, &all_found)) { /* NOTE: syncing isn't allowed here */ + client_check_new_mail(client); client_send_tagline(client, all_found ? "OK Fetch completed." : "NO Some of the requested messages " "no longer exist.");
--- a/src/imap/cmd-search.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/imap/cmd-search.c Sat Sep 28 12:51:13 2002 +0300 @@ -35,6 +35,7 @@ if (client->mailbox->search(client->mailbox, sargs, client->outbuf, client->cmd_uid)) { /* NOTE: syncing isn't allowed here */ + client_check_new_mail(client); client_send_tagline(client, "OK Search completed."); } else { client_send_storage_error(client);
--- a/src/imap/cmd-store.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/imap/cmd-store.c Sat Sep 28 12:51:13 2002 +0300 @@ -109,6 +109,7 @@ modify_type, func, client, &all_found)) { /* NOTE: syncing isn't allowed here */ + client_check_new_mail(client); client_send_tagline(client, all_found ? "OK Store completed." : "NO Some of the messages no longer exist."); } else
--- a/src/imap/commands-util.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/imap/commands-util.c Sat Sep 28 12:51:13 2002 +0300 @@ -97,34 +97,43 @@ t_pop(); } -static int client_sync_full(Client *client, int expunge) +static int client_sync_full(Client *client, int sync_log, int expunge) { - unsigned int messages; + unsigned int messages, recent; char str[MAX_LARGEST_T_STRLEN+20]; if (client->mailbox == NULL) return TRUE; - if (!client->mailbox->sync(client->mailbox, &messages, expunge, - sync_expunge_func, sync_flags_func, client)) + if (!client->mailbox->sync(client->mailbox, expunge, &messages, &recent, + sync_log ? sync_expunge_func : NULL, + sync_log ? sync_flags_func : NULL, client)) return FALSE; if (messages != 0) { i_snprintf(str, sizeof(str), "* %u EXISTS", messages); client_send_line(client, str); + + i_snprintf(str, sizeof(str), "* %u RECENT", recent); + client_send_line(client, str); } return TRUE; } +void client_check_new_mail(Client *client) +{ + (void)client_sync_full(client, FALSE, FALSE); +} + void client_sync_mailbox(Client *client) { - (void)client_sync_full(client, FALSE); + (void)client_sync_full(client, TRUE, FALSE); } int client_sync_and_expunge_mailbox(Client *client) { - return client_sync_full(client, TRUE); + return client_sync_full(client, TRUE, TRUE); } void client_send_storage_error(Client *client)
--- a/src/imap/commands-util.h Fri Sep 27 17:16:52 2002 +0300 +++ b/src/imap/commands-util.h Sat Sep 28 12:51:13 2002 +0300 @@ -14,8 +14,12 @@ error message to client. */ int client_verify_open_mailbox(Client *client); +/* Check if there's new mail in mailbox. If yes, notify client by sending + EXISTS and RECENT. */ +void client_check_new_mail(Client *client); + /* Synchronize selected mailbox with client by sending EXPUNGE and - FETCH FLAGS responses. */ + FETCH FLAGS responses. Also does new mail checking. */ void client_sync_mailbox(Client *client); /* Synchronize selected mailbox and expunge messages with \Deleted flag. */
--- a/src/lib-storage/index/index-status.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/lib-storage/index/index-status.c Sat Sep 28 12:51:13 2002 +0300 @@ -4,42 +4,6 @@ #include "mail-custom-flags.h" #include "index-storage.h" -static unsigned int get_recent_count(MailIndex *index) -{ - MailIndexHeader *hdr; - MailIndexRecord *rec; - unsigned int seq; - - hdr = mail_index_get_header(index); - if (index->first_recent_uid <= 1) { - /* all are recent */ - return hdr->messages_count; - } - - /* get the first recent message */ - if (index->first_recent_uid >= hdr->next_uid) - return 0; - - rec = index->lookup_uid_range(index, index->first_recent_uid, - hdr->next_uid - 1); - if (rec == NULL) - return 0; - - /* now we know the record, but we'd still need to know how many - messages there's after this. there's two way to do this - - get the sequence number thus far (fast, unless there's deleted - messages) or just start reading messages forward until we're at - the end (fast assuming there's only a few recent messages). - it's a bit easier to use the first method and often it should be - faster too.. */ - seq = index->get_sequence(index, rec); - if (seq == 0) { - i_error("Couldn't get sequence for UID %u", rec->uid); - return 0; - } - return hdr->messages_count+1 - seq; -} - static unsigned int get_first_unseen_seq(MailIndex *index) { MailIndexHeader *hdr; @@ -127,7 +91,7 @@ } if (items & STATUS_RECENT) - status->recent = get_recent_count(ibox->index); + status->recent = index_storage_get_recent_count(ibox->index); if (items & STATUS_CUSTOM_FLAGS) { get_custom_flags(ibox->index->custom_flags,
--- a/src/lib-storage/index/index-storage.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/lib-storage/index/index-storage.c Sat Sep 28 12:51:13 2002 +0300 @@ -76,3 +76,39 @@ return mail_storage_set_index_error(ibox); } } + +unsigned int index_storage_get_recent_count(MailIndex *index) +{ + MailIndexHeader *hdr; + MailIndexRecord *rec; + unsigned int seq; + + hdr = mail_index_get_header(index); + if (index->first_recent_uid <= 1) { + /* all are recent */ + return hdr->messages_count; + } + + /* get the first recent message */ + if (index->first_recent_uid >= hdr->next_uid) + return 0; + + rec = index->lookup_uid_range(index, index->first_recent_uid, + hdr->next_uid - 1); + if (rec == NULL) + return 0; + + /* now we know the record, but we'd still need to know how many + messages there's after this. there's two way to do this - + get the sequence number thus far (fast, unless there's deleted + messages) or just start reading messages forward until we're at + the end (fast assuming there's only a few recent messages). + it's a bit easier to use the first method and often it should be + faster too.. */ + seq = index->get_sequence(index, rec); + if (seq == 0) { + i_error("Couldn't get sequence for UID %u", rec->uid); + return 0; + } + return hdr->messages_count+1 - seq; +}
--- a/src/lib-storage/index/index-storage.h Fri Sep 27 17:16:52 2002 +0300 +++ b/src/lib-storage/index/index-storage.h Sat Sep 28 12:51:13 2002 +0300 @@ -34,6 +34,8 @@ int index_mailbox_fix_custom_flags(IndexMailbox *ibox, MailFlags *flags, const char *custom_flags[]); +unsigned int index_storage_get_recent_count(MailIndex *index); + int index_expunge_seek_first(IndexMailbox *ibox, unsigned int *seq, MailIndexRecord **rec); @@ -48,7 +50,8 @@ int index_storage_expunge(Mailbox *box); int index_storage_get_status(Mailbox *box, MailboxStatusItems items, MailboxStatus *status); -int index_storage_sync(Mailbox *box, unsigned int *messages, int expunge, +int index_storage_sync(Mailbox *box, int expunge, + unsigned int *messages, unsigned int *recent, MailExpungeFunc expunge_func, MailFlagUpdateFunc flag_func, void *context);
--- a/src/lib-storage/index/index-sync.c Fri Sep 27 17:16:52 2002 +0300 +++ b/src/lib-storage/index/index-sync.c Sat Sep 28 12:51:13 2002 +0300 @@ -25,7 +25,8 @@ return TRUE; } -int index_storage_sync(Mailbox *box, unsigned int *messages, int expunge, +int index_storage_sync(Mailbox *box, int expunge, + unsigned int *messages, unsigned int *recent, MailExpungeFunc expunge_func, MailFlagUpdateFunc flag_func, void *context) @@ -43,7 +44,7 @@ return FALSE; } - *messages = 0; + *messages = *recent = 0; if (!index_storage_sync_if_possible(ibox)) return FALSE; @@ -100,6 +101,7 @@ if (count > ibox->synced_messages_count) { /* new messages in mailbox */ *messages = count; + *recent = index_storage_get_recent_count(ibox->index); } ibox->synced_messages_count = count; }
--- a/src/lib-storage/mail-storage.h Fri Sep 27 17:16:52 2002 +0300 +++ b/src/lib-storage/mail-storage.h Sat Sep 28 12:51:13 2002 +0300 @@ -130,11 +130,13 @@ /* Synchronize the mailbox by reading all expunges and flag changes. If new mail has been added to mailbox, messages contains the total - number of messages in mailbox, otherwise 0. functions may be NULL. + number of messages in mailbox and recent is set, otherwise 0. + Functions may be NULL. If expunge is TRUE, deleted mails are expunged as well. Difference to expunge() function is that expunge_func is also called. */ - int (*sync)(Mailbox *box, unsigned int *messages, int expunge, + int (*sync)(Mailbox *box, int expunge, + unsigned int *messages, unsigned int *recent, MailExpungeFunc expunge_func, MailFlagUpdateFunc flag_func, void *context);