bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenvoid dbox_attachment_save_write_metadata(struct mail_save_context *ctx,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen const ARRAY_TYPE(mail_attachment_extref) *extrefs;
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen extrefs = index_attachment_save_get_extrefs(ctx);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen if (extrefs == NULL || array_count(extrefs) == 0)
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen index_attachment_append_extrefs(str, extrefs);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainendbox_attachment_file_get_stream_from(struct dbox_file *file,
7d73c8f29360df6f1705c0f6670b9030632772f6Timo Sirainen const char **error_r)
66a1eb655401702405cd8adc23142efe7a1dd9a5Timo Sirainen mail_storage_set_critical(&file->storage->storage,
66a1eb655401702405cd8adc23142efe7a1dd9a5Timo Sirainen "%s contains references to external attachments, "
66a1eb655401702405cd8adc23142efe7a1dd9a5Timo Sirainen "but mail_attachment_dir is unset", file->cur_path);
338088fe2875e8039d2b3df32cbd7a8396b24ea6Timo Sirainen msg_size = dbox_file_get_plaintext_size(file);
338088fe2875e8039d2b3df32cbd7a8396b24ea6Timo Sirainen path_suffix = file->storage->v.get_attachment_path_suffix(file);
52de839a8249bff5eace53dc1401b28baa0c124bTimo Sirainen if (index_attachment_stream_get(file->storage->attachment_fs,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainenint dbox_attachment_file_get_stream(struct dbox_file *file,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* need to read metadata in case there are external references */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen if ((ret = dbox_file_metadata_read(file)) <= 0)
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen i_stream_seek(file->input, file->cur_offset + file->msg_header_size);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen ext_refs = dbox_file_metadata_get(file, DBOX_METADATA_EXT_REF);
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen /* we have external references. */
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen ret = dbox_attachment_file_get_stream_from(file, ext_refs,
7d73c8f29360df6f1705c0f6670b9030632772f6Timo Sirainen "Corrupted ext-refs metadata %s: %s",