2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo Sirainen/* how many seconds to wait before overriding uidlist.lock */
2e7e4804d8a88b10e00a3f9ec3726759ae0a6a13Timo Sirainen#define MAILDIR_UIDLIST_LOCK_STALE_TIMEOUT (60*2)
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen /* POP3 UIDL format unless overridden by records */
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen MAILDIR_UIDLIST_HDR_EXT_POP3_UIDL_FORMAT = 'P'
df9169221169d9cd8d8f49fc51ad40bed0fb6f64Timo Sirainen#define MAILDIR_UIDLIST_REC_EXT_KEY_IS_VALID(c) \
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen /* Physical message size. If filename also contains ,S=<vsize> this
97eb53ade9057e6966dbb77289ad0204c7e1657bTimo Sirainen isn't written to uidlist. */
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen /* Virtual message size. If filename also contains ,W=<vsize> this
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen isn't written to uidlist. */
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen /* POP3 UIDL overriding the default format */
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen /* POP3 message ordering number. Lower numbered messages are listed
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen first. Messages without ordering number are listed after them.
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen The idea is to be able to preserve POP3 UIDL list and IMAP UIDs
e1eeb3be29afde2830c2b7ed594c6f1fef2f69dcTimo Sirainen perfectly when migrating from other servers. */
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen /* Message GUID (default is the base filename) */
09c3a491f4f6ccebe290c7709bdc0d79a187610bTimo Sirainenint maildir_uidlist_lock(struct maildir_uidlist *uidlist);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint maildir_uidlist_try_lock(struct maildir_uidlist *uidlist);
4673afe816ffbca769585e4518e9b3c3d72e95ddTimo Sirainenint maildir_uidlist_lock_touch(struct maildir_uidlist *uidlist);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid maildir_uidlist_unlock(struct maildir_uidlist *uidlist);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool maildir_uidlist_is_locked(struct maildir_uidlist *uidlist);
a0aedab7cd06125e4d73638b1bd0c01c7caa2626Timo Sirainenbool maildir_uidlist_is_read(struct maildir_uidlist *uidlist);
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainen/* Returns TRUE if uidlist file is currently open */
6013fbad6638795a00e6c2a2dd2cdbee19612494Timo Sirainenbool maildir_uidlist_is_open(struct maildir_uidlist *uidlist);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenstruct maildir_uidlist *maildir_uidlist_init(struct maildir_mailbox *mbox);
9740d55b228a670047c854484d5cc979a056a9afTimo Sirainenvoid maildir_uidlist_deinit(struct maildir_uidlist **uidlist);
746a7ec64a09649ed3c96c88b97cdc370a7bbe2fTimo Sirainen/* Returns -1 if error, 0 if file is broken or lost, 1 if ok. If nfs_flush=TRUE
746a7ec64a09649ed3c96c88b97cdc370a7bbe2fTimo Sirainen and storage has NFS_FLUSH flag set, the NFS attribute cache is flushed to
746a7ec64a09649ed3c96c88b97cdc370a7bbe2fTimo Sirainen make sure that we see the latest uidlist file. */
4f44284b96302c0a18203e2ac1243aeb193c6840Timo Sirainenint maildir_uidlist_refresh(struct maildir_uidlist *uidlist);
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen/* Like maildir_uidlist_refresh(), but if uidlist isn't opened yet, try to
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainen fill in the uidvalidity/nextuid from index file instead. */
7c65a07e04f28f2a881d83989f85f9ad0e87a7b4Timo Sirainenint maildir_uidlist_refresh_fast_init(struct maildir_uidlist *uidlist);
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen/* Look up uidlist record for given filename. Returns 1 if found,
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen 0 if not found, -1 if error */
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainenint maildir_uidlist_lookup(struct maildir_uidlist *uidlist, uint32_t uid,
7ede6554e451ec039a67beec7d6ee4aff61d386eTimo Sirainen const char **fname_r);
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainen/* Returns extension's value or NULL if it doesn't exist. */
621e8c0767de486db8d4ebb317d441b3f3a0434fTimo Sirainenmaildir_uidlist_lookup_ext(struct maildir_uidlist *uidlist, uint32_t uid,
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenuint32_t maildir_uidlist_get_uid_validity(struct maildir_uidlist *uidlist);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenuint32_t maildir_uidlist_get_next_uid(struct maildir_uidlist *uidlist);
c0bfb67ba32064347bac3241f1aac9b8a809e2f1Timo Sirainenint maildir_uidlist_get_mailbox_guid(struct maildir_uidlist *uidlist,
17ad2164c747cedbf81dae1893063e71a3df0356Timo Sirainenvoid maildir_uidlist_set_mailbox_guid(struct maildir_uidlist *uidlist,
92888ef30960c30ccc9e030fe7eab5d4d04a7d1cTimo Sirainenvoid maildir_uidlist_set_uid_validity(struct maildir_uidlist *uidlist,
6b77095184aeb8a9976a74fa9ba1a06740f40d0eTimo Sirainenvoid maildir_uidlist_set_next_uid(struct maildir_uidlist *uidlist,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen/* Update extended record. */
81c7a6e414a6d1c31f65cc977feda823b586d263Timo Sirainenvoid maildir_uidlist_set_ext(struct maildir_uidlist *uidlist, uint32_t uid,
81c7a6e414a6d1c31f65cc977feda823b586d263Timo Sirainen const char *value);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenvoid maildir_uidlist_unset_ext(struct maildir_uidlist *uidlist, uint32_t uid,
81c7a6e414a6d1c31f65cc977feda823b586d263Timo Sirainen/* If uidlist has changed, update it. This is mostly meant to be used with
81c7a6e414a6d1c31f65cc977feda823b586d263Timo Sirainen maildir_uidlist_set_ext() */
81c7a6e414a6d1c31f65cc977feda823b586d263Timo Sirainenint maildir_uidlist_update(struct maildir_uidlist *uidlist);
785d9cca224d33ca3938e9166784f6483e8a27d7Timo Sirainenvoid maildir_uidlist_set_all_nonsynced(struct maildir_uidlist *uidlist);
57a91f930a12d2cd1220da4f3f7cb2c47557cd37Timo Sirainen/* Sync uidlist with what's actually on maildir. Returns same as
57a91f930a12d2cd1220da4f3f7cb2c47557cd37Timo Sirainen maildir_uidlist_lock(). */
e32cf1b4430c4a5f28c9b5bb8b1366e7b06ed68dTimo Sirainenint maildir_uidlist_sync_init(struct maildir_uidlist *uidlist,
57a91f930a12d2cd1220da4f3f7cb2c47557cd37Timo Sirainen struct maildir_uidlist_sync_ctx **sync_ctx_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint maildir_uidlist_sync_next(struct maildir_uidlist_sync_ctx *ctx,
3054cbf69a94ca08123ca3a8d6a2c19a1784e11dTimo Sirainenint maildir_uidlist_sync_next_uid(struct maildir_uidlist_sync_ctx *ctx,
2087637d10ad94ea029fe055f8ee55cd594955a8Timo Sirainenvoid maildir_uidlist_sync_remove(struct maildir_uidlist_sync_ctx *ctx,
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainenvoid maildir_uidlist_sync_set_ext(struct maildir_uidlist_sync_ctx *ctx,
e4e7475f646d66a257d682738fbff1f206ce4924Timo Sirainen const char *value);
2bde8972f2dcec46d96543407cc5b56954054359Timo Sirainenvoid maildir_uidlist_update_fname(struct maildir_uidlist *uidlist,
4b43f50117630aa12b3cfd0cbd05ae22ba27fec1Timo Sirainenmaildir_uidlist_sync_get_full_filename(struct maildir_uidlist_sync_ctx *ctx,
777ff25e82e0305e2696bcbe3c6e0274e3e8ce10Timo Sirainenvoid maildir_uidlist_sync_recreate(struct maildir_uidlist_sync_ctx *ctx);
73c76fa7340a107229c530196d026aadeae979c7Timo Sirainenvoid maildir_uidlist_sync_finish(struct maildir_uidlist_sync_ctx *ctx);
aa62d8779ce53900c2f09bf2ff6fa790bc9f6a89Timo Sirainenint maildir_uidlist_sync_deinit(struct maildir_uidlist_sync_ctx **ctx,
228edfb38d7f1a0bfe36f74e7c521006ea48fbdfTimo Sirainenbool maildir_uidlist_get_uid(struct maildir_uidlist *uidlist,
0f506139b4c95589a09a81a5d51636aee994cd1eTimo Sirainenmaildir_uidlist_get_full_filename(struct maildir_uidlist *uidlist,
316689d0ef55e2fa4e2fb4ac5b1ea35ce65688d3Timo Sirainenvoid maildir_uidlist_add_flags(struct maildir_uidlist *uidlist,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* List all maildir files. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmaildir_uidlist_iter_init(struct maildir_uidlist *uidlist);
1302f472805684b42ead4be8e4d5cbd95dfdc29bTimo Sirainenbool maildir_uidlist_iter_next(struct maildir_uidlist_iter_ctx *ctx,
1302f472805684b42ead4be8e4d5cbd95dfdc29bTimo Sirainen const char **filename_r);