mail-storage.h revision d23c747de9d33966483fbdd41f08ad7766da7c5c
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* If some operation is taking long, call notify_ok every n seconds. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Print debugging information while initializing the storage */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Allow full filesystem access with absolute or relative paths. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't try to mmap() files */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't try to write() to mmap()ed files. Required for the few
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen OSes that don't have unified buffer cache
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen (currently OpenBSD <= 3.5) */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Remember message headers' MD5 sum */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Use CRLF linefeeds when saving mails. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Don't try to autodetect anything, require that the given data
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen contains all the necessary information. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Don't autocreate any directories. If they don't exist,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen fail to create the storage. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Rely on O_EXCL when creating dotlocks */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Flush NFS caches for mail storage / index */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't use fsync() or fdatasync() */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen /* Mailbox must not be modified even if asked */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Only saving/copying mails to mailbox works. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Any extra time consuming operations shouldn't be performed
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (eg. when opening mailbox just for STATUS). */
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen /* Don't reset MAIL_RECENT flags when syncing */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Don't create index files for the mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Keep mailbox exclusively locked all the time while it's open */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Enable tracking modsequences */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen /* Enable tracking expunge modsequences */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Update search results whenever the mailbox view is synced.
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen Expunged messages are removed even without this flag. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Queue changes so _sync() can be used. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Maximum size for sort program (each one separately + END) */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_FLAG_REVERSE = 0x1000, /* reverse this mask type */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MAIL_SORT_END = 0x0000 /* ends sort program */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Set has_nuls / has_no_nuls fields */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* specials: */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Hide changes done in this transaction from next view sync */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* External transaction. Should be used for copying and appends,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen but nothing else. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Always assign UIDs to messages when saving/copying. Normally this
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen is done only if the mailbox is synced, or if dest_mail parameter
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen was non-NULL to mailbox_save_init() or mailbox_copy() */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Refresh the index so lookups return latest flags/modseqs */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Make sure we sync all external changes done to mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Make sure we write all our internal changes into the mailbox */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* If it's not too much trouble, check if there are some changes */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Don't sync expunges from our view */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Stop auto syncing */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* If mailbox is currently inconsistent, fix it instead of failing. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen /* Syncing after an EXPUNGE command. This is just an informational
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen flag for plugins. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* There are expunges that haven't been synced yet */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* Modseqs aren't permanent (index is in memory) */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* always set */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen struct mailbox_transaction_context *transaction;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int has_nuls:1; /* message data is known to contain NULs */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen unsigned int has_no_nuls:1; /* -''- known to not contain NULs */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* "* OK <text>" */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void (*notify_ok)(struct mailbox *mailbox, const char *text,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen /* "* NO <text>" */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen void (*notify_no)(struct mailbox *mailbox, const char *text,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainentypedef void mailbox_notify_callback_t(struct mailbox *box, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* register all mail storages */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Register mail storage class with given name - all methods that are NULL
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen are set to default methods */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_class_register(struct mail_storage *storage_class);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_class_unregister(struct mail_storage *storage_class);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Returns flags and lock_method based on environment settings. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_parse_env(enum mail_storage_flags *flags_r,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Create a new instance of registered mail storage class with given
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen storage-specific data. If driver is NULL, it's tried to be autodetected
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen from data. If data is NULL, it uses the first storage that exists.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen The storage is put into ns->storage. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_create(struct mail_namespace *ns, const char *driver,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *data, enum mail_storage_flags flags,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char **error_r);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenvoid mail_storage_destroy(struct mail_storage **storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenchar mail_storage_get_hierarchy_sep(struct mail_storage *storage);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_get_list(const struct mail_storage *storage) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenmail_storage_get_namespace(const struct mail_storage *storage) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Set storage callback functions to use. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenvoid mail_storage_set_callbacks(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* name is allowed to contain multiple new hierarchy levels.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen If directory is TRUE, the mailbox should be created so that it
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen can contain children. The mailbox itself doesn't have to be
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen created as long as it shows in LIST. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mail_storage_mailbox_create(struct mail_storage *storage, const char *name,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns the error message of last occurred error. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_last_error(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the given mailbox, or NULL if mailbox doesn't exist in
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen filesystem. is_file_r is set to TRUE if returned path points to a file,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen and FALSE if it points to a directory. If name is "", the root storage
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen directory is returned. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_path(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the control directory of the mailbox, or NULL if mailbox
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen doesn't exist in filesystem. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_control_dir(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *name);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns path to the index directory of the mailbox, or NULL if using
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen in-memory indexes or mailbox doesn't exist. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mail_storage_get_mailbox_index_dir(struct mail_storage *storage,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen const char *name);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Open a mailbox. If input stream is given, mailbox is opened read-only
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen using it as a backend. If storage doesn't support stream backends and its
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen tried to be used, NULL is returned.
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen Note that append and copy may open the selected mailbox again
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen with possibly different readonly-state. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mailbox *mailbox_open(struct mail_storage *storage, const char *name,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Close the box. Returns -1 if some cleanup errors occurred, but
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen the mailbox was closed anyway. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Enable the given feature for the mailbox. */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenint mailbox_enable(struct mailbox *box, enum mailbox_feature features);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenenum mailbox_feature mailbox_get_enabled_features(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns storage of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenstruct mail_storage *mailbox_get_storage(const struct mailbox *box) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns name of given mailbox */
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenconst char *mailbox_get_name(const struct mailbox *box) ATTR_PURE;
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Returns TRUE if mailbox is read-only. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns TRUE if mailbox currently supports adding keywords. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_allow_new_keywords(struct mailbox *box);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen/* Gets the mailbox status information. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_get_status(struct mailbox *box, enum mailbox_status_items items,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Synchronize the mailbox. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainenbool mailbox_sync_next(struct mailbox_sync_context *ctx,
b71f152acb8a197d20b709ca74366e6d765bd200Timo Sirainenint mailbox_sync_deinit(struct mailbox_sync_context **ctx,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* One-step mailbox synchronization. Use this if you don't care about
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_sync(struct mailbox *box, enum mailbox_sync_flags flags,
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen/* Call given callback function when something changes in the mailbox. */
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainenvoid mailbox_notify_changes(struct mailbox *box, unsigned int min_interval,
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen mailbox_notify_callback_t *callback, void *context);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen ({(void)(1 ? 0 : callback((struct mailbox *)NULL, context)); \
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen (mailbox_notify_callback_t *)callback, context); })
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen# define mailbox_notify_changes(box, min_interval, callback, context) \
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (mailbox_notify_callback_t *)callback, context)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_notify_changes_stop(struct mailbox *box);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_transaction_commit(struct mailbox_transaction_context **t);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* If no messages were saved/copied, first/last_saved_uid_r are 0. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_transaction_commit_get_uids(struct mailbox_transaction_context **t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_transaction_rollback(struct mailbox_transaction_context **t);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Return the number of active transactions for the mailbox. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenunsigned int mailbox_transaction_get_count(const struct mailbox *box) ATTR_PURE;
47f1c273dfaea552c034ffbecdec096f7cbaef35Timo Sirainen/* When committing transaction, drop flag/keyword updates for messages whose
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen mdoseq is larger than max_modseq. Save those messages' sequences to the
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen given array. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Build mail_keywords from NULL-terminated keywords list.
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen Returns 0 if successful, -1 if there are invalid keywords (error is set). */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_keywords_create(struct mailbox *box, const char *const keywords[],
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Like mailbox_keywords_create(), except ignore invalid keywords. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_keywords_create_valid(struct mailbox *box,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const char *const keywords[]);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_keywords_free(struct mailbox *box,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Returns TRUE if keyword is valid, FALSE and error if not. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenbool mailbox_keyword_is_valid(struct mailbox *box, const char *keyword,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen const char **error_r);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Convert uid range to sequence range. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_get_seq_range(struct mailbox *box, uint32_t uid1, uint32_t uid2,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Convert sequence range to uid range. If sequences contain
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (uint32_t)-1 to specify "*", they're preserved. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenvoid mailbox_get_uid_range(struct mailbox *box,
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen/* Get list of UIDs expunged after modseq and within the given range.
199d62c0ddfb3c7d634c6940c29869ef56cfd3c4Timo Sirainen UIDs that have been expunged after the last mailbox sync aren't returned.
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen Returns TRUE if ok, FALSE if modseq is lower than we can check for. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenbool mailbox_get_expunged_uids(struct mailbox *box, uint64_t modseq,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Initialize header lookup for given headers. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_header_lookup_init(struct mailbox *box, const char *const headers[]);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Initialize new search request. charset specifies the character set used in
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen the search argument strings. If sort_program is non-NULL, the messages are
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen returned in the requested order, otherwise from first to last. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenmailbox_search_init(struct mailbox_transaction_context *t,
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainen/* Deinitialize search request. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_search_deinit(struct mail_search_context **ctx);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen/* Search the next message. Returns 1 if found, 0 if not, -1 if failure. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenint mailbox_search_next(struct mail_search_context *ctx, struct mail *mail);
f096367f0f7b0e481f8abe0969afdf2d8250057eTimo Sirainen/* Like mailbox_search_next(), but don't spend too much time searching.
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen Returns 1 if found, -1 if failure or 0 with tryagain_r=FALSE if
3b1bb5fd562be9d1a5f6894b82d2ba0d529cdcb3Timo Sirainen finished, and TRUE if more results will by calling the function again. */
442232f2d1cfdf28f3a18aa00a5c19246d321036Timo Sirainenint mailbox_search_next_nonblock(struct mail_search_context *ctx,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Remember the search result for future use. This must be called before the
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen first mailbox_search_next*() call. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenmailbox_search_result_save(struct mail_search_context *ctx,
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* Free memory used by search result. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenvoid mailbox_search_result_free(struct mail_search_result **result);
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainen/* A simplified API for searching and saving the result. */
4e56e6408815c04f2e5b904a648a366a2dcbd408Timo Sirainenint mailbox_search_result_build(struct mailbox_transaction_context *t,
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen/* Return all messages' UIDs in the search result. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenmailbox_search_result_get(struct mail_search_result *result);
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen/* Return messages that have been removed and added since the last sync call.
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen This function must not be called if search result wasn't saved with
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainen _QUEUE_SYNC flag. */
7891c8e6debdcfec552cb1beea2a0230fe89957bTimo Sirainenvoid mailbox_search_result_sync(struct mail_search_result *result,
struct mail_save_context *
const char *envelope);
const char **value_r);
const char **value_r);
const char *const **value_r);
const char *const **value_r);
const char **value_r);