mail-index.h revision 29c8f5c5f7d659cc96f3c45aaf80b113f4ac2315
66ae183b6e895216037bd921367670f4b0665911Timo Sirainen /* Rebuild flag is set while index is being rebuilt or when
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen some error is noticed in the index file. If this flag is set,
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen the index shouldn't be used before rebuilding it. */
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainentypedef enum {
8fa41238067c854435884c459963fde6f8c6436bTimo Sirainentypedef enum {
8fa41238067c854435884c459963fde6f8c6436bTimo Sirainen /* If binary flags are set, it's not checked whether mail is
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen missing CRs. So this flag may be set as an optimization for
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen regular non-binary mails as well if it's known that it contains
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen valid CR+LF line breaks. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Currently this means with mbox format that message flags have
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen been changed in index, but not written into mbox file yet. */
b66a207ddcfc72a634186ec7e9a82df28ffc1d4eTimo Sirainen (((field) & (FIELD_TYPE_FROM | FIELD_TYPE_TO | FIELD_TYPE_CC | \
b66a207ddcfc72a634186ec7e9a82df28ffc1d4eTimo Sirainen (((field) & (FIELD_TYPE_BODY|FIELD_TYPE_BODYSTRUCTURE| \
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainentypedef enum {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef struct _MailCustomFlags MailCustomFlags;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainentypedef struct _MailIndexHeader MailIndexHeader;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef struct _MailIndexDataHeader MailIndexDataHeader;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainentypedef struct _MailIndexRecord MailIndexRecord;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainentypedef struct _MailIndexDataRecord MailIndexDataRecord;
9f32b9444d2a6db8f556d2c49ffceab1a59791ffTimo Sirainentypedef struct _MailIndexUpdate MailIndexUpdate;
648d24583c1574441c4fa0331a90bd4d6e7996c5Timo Sirainen /* 0 = version
ee246b46953e4b94b2f22e093373674fa9155500Timo Sirainen 2 = sizeof(unsigned int),
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen 3 = sizeof(time_t),
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen 4 = sizeof(uoff_t),
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen 5 = MEM_ALIGN_SIZE */
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen unsigned int indexid;
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainen unsigned int sync_id; /* re-mmap() when changed, required only
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if file size is changed */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int flags;
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainen /* these UIDs may not exist and may not even be unseen */
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen unsigned int indexid;
036626b19f14bef582f96e556913ae91b1d67881Timo Sirainen unsigned int reserved; /* for alignment mostly */
b66a207ddcfc72a634186ec7e9a82df28ffc1d4eTimo Sirainen /* remember to keep uoff_t's 8 byte aligned so we don't waste space */
b66a207ddcfc72a634186ec7e9a82df28ffc1d4eTimo Sirainen unsigned int uid;
b66a207ddcfc72a634186ec7e9a82df28ffc1d4eTimo Sirainen unsigned int index_flags; /* MailIndexMailFlags */
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen uoff_t body_size; /* if header_size == 0, the size of full message */
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen char data[MEM_ALIGN_SIZE]; /* variable size */
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen (sizeof(MailIndexDataRecord) - MEM_ALIGN_SIZE)
47e0598840ecffa364ebed523e06939e22738f06Timo Sirainen (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* If fast is TRUE, compressing and cache updates are not performed.
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen Note that opening same index twice in the same process is a bad
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen idea since they share the same file locks. As soon one of the
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen indexes is closed, the locks in second index are dropped which
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen especially hurts modify log since it keeps locks all the time. */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int (*open)(MailIndex *index, int update_recent, int fast);
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen int (*open_or_create)(MailIndex *index, int update_recent, int fast);
d161e3c2cde2bd8d5917840f68823a2259ed426eTimo Sirainen /* Free index from memory. */
1e923fcf497665fe071a154c31fb452766b0b2deTimo Sirainen /* Lock/unlock index. May block. Note that unlocking must not
d161e3c2cde2bd8d5917840f68823a2259ed426eTimo Sirainen reset error from get_last_error() as unlocking can be done as
1e923fcf497665fe071a154c31fb452766b0b2deTimo Sirainen a cleanup after some other function failed. Index is always
d161e3c2cde2bd8d5917840f68823a2259ed426eTimo Sirainen mmap()ed after set_lock() succeeds.
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen Trying to change a shared lock into exclusive lock is a fatal
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen error, since it may create a deadlock. Even though operating
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen system should detect it and fail, it's not a good idea to even
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch let it happen. Better ways to do this would be to a) mark the
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen data to be updated later, b) use try_lock() if the update is
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen preferred but not required, c) unlock + lock again, but make
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen sure that won't create race conditions */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int (*set_lock)(MailIndex *index, MailLockType lock_type);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Try locking the index. Returns TRUE if the lock was got and
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen FALSE if lock isn't possible to get currently or some other error
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen occured. Never blocks. */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen int (*try_lock)(MailIndex *index, MailLockType lock_type);
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen /* Rebuild the whole index. Note that this changes the indexid
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen so all the other files must also be rebuilt after this call.
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen Index MUST NOT have shared lock, but exclusive lock or no lock at
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen all is fine. Note that this function may leave the index
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen exclusively locked, and always sets index->inconsistent = TRUE. */
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen /* Verify that the index is valid. If anything invalid is found,
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen index is set inconsistent and to be rebuilt at next open.
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen Same locking issues as with rebuild(). */
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen /* Synchronize the index with the mailbox. Same locking issues as
ea91861234475257f436dc07925f80cf4ac32b71Timo Sirainen with rebuild(). */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen /* Returns the index header (never fails). The index needs to be
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen locked before calling this function, and must be kept locked as
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen long as you keep using the returned structure. */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen MailIndexHeader *(*get_header)(MailIndex *index);
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen /* sequence -> data lookup. The index needs to be locked before calling
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen this function, and must be kept locked as long as you keep using
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen the returned structure. */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen MailIndexRecord *(*lookup)(MailIndex *index, unsigned int seq);
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen /* Return the next record after specified record, or NULL if it was
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen last record. The index must be locked all the time between
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen lookup() and last next() call. */
c5454841b5067a22827556ca9bc7935d190f57baTimo Sirainen MailIndexRecord *(*next)(MailIndex *index, MailIndexRecord *rec);
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen /* Find first existing UID in range. Sequence number is also retrieved
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if seq_r is non-NULL. */
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen MailIndexRecord *(*lookup_uid_range)(MailIndex *index,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen unsigned int *seq_r);
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Find field from specified record, or NULL if it's not in index.
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen Makes sure that the field ends with \0. */
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen const char *(*lookup_field)(MailIndex *index, MailIndexRecord *rec,
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen /* Find field from specified record, or NULL if it's not in index. */
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen const void *(*lookup_field_raw)(MailIndex *index, MailIndexRecord *rec,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Mark the fields to be cached later. If any of them is already
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen set in hdr->cache_fields, mark the caching to happen next time
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen index is opened. */
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen void (*cache_fields_later)(MailIndex *index, MailField field);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen /* Open mail file and return it as mmap()ed IBuffer. If we fails,
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen we return NULL and set deleted = TRUE if failure was because the
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen mail was just deleted (ie. not an error). */
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen IBuffer *(*open_mail)(MailIndex *index, MailIndexRecord *rec,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen /* Expunge a mail from index. Tree and modifylog is also updated. The
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen index must be exclusively locked before calling this function.
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen If seq is 0, the modify log isn't updated. This is useful if
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen after append() something goes wrong and you wish to delete the
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen mail immediately. If external_change is TRUE, the modify log is
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen always written.
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen Note that the sequence numbers also update immediately after this
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen call, so if you want to delete messages 1..4 just call this
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen function 4 times with seq being 1. */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int (*expunge)(MailIndex *index, MailIndexRecord *rec,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Update mail flags. The index must be exclusively locked before
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen calling this function. This shouldn't be called in the middle of
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen update_begin() as it may modify location field. */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen int (*update_flags)(MailIndex *index, MailIndexRecord *rec,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen /* Append a new record to index. The index must be exclusively
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen locked before calling this function. The record pointer is
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen updated to the mmap()ed record. rec->uid is updated in
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen append_end(). */
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen int (*append_begin)(MailIndex *index, MailIndexRecord **rec);
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen int (*append_end)(MailIndex *index, MailIndexRecord *rec);
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen /* Updating fields happens by calling update_begin(), one or more
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen update_field()s and finally update_end() which does the actual
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen updating. The index must be exclusively locked all this time.
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen update_begin() and update_field() functions cannot fail.
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen The extra_space parameter for update_field() specifies the amount
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen of extra empty space we should leave after the value, so that if
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen the field grows in future it could be expanded without copying it
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen to end of file. When the field already exists, the extra_space
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen The files may not actually be updated until after you've unlocked
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen MailIndexUpdate *(*update_begin)(MailIndex *index,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen void (*update_field)(MailIndexUpdate *update, MailField field,
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen /* Just remember that full_field_size will be MEM_ALIGNed, so
6825360d446542046757b06064282301c4c6b27cTimo Sirainen it may differer from the given size parameter. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen void (*update_field_raw)(MailIndexUpdate *update, MailField field,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Returns last error message */
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen const char *(*get_last_error)(MailIndex *index);
6a04c5112961c5f4fb2d2f25192b3dc424d62ad0Timo Sirainen /* Returns TRUE if last error was because we ran out of available
3ccab0bac68040f179a7de45c516cec258e28fdbTimo Sirainen disk space. */
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen /* Returns TRUE if index is now in inconsistent state with the
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen previous known state, meaning that the message IDs etc. may
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen have changed - only way to recover this would be to fully close
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen the mailbox and reopen it. With IMAP connection this would mean
6825360d446542046757b06064282301c4c6b27cTimo Sirainen a forced disconnection since we can't do forced CLOSE. */
6825360d446542046757b06064282301c4c6b27cTimo Sirainen int (*is_inconsistency_error)(MailIndex *index);
6825360d446542046757b06064282301c4c6b27cTimo Sirainen/* private: */
c8d093d149253fe8faec267c5057f45fe626f84cTimo Sirainen char *dir; /* directory where to place the index files */
6825360d446542046757b06064282301c4c6b27cTimo Sirainen MailField default_cache_fields, never_cache_fields;
6825360d446542046757b06064282301c4c6b27cTimo Sirainen unsigned int indexid;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int sync_id;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen char *mbox_path; /* mbox-specific path to the actual mbox file */
f5c53272acbe1517440aa9c277133babc887ee84Timo Sirainen /* these counters can be used to check that we've synced the mailbox
31a574fda352ef4f71dbff9c30e15e4744e132c0Timo Sirainen after locking it */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen /* last mbox sync: */
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen /* these fields are OR'ed to the fields in index header once we
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen get around grabbing exclusive lock */
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen/* needed to remove annoying warnings about not initializing all struct
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen 0, 0, 0, 0, 0
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainen/* defaults - same as above but prefixed with mail_index_. */
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenint mail_index_open(MailIndex *index, int update_recent, int fast);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenint mail_index_open_or_create(MailIndex *index, int update_recent, int fast);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenint mail_index_set_lock(MailIndex *index, MailLockType lock_type);
4a09c57f1c66b4a8880bcc12b567bb42c3549f52Timo Sirainenint mail_index_try_lock(MailIndex *index, MailLockType lock_type);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo SirainenMailIndexHeader *mail_index_get_header(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo SirainenMailIndexRecord *mail_index_lookup(MailIndex *index, unsigned int seq);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo SirainenMailIndexRecord *mail_index_next(MailIndex *index, MailIndexRecord *rec);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo SirainenMailIndexRecord *mail_index_lookup_uid_range(MailIndex *index,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen unsigned int *seq_r);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenconst char *mail_index_lookup_field(MailIndex *index, MailIndexRecord *rec,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenconst void *mail_index_lookup_field_raw(MailIndex *index, MailIndexRecord *rec,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_cache_fields_later(MailIndex *index, MailField field);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_expunge(MailIndex *index, MailIndexRecord *rec,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_update_flags(MailIndex *index, MailIndexRecord *rec,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_append_begin(MailIndex *index, MailIndexRecord **rec);
e7d0bea63a08b08c47c4b5c187d2cb7127859657Timo Sirainenint mail_index_append_end(MailIndex *index, MailIndexRecord *rec);
e7d0bea63a08b08c47c4b5c187d2cb7127859657Timo SirainenMailIndexUpdate *mail_index_update_begin(MailIndex *index,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_update_end(MailIndexUpdate *update);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_update_field(MailIndexUpdate *update, MailField field,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_update_field_raw(MailIndexUpdate *update, MailField field,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenconst char *mail_index_get_last_error(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_is_diskspace_error(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_is_inconsistency_error(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen/* INTERNAL: */
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_init_header(MailIndex *index, MailIndexHeader *hdr);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_fmdatasync(MailIndex *index, size_t size);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_verify_hole_range(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_mark_flag_changes(MailIndex *index, MailIndexRecord *rec,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenvoid mail_index_update_headers(MailIndexUpdate *update, IBuffer *inbuf,
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen MessageHeaderFunc header_func, void *context);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainenint mail_index_compress_data(MailIndex *index);
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen/* Max. mmap()ed size for a message */
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen/* Delete unused non-local temp files after 24h. Just to be sure we don't
3f2ad7b8c3a243dabcba469c8a331423d036f3fcTimo Sirainen delete it too early. The temp files don't harm much anyway. */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen/* number of records to always keep allocated in index file,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen either used or unused */
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen/* when empty space in index file gets full, grow the file n% larger */
c53e8ee216904ffe6de4f6518d9f9f5107b7610eTimo Sirainen/* ftruncate() the index file when only n% of it is in use */
c53e8ee216904ffe6de4f6518d9f9f5107b7610eTimo Sirainen/* don't truncate whole file anyway, keep n% of the empty space */
c53e8ee216904ffe6de4f6518d9f9f5107b7610eTimo Sirainen/* Compress the file when deleted space reaches n% of total size */
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen/* uoff_t to index file for given record */
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen ((uoff_t) ((char *) (ptr) - (char *) ((index)->mmap_base)))
1e47cfede3a0b62654105daab00e97b5d660bc6bTimo Sirainen/* index number for uoff_t position */
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (((pos) - sizeof(MailIndexHeader)) / sizeof(MailIndexRecord))
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen/* index number for given record */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen INDEX_POSITION_INDEX(INDEX_FILE_POSITION(index, ptr))
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen/* mark the index corrupted */
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen STMT_START { (index)->set_flags |= MAIL_INDEX_FLAG_REBUILD; } STMT_END
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen/* get number of records in mmaped index */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen ((index->mmap_used_length - sizeof(MailIndexHeader)) / \
e4b09b008ab544eb8994beecbfffefa21d855e43Timo Sirainen/* minimum size for index file */