dbox-attachment.c revision 4a962dccf2fee41bbfec0475c8dd4387d4608f37
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2010-2011 Dovecot authors, see the included COPYING file */
3ed2d0f6b5e67e2663d44489d9da3176823789a8Timo Sirainenvoid dbox_attachment_save_write_metadata(struct mail_save_context *ctx,
1a5573ebc32fae2fe576ec544e1781323c1db609Timo Sirainen const ARRAY_TYPE(mail_attachment_extref) *extrefs;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen extrefs = index_attachment_save_get_extrefs(ctx);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen if (extrefs == NULL || array_count(extrefs) == 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen str_printfa(str, "%"PRIuUOFF_T" %"PRIuUOFF_T" ",
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen str_append_c(str, DBOX_ATTACHMENT_DECODE_OPTION_CRLF);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen /* make it clear there are no options */
3e564425db51f3921ce4de11859777135fdedd15Timo Sirainen str_append_c(str, DBOX_ATTACHMENT_DECODE_OPTION_NONE);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int num;
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen if (*str == DBOX_ATTACHMENT_DECODE_OPTION_NONE)
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainendbox_attachment_parse_extref_real(const char *line, pool_t pool,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen const char *const *args;
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen unsigned int i, len;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen if (str_to_uoff(start_offset_str, &extref.start_offset) < 0 ||
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen !parse_extref_decode_options(decode_options, &extref))
7900eb30bac4a46b259522c58362884661483d7cJosef 'Jeff' Sipekbool dbox_attachment_parse_extref(const char *line, pool_t pool,
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen ret = dbox_attachment_parse_extref_real(line, pool, extrefs);
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainendbox_attachment_file_get_stream_from(struct dbox_file *file,
8d630c15a8ed6f85553467c3a231a273defca5f6Timo Sirainen const char **error_r)
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainen ARRAY_TYPE(mail_attachment_extref) extrefs_arr;
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen unsigned int i;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (!dbox_attachment_parse_extref_real(ext_refs, pool_datastack_create(),
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen path_suffix = file->storage->v.get_attachment_path_suffix(file);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen path = t_strdup_printf("%s/%s%s", file->storage->attachment_dir,
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen uoff_t part_size = extref->start_offset - last_voffset;
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen if ((*stream)->v_offset + part_size > psize) {
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen "ext-refs point outside message "
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen "(%"PRIuUOFF_T" + %"PRIuUOFF_T" > %"PRIuUOFF_T")",
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen input = i_stream_create_limit(*stream, part_size);
aa41b2e17912d6cad3151babea6a85dd88539d28Timo Sirainen i_stream_seek(*stream, (*stream)->v_offset + part_size);
cff1f182205e674285cf3ff446a0dcf7afea277dTimo Sirainen input2 = i_stream_create_file(path, IO_BLOCK_SIZE);
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen input = i_stream_create_base64_encoder(input2,
f318b3dbe2acc177b8ee1c160e4b5b14e7f2cd41Timo Sirainen input = i_stream_create_attachment(input2, extref->size);
6469cf211a57433335641725dc236ebb2b9fdd3bTimo Sirainen "ext-refs point outside message "
bd6a8056771b6150685dea319ab5a94e021d17f1Josef 'Jeff' Sipek input = i_stream_create_limit(*stream, trailer_size);
c0d069950af1dbc6a4e5c3de3bf2e437796e3ae0Timo Sirainenint dbox_attachment_file_get_stream(struct dbox_file *file,
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen /* need to read metadata in case there are external references */
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen if ((ret = dbox_file_metadata_read(file)) <= 0)
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen i_stream_seek(file->input, file->cur_offset + file->msg_header_size);
d756ebcfa96bd7cff02097c8f26df9df368b81b1Timo Sirainen ext_refs = dbox_file_metadata_get(file, DBOX_METADATA_EXT_REF);
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen /* we have external references. */
5137d2d80255938a0f5fb8f3c1a21b34cf11ada3Timo Sirainen ret = dbox_attachment_file_get_stream_from(file, ext_refs,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen "Corrupted ext-refs metadata %s: %s",