mail-index.h revision d5aa01c4d7cc8b099f47cf011cba850b1759eb2d
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* Rebuild flag is set while index is being rebuilt or when
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen some error is noticed in the index file. If this flag is set,
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen the index shouldn't be used before rebuilding it. */
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainentypedef enum {
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* First MUST become a field that ALWAYS exists. This is because some
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen code which goes through all fields does it by calling
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen lookup_field(.., .., 1) and next() after that. If the first field
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen didn't exist, nothing would be found.
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen Location field is a good first field anyway, it's the one most
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen often needed. With maildir format, it's the file name and with
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen mbox format it's the file position as a string. */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen (((field) & (FIELD_TYPE_FROM | FIELD_TYPE_TO | FIELD_TYPE_CC | \
58a770f1e0ab553a0dba9cad9d6f3a6cdf2dc855Timo Sirainentypedef enum {
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainentypedef struct _MailIndexHeader MailIndexHeader;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainentypedef struct _MailIndexDataHeader MailIndexDataHeader;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainentypedef struct _MailIndexRecord MailIndexRecord;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainentypedef struct _MailIndexDataRecord MailIndexDataRecord;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainentypedef struct _MailIndexUpdate MailIndexUpdate;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* 0 = flags,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen 1 = sizeof(unsigned int),
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen 2 = sizeof(time_t),
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen 3 = sizeof(off_t) */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen unsigned int version;
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen unsigned int indexid;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen unsigned int flags;
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* these UIDs may not exist and may not even be unseen */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen unsigned int indexid;
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen unsigned int uid;
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen ((rec)->header_size + (rec)->body_size == (rec)->full_virtual_size)
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen char data[MEM_ALIGN_SIZE]; /* variable size */
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen (sizeof(MailIndexDataRecord) - MEM_ALIGN_SIZE + (rec)->full_field_size)
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen int (*open)(MailIndex *index, int update_recent);
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen int (*open_or_create)(MailIndex *index, int update_recent);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* Free index from memory. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* Lock/unlock index. May block. Note that unlocking must not
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen reset error from get_last_error() as unlocking can be done as
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen a cleanup after some other function failed. Index is always
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen mmap()ed after set_lock() succeeds.
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen Trying to change a shared lock into exclusive lock is a fatal
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen error, since it may create a deadlock. Even though operating
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen system should detect it and fail, it's not a good idea to even
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen let it happen. Better ways to do this would be to a) mark the
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen data to be updated later, b) use try_lock() if the update is
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen preferred but not required, c) unlock + lock again, but make
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen sure that won't create race conditions */
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen int (*set_lock)(MailIndex *index, MailLockType lock_type);
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen /* Try locking the index. Returns TRUE if the lock was got and
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen FALSE if lock isn't possible to get currently or some other error
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen occured. Never blocks. */
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen int (*try_lock)(MailIndex *index, MailLockType lock_type);
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen /* Rebuild the whole index. Note that this changes the indexid
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen so all the other files must also be rebuilt after this call.
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen Index MUST NOT have shared lock, exclusive lock or no lock at all
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen is fine. Note that this function may leave the index exclusively
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* Verify that the index is valid. If anything invalid is found,
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen rebuild() is called. Same locking issues as with rebuild(). */
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen /* Synchronize the index with the mailbox. Same locking issues as
99df8a838cd9c5257ea5a2554383a9a999191e38Pali Rohár with rebuild(). */
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* Returns the index header (never fails). The index needs to be
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen locked before calling this function, and must be kept locked as
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen long as you keep using the returned structure. */
99df8a838cd9c5257ea5a2554383a9a999191e38Pali Rohár MailIndexHeader *(*get_header)(MailIndex *index);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* sequence -> data lookup. The index needs to be locked before calling
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen this function, and must be kept locked as long as you keep using
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen the returned structure. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen MailIndexRecord *(*lookup)(MailIndex *index, unsigned int seq);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* Return the next record after specified record, or NULL if it was
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen last record. The index must be locked all the time between
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen lookup() and last next() call. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen MailIndexRecord *(*next)(MailIndex *index, MailIndexRecord *rec);
unsigned int first_uid,
unsigned int last_uid);
int external_change);
unsigned int indexid;
int mbox_locks;
void *mmap_base;
unsigned int last_lookup_seq;
unsigned int first_recent_uid;
unsigned int modifylog_id;
unsigned int set_flags;
unsigned int set_cache_fields;
#define MAIL_INDEX_PRIVATE_FILL \
unsigned int first_uid,
unsigned int last_uid);
int external_change);