bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenistream_attachment_connector_begin(struct istream *base_input, uoff_t msg_size)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen pool = pool_alloconly_create("istream-attachment-connector", 1024);
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen conn = p_new(pool, struct istream_attachment_connector, 1);
f5f8bd05b524864d0ae678cd7d08e60b0e277feeTimo Sirainen conn->base_input_offset = base_input->v_offset;
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenint istream_attachment_connector_add(struct istream_attachment_connector *conn,
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen const char **error_r)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen "Attachment %s points before the previous attachment "
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen base_prefix_size = start_offset - conn->encoded_offset;
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen if (start_offset + encoded_size > conn->msg_size) {
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen "Attachment %s points outside message "
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen "(%"PRIuUOFF_T" + %"PRIuUOFF_T" > %"PRIuUOFF_T")",
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen /* add a part of the base message before the attachment */
24d6fd2b8e2c327ae2a20a0c4be8af2ef7b3b468Timo Sirainen input = i_stream_create_min_sized_range(conn->base_input,
24d6fd2b8e2c327ae2a20a0c4be8af2ef7b3b468Timo Sirainen i_stream_set_name(input, t_strdup_printf("%s middle",
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen input = i_stream_create_base64_encoder(decoded_input,
08997487a0de72a0e77ff73d54e0ae228f1d5908Timo Sirainen i_stream_set_name(input, t_strdup_printf("%s[base64:%u b/l%s]",
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen input2 = i_stream_create_sized(input, encoded_size);
96b8965a967dcaef1316f4f32d5cd956d844201bTimo Sirainenistream_attachment_connector_free(struct istream_attachment_connector *conn)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenistream_attachment_connector_finish(struct istream_attachment_connector **_conn)
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen struct istream_attachment_connector *conn = *_conn;
f5f8bd05b524864d0ae678cd7d08e60b0e277feeTimo Sirainen if (conn->base_input_offset != conn->msg_size) {
f5f8bd05b524864d0ae678cd7d08e60b0e277feeTimo Sirainen i_assert(conn->base_input_offset < conn->msg_size);
075081e25ef07989be10f7c9cf85f833f90be46fTimo Sirainen trailer_size = conn->msg_size - conn->encoded_offset;
075081e25ef07989be10f7c9cf85f833f90be46fTimo Sirainen input = i_stream_create_sized_range(conn->base_input,
075081e25ef07989be10f7c9cf85f833f90be46fTimo Sirainen "%s trailer", i_stream_get_name(conn->base_input)));
075081e25ef07989be10f7c9cf85f833f90be46fTimo Sirainen input = i_stream_create_range(conn->base_input,
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainen inputs = array_idx_modifiable(&conn->streams, 0);
8aeae03f9f447c8a792b215c9fb954468053c556Timo Sirainenvoid istream_attachment_connector_abort(struct istream_attachment_connector **_conn)