1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#ifndef SDBOX_FILE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define SDBOX_FILE_H
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "dbox-file.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct sdbox_file {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_file file;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct sdbox_mailbox *mbox;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* 0 while file is being created */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t uid;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* list of attachment paths while saving/copying message */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen pool_t attachment_pool;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen ARRAY_TYPE(const_string) attachment_paths;
cc0a651962a3e54d5a62231ac5847ae7f9f7de7fTimo Sirainen bool written_to_disk;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct dbox_file *sdbox_file_init(struct sdbox_mailbox *mbox, uint32_t uid);
e8762c2b4914db7997fa9eb644a91586952d1876Timo Sirainenstruct dbox_file *sdbox_file_create(struct sdbox_mailbox *mbox);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenvoid sdbox_file_free(struct dbox_file *file);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen/* Get file's extrefs metadata. */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint sdbox_file_get_attachments(struct dbox_file *file, const char **extrefs_r);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen/* Returns attachment path for this file, given the source path. The result is
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen always <hash>-<guid>-<mailbox_guid>-<uid>. The source path is expected to
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen contain <hash>-<guid>[-*]. */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenconst char *
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainensdbox_file_attachment_relpath(struct sdbox_file *file, const char *srcpath);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Assign UID for a newly created file (by renaming it) */
172b6edea36e425b0d0c35a854721ae63f57c289Timo Sirainenint sdbox_file_assign_uid(struct sdbox_file *file, uint32_t uid,
172b6edea36e425b0d0c35a854721ae63f57c289Timo Sirainen bool ignore_if_exists);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint sdbox_file_create_fd(struct dbox_file *file, const char *path,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool parents);
c2d2161296e2361f97ee48b70b168602157069e6Timo Sirainen/* Move the file to alt path or back. */
c2d2161296e2361f97ee48b70b168602157069e6Timo Sirainenint sdbox_file_move(struct dbox_file *file, bool alt_path);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen/* Unlink file and all of its referenced attachments. */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint sdbox_file_unlink_with_attachments(struct sdbox_file *sfile);
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi/* Unlink file and its attachments when rolling back a saved message. */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint sdbox_file_unlink_aborted_save(struct sdbox_file *file);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#endif