61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen#ifndef MAILBOX_LIST_DELETE_H
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen#define MAILBOX_LIST_DELETE_H
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen
a8fe899601735459641edae975c0fa08be8482e2Timo Sirainen#include "mailbox-list.h"
ae1a57954535642c09c3b8aee184736ddbb06cdfTimo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* Delete the mailbox atomically by rename()ing it to trash_dir and afterwards
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen recursively deleting the trash_dir. If the rename() fails because trash_dir
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen already exists, the trash_dir is first deleted and rename() is retried.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns 1 if the rename() succeeded. Returns 0 if rename() fails with EXDEV,
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen which means the source and destination are on different filesystems and
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen the rename can never succeeed.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen If the path didn't exist, returns -1 and sets the list error to
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen MAIL_ERROR_NOTFOUND.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Attempting to delete INBOX or the namespace root returns -1 and sets the
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen list error to MAIL_ERROR_NOTPOSSIBLE.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns -1 and sets the list error on other errors. */
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenint mailbox_list_delete_maildir_via_trash(struct mailbox_list *list,
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen const char *name,
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen const char *trash_dir);
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* Try to unlink() the path. Returns 0 on success. If the path didn't exist,
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen returns -1 and sets the list error to MAIL_ERROR_NOTFOUND.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns -1 and sets the list error on other errors. */
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenint mailbox_list_delete_mailbox_file(struct mailbox_list *list,
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen const char *name, const char *path);
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* Delete all files from the given path. Also all internal directories
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen (as returned by is_internal_name() check) are recursively deleted.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Otherwise directories are left undeleted.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns 0 if anything was unlink()ed and no unexpected errors happened.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Also returns 0 if there were no files and the path was successfully
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen rmdir()ed.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen If the path didn't exist, returns -1 and sets the list error to
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen MAIL_ERROR_NOTFOUND.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen If the path exists and has subdirectories, but no files were unlink()ed,
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen returns -1 and sets the list error to MAIL_ERROR_NOTPOSSIBLE.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Attempting to delete INBOX or the namespace root returns -1 and sets the
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen list error to MAIL_ERROR_NOTPOSSIBLE.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns -1 and sets the list error on other errors. */
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainenint mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list,
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen const char *name, const char *path,
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen bool rmdir_path);
a1bef9db6db683360e6e7be59a7f9e9718cf6ff5Timo Sirainen/* Lookup INDEX, CONTROL and ALT directories for the mailbox and delete them.
a1bef9db6db683360e6e7be59a7f9e9718cf6ff5Timo Sirainen Returns 1 if anything was unlink()ed or rmdir()ed, 0 if not.
a1bef9db6db683360e6e7be59a7f9e9718cf6ff5Timo Sirainen Returns -1 and sets the list error on any errors. */
a1bef9db6db683360e6e7be59a7f9e9718cf6ff5Timo Sirainenint mailbox_list_delete_finish(struct mailbox_list *list, const char *name);
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen/* Finish mailbox deletion by calling mailbox_list_delete_finish() if needed.
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen Set root_delete_success to TRUE if the mail root directory was successfully
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen deleted, FALSE if not. The list is expected to have a proper error when
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen root_delete_success==FALSE.
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen Returns 0 if mailbox deletion should be treated as success. If not, returns
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen -1 and sets the list error if necessary. */
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainenint mailbox_list_delete_finish_ret(struct mailbox_list *list,
12bd6ddfeb75d81ccc09bf34b374b0637dfe890fTimo Sirainen const char *name, bool root_delete_success);
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* rmdir() path and its parent directories until the root directory is reached.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen The root isn't rmdir()ed. */
ae1a57954535642c09c3b8aee184736ddbb06cdfTimo Sirainenvoid mailbox_list_delete_until_root(struct mailbox_list *list, const char *path,
ae1a57954535642c09c3b8aee184736ddbb06cdfTimo Sirainen enum mailbox_list_path_type type);
d823c19df414cac96c7f50a6f78a13fd03bcb27eTimo Sirainen/* Call mailbox_list_delete_until_root() for all the paths of the mailbox. */
d823c19df414cac96c7f50a6f78a13fd03bcb27eTimo Sirainenvoid mailbox_list_delete_mailbox_until_root(struct mailbox_list *list,
d823c19df414cac96c7f50a6f78a13fd03bcb27eTimo Sirainen const char *storage_name);
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* Wrapper to unlink_directory(UNLINK_DIRECTORY_FLAG_RMDIR). If it fails due
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen to ELOOP, try to unlink() the path instead. */
97e511960951550338d69cac98fb5f3ca2badb09Timo Sirainenint mailbox_list_delete_trash(const char *path, const char **error_r);
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen/* Try to unlink() the path to the mailbox. Returns 0 on success.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen If the path didn't exist, returns -1 and sets the list error to
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen MAIL_ERROR_NOTFOUND.
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen If the path is a directory, returns -1 and sets the list error to
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen MAIL_ERROR_NOTPOSSIBLE.
ae1a57954535642c09c3b8aee184736ddbb06cdfTimo Sirainen
0877bd89b43d59c0e0257eb08305b22866ec21d5Timo Sirainen Returns -1 and sets the list error on other errors. */
0b25846ba794ce19536a24d4065beaf2a0bd9464Timo Sirainenint mailbox_list_delete_symlink_default(struct mailbox_list *list,
0b25846ba794ce19536a24d4065beaf2a0bd9464Timo Sirainen const char *name);
0b25846ba794ce19536a24d4065beaf2a0bd9464Timo Sirainen
61b0637759146621cbb7edcbd0b03a71cfd66dfeTimo Sirainen#endif