b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen#ifndef INDEX_ATTACHMENT_H
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen#define INDEX_ATTACHMENT_H
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen#include "sha1.h"
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct fs;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct mail_save_context;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct mail_storage;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenstruct mail_attachment_extref {
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* path without attachment_dir/ prefix */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const char *path;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* offset in input stream where part begins */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen uoff_t start_offset;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen uoff_t size;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* If non-zero, this attachment was saved as base64-decoded and it
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen need to be encoded back before presenting it to client. Each line
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen (except last one) consists of this many base64 blocks (4 chars of
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen base64 encoded data). */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen unsigned int base64_blocks_per_line;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* Line feeds are CRLF instead of LF */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen bool base64_have_crlf;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen};
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo SirainenARRAY_DEFINE_TYPE(mail_attachment_extref, struct mail_attachment_extref);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenvoid index_attachment_save_begin(struct mail_save_context *ctx,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct fs *fs, struct istream *input);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint index_attachment_save_continue(struct mail_save_context *ctx);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint index_attachment_save_finish(struct mail_save_context *ctx);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenvoid index_attachment_save_free(struct mail_save_context *ctx);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenconst ARRAY_TYPE(mail_attachment_extref) *
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenindex_attachment_save_get_extrefs(struct mail_save_context *ctx);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen/* Delete a given attachment name from storage
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen (name is same as mail_attachment_extref.name). */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint index_attachment_delete(struct mail_storage *storage,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen struct fs *fs, const char *name);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainenvoid index_attachment_append_extrefs(string_t *str,
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen const ARRAY_TYPE(mail_attachment_extref) *extrefs);
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen/* Parse extrefs value to given array. Names are allocated from the
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen given pool. */
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainenbool index_attachment_parse_extrefs(const char *line, pool_t pool,
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen ARRAY_TYPE(mail_attachment_extref) *extrefs);
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainenint index_attachment_stream_get(struct fs *fs, const char *attachment_dir,
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen const char *path_suffix,
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen struct istream **stream, uoff_t full_size,
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen const char *ext_refs, const char **error_r);
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen#endif