[Dovecot] index synchronization during local delivery
Timo Sirainen
tss at iki.fi
Wed Feb 15 04:19:00 EET 2012
On 14.2.2012, at 5.31, Andy YB Hu wrote:
> Now our system will take dovecot as the whole imap back end, and keep the
> LDA of ours, But our system has our own UID generation mechanism (in
> dovecot it's incremental from 1), which will be done while local delivery,
> So when local deliveries, it will first generate the UID, move the mail
> into maildir, then synchronize the mailbox index, which is part of dovecot
> LDA does. The question is what API or something else about index
> synchronization I can integrate into our own LDA program easily? Seems
> mailbox_copy() would be the possibility?
If you want it to be free of race conditions:
1. Write the mail to tmp/
2. Create dovecot-uidlist.lock
3. Generate the UID and move the mail to new/ or cur/
4. Append a line to dovecot-uidlist with your UID and the Maildir filename
5. Delete dovecot-uidlist.lock
Although it sounds like the UID is generated before you can even create uidlist lock? That means IMAP client can at the same time generate a conflicting UID with APPEND/COPY. Also remember that UIDs must always be increasing. If you try to add a new message with lower UID then Dovecot won't like it, and even if you fix that, some IMAP clients may never see the mail.
Anyway, once you have uidlist updated you can do indexing/caching with e.g. "doveadm index" command in v2.0.
More information about the dovecot
mailing list