[Dovecot] dovecot notifying a database about total number of messages.
Hello,
in addition to our mail system, we have some other systems which needs to know how many messages, and how many unread messages, a user has in his/her inbox (maildir).
Currently, we have a mod_perl script which takes a mail address as input, and then traverses the maildir, and outputs the number of unread messages.
Our challenge is that the maildirs are located on a SAN, and traversing a maildir is slow. We currently have more than 100 requests pr. second, which we handle with caching, and spreading the load across different servers.
I'm looking into the possibility of either using dovecots index files, or having dovecot update a database with total number of messages/number of unread messages.
Question:
- if I'm using perl, is there any way I can read in the information in the index files? Is the data formatted in some standarized way, so that I can parse it, or use a module which read in the data?
(if I can read the indexes in wrapper scripts to imap/pop/deliver, then I could probably update a database with the information)
- how would you proceed, if the aim is to end up with dovecot notifying a database regarding the number of messages, and unread messages?
-- Erland Nylend
On Fri, 2007-08-17 at 13:33 +0200, Erland Nylend wrote:
- if I'm using perl, is there any way I can read in the information in the index files? Is the data formatted in some standarized way, so that I can parse it, or use a module which read in the data?
With v1.0 it would be pretty easy, but v1.1 makes this more difficult because it doesn't keep dovecot.index up-to-date all the time. Instead you'd have to read dovecot.index and apply new changes from dovecot.index.log.
- how would you proceed, if the aim is to end up with dovecot notifying a database regarding the number of messages, and unread messages?
Create a plugin which overrides mail_storage.sync_deinit(). Quota plugin could be used as an example:
static int quota_mailbox_sync_deinit(struct mailbox_sync_context *ctx, enum mailbox_status_items status_items, struct mailbox_status *status_r) { struct quota_mailbox *qbox = QUOTA_CONTEXT(ctx->box);
/* just in case sync_notify() wasn't called with uid=0 */
quota_mailbox_sync_finish(qbox);
return qbox->module_ctx.super.sync_deinit(ctx, status_items, status_r);
}
Call super.sync_deinit() with status_items having STATUS_UNREAD. status_r->unseen then contains the unseen counter.
If you want to avoid useless database updates, you could call mailbox_get_status() in sync_init() and save the unseen count there, and then compare in sync_deinit() if it got changed.
participants (2)
-
Erland Nylend
-
Timo Sirainen