maildir-uidlist.h revision e30b748edcef3cf3352478bf21fa8f785bdc773a
7e19fab3af21714e410863295a27b859111ba40dEugen Kuksa#ifndef MAILDIR_UIDLIST_H
7e19fab3af21714e410863295a27b859111ba40dEugen Kuksa#define MAILDIR_UIDLIST_H
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa#define MAILDIR_UIDLIST_NAME "dovecot-uidlist"
abc834c020080fe44a1ea4e34278327e99e3e12eEugen Kuksa
abc834c020080fe44a1ea4e34278327e99e3e12eEugen Kuksastruct maildir_mailbox;
abc834c020080fe44a1ea4e34278327e99e3e12eEugen Kuksastruct maildir_uidlist;
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksastruct maildir_uidlist_sync_ctx;
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksaenum maildir_uidlist_sync_flags {
6bbb71b52f053c148669e5b128e236781150da1fEugen Kuksa MAILDIR_UIDLIST_SYNC_PARTIAL = 0x01,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_SYNC_KEEP_STATE = 0x02,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_SYNC_FORCE = 0x04,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_SYNC_TRYLOCK = 0x08
255e2c2477c832c7a785ae0ae77fd25add1e58e6Eugen Kuksa};
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa
255e2c2477c832c7a785ae0ae77fd25add1e58e6Eugen Kuksaenum maildir_uidlist_rec_flag {
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_FLAG_NEW_DIR = 0x01,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_FLAG_MOVED = 0x02,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_FLAG_RECENT = 0x04,
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_FLAG_NONSYNCED = 0x08,
255e2c2477c832c7a785ae0ae77fd25add1e58e6Eugen Kuksa MAILDIR_UIDLIST_REC_FLAG_RACING = 0x10
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa};
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksaenum maildir_uidlist_hdr_ext_key {
8230471f68bf2a663d94872531d0bcf16d426bbeEugen Kuksa MAILDIR_UIDLIST_HDR_EXT_UID_VALIDITY = 'V',
8230471f68bf2a663d94872531d0bcf16d426bbeEugen Kuksa MAILDIR_UIDLIST_HDR_EXT_NEXT_UID = 'N',
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa /* POP3 UIDL format unless overridden by records */
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_HDR_EXT_POP3_UIDL_FORMAT = 'P'
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa};
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksaenum maildir_uidlist_rec_ext_key {
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa /* Virtual message size. If filename also contains ,W=<vsize> this
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa isn't written to uidlist. */
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_EXT_VSIZE = 'W',
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa /* POP3 UIDL overriding the default format */
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa MAILDIR_UIDLIST_REC_EXT_POP3_UIDL = 'P'
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa};
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksa
f0264afd33a980b6584747fc8159ee950805d9e3Eugen Kuksaint maildir_uidlist_lock(struct maildir_uidlist *uidlist);
b51057b860560bf3ee454c03a121af3d5d34f482Eugen Kuksaint maildir_uidlist_try_lock(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaint maildir_uidlist_lock_touch(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksavoid maildir_uidlist_unlock(struct maildir_uidlist *uidlist);
28001d576e67ba46ed481c5695f1e0827ff26007Eugen Kuksabool maildir_uidlist_is_locked(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
b1fe9054ad7c7192fe4c474363247dad15963e99Eugen Kuksastruct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksastruct maildir_uidlist *
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksamaildir_uidlist_init_readonly(struct index_mailbox *ibox);
d89f470f7da0b9f8295d0ac0defff09884894b8bEugen Kuksavoid maildir_uidlist_deinit(struct maildir_uidlist **uidlist);
d89f470f7da0b9f8295d0ac0defff09884894b8bEugen Kuksa
d89f470f7da0b9f8295d0ac0defff09884894b8bEugen Kuksa/* Returns -1 if error, 0 if file is broken or lost, 1 if ok. If nfs_flush=TRUE
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa and storage has NFS_FLUSH flag set, the NFS attribute cache is flushed to
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa make sure that we see the latest uidlist file. */
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaint maildir_uidlist_refresh(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa/* Returns uidlist record for given filename, or NULL if not found. */
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaconst char *
6bbb71b52f053c148669e5b128e236781150da1fEugen Kuksamaildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa enum maildir_uidlist_rec_flag *flags_r);
4fbbf628eda08ffdeb98cb41fb7e9001050eec3aEugen Kuksa/* Returns extension's value or NULL if it doesn't exist. */
4fbbf628eda08ffdeb98cb41fb7e9001050eec3aEugen Kuksaconst char *
4fbbf628eda08ffdeb98cb41fb7e9001050eec3aEugen Kuksamaildir_uidlist_lookup_ext(struct maildir_uidlist *uidlist, uint32_t uid,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa enum maildir_uidlist_rec_ext_key key);
67daeb8066e4460cb820db60c45138dd48309bb9Eugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksauint32_t maildir_uidlist_get_uid_validity(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksauint32_t maildir_uidlist_get_next_uid(struct maildir_uidlist *uidlist);
7e19fab3af21714e410863295a27b859111ba40dEugen Kuksa
7e19fab3af21714e410863295a27b859111ba40dEugen Kuksavoid maildir_uidlist_set_uid_validity(struct maildir_uidlist *uidlist,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa uint32_t uid_validity);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksavoid maildir_uidlist_set_next_uid(struct maildir_uidlist *uidlist,
a8028fd2789e323040de08827a0fe1f7d36fde2bEugen Kuksa uint32_t next_uid, bool force);
a8028fd2789e323040de08827a0fe1f7d36fde2bEugen Kuksa
a8028fd2789e323040de08827a0fe1f7d36fde2bEugen Kuksavoid maildir_uidlist_set_ext(struct maildir_uidlist *uidlist, uint32_t uid,
255e2c2477c832c7a785ae0ae77fd25add1e58e6Eugen Kuksa enum maildir_uidlist_rec_ext_key key,
7e19fab3af21714e410863295a27b859111ba40dEugen Kuksa const char *value);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa/* If uidlist has changed, update it. This is mostly meant to be used with
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa maildir_uidlist_set_ext() */
67daeb8066e4460cb820db60c45138dd48309bb9Eugen Kuksaint maildir_uidlist_update(struct maildir_uidlist *uidlist);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa/* Sync uidlist with what's actually on maildir. Returns same as
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa maildir_uidlist_lock(). */
4ec9d8b62c3c1a001548eb0883b6f81e00c391a0Eugen Kuksaint maildir_uidlist_sync_init(struct maildir_uidlist *uidlist,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa enum maildir_uidlist_sync_flags sync_flags,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa struct maildir_uidlist_sync_ctx **sync_ctx_r);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa/* Returns 1 = ok, -1 = error, 0 = new file and dovecot-uidlist is locked */
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaint maildir_uidlist_sync_next_pre(struct maildir_uidlist_sync_ctx *ctx,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa const char *filename);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaint maildir_uidlist_sync_next(struct maildir_uidlist_sync_ctx *ctx,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa const char *filename,
4ec9d8b62c3c1a001548eb0883b6f81e00c391a0Eugen Kuksa enum maildir_uidlist_rec_flag flags);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksavoid maildir_uidlist_sync_remove(struct maildir_uidlist_sync_ctx *ctx,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa const char *filename);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaconst char *
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksamaildir_uidlist_sync_get_full_filename(struct maildir_uidlist_sync_ctx *ctx,
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa const char *filename);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksavoid maildir_uidlist_sync_finish(struct maildir_uidlist_sync_ctx *ctx);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaint maildir_uidlist_sync_deinit(struct maildir_uidlist_sync_ctx **ctx);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksabool maildir_uidlist_get_uid(struct maildir_uidlist *uidlist,
4ec9d8b62c3c1a001548eb0883b6f81e00c391a0Eugen Kuksa const char *filename, uint32_t *uid_r);
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksaconst char *
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksamaildir_uidlist_get_full_filename(struct maildir_uidlist *uidlist,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa const char *filename);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa
923d69139038e74c0936e826bbfdc8717fbbc7b3Eugen Kuksavoid maildir_uidlist_add_flags(struct maildir_uidlist *uidlist,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa const char *filename,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa enum maildir_uidlist_rec_flag flags);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa/* List all maildir files. */
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksastruct maildir_uidlist_iter_ctx *
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksamaildir_uidlist_iter_init(struct maildir_uidlist *uidlist);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksabool maildir_uidlist_iter_next(struct maildir_uidlist_iter_ctx *ctx,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa uint32_t *uid_r,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa enum maildir_uidlist_rec_flag *flags_r,
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa const char **filename_r);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksavoid maildir_uidlist_iter_deinit(struct maildir_uidlist_iter_ctx **ctx);
5efadb4662f2a63d5f5f1a5b303ab7c3371069a8Eugen Kuksa
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa#endif
daf3e28fff47a65b53d6fb65155301763b9f166eEugen Kuksa