if (conn->base_input_offset != conn->msg_size) {
i_assert(conn->base_input_offset < conn->msg_size);
- trailer_size = conn->msg_size - conn->encoded_offset;
- input = i_stream_create_sized_range(conn->base_input,
- conn->base_input_offset,
- trailer_size);
- i_stream_set_name(input, t_strdup_printf(
- "%s trailer", i_stream_get_name(conn->base_input)));
+ if (conn->msg_size != (uoff_t)-1) {
+ trailer_size = conn->msg_size - conn->encoded_offset;
+ input = i_stream_create_sized_range(conn->base_input,
+ conn->base_input_offset,
+ trailer_size);
+ i_stream_set_name(input, t_strdup_printf(
+ "%s trailer", i_stream_get_name(conn->base_input)));
+ } else {
+ input = i_stream_create_range(conn->base_input,
+ conn->base_input_offset,
+ (uoff_t)-1);
+ }
array_append(&conn->streams, &input, 1);
}
array_append_zero(&conn->streams);
#define ISTREAM_ATTACHMENT_CONNECTOR_H
/* Start building a message stream. The base_input contains the message
- without attachments. The final stream must be exactly msg_size bytes. */
+ without attachments. The final stream must be exactly msg_size bytes.
+ If the original msg_size isn't known, it can be set to (uoff_t)-1. */
struct istream_attachment_connector *
istream_attachment_connector_begin(struct istream *base_input, uoff_t msg_size);
const unsigned char *data;
size_t size;
struct sha1_ctxt hash;
- uoff_t msg_size;
+ uoff_t msg_size, orig_msg_size;
buffer_t *base_buf;
unsigned char hash_file[SHA1_RESULTLEN], hash_attached[SHA1_RESULTLEN];
int ret = 0;
i_stream_skip(input, size);
}
sha1_result(&hash, hash_file);
- msg_size = input->v_offset;
+ msg_size = orig_msg_size = input->v_offset;
i_stream_unref(&input);
/* read through attachment extractor */
i_stream_unref(&input2);
/* rebuild the original stream and see if the hash matches */
- {
+ for (unsigned int i = 0; i < 2; i++) {
input2 = i_stream_create_from_data(base_buf->data, base_buf->used);
input = test_build_original_istream(input2, msg_size);
i_stream_unref(&input2);
sha1_loop(&hash, data, size);
i_stream_skip(input, size);
}
- test_assert(input->eof && input->stream_errno == 0);
+ test_assert_idx(input->eof && input->stream_errno == 0, i);
sha1_result(&hash, hash_attached);
i_stream_unref(&input);
if (memcmp(hash_file, hash_attached, SHA1_RESULTLEN) != 0)
ret = -1;
+
+ /* try again without knowing the message's size */
+ msg_size = (uoff_t)-1;
}
/* try with a wrong message size */
for (int i = 0; i < 2; i++) {
input2 = i_stream_create_from_data(base_buf->data, base_buf->used);
- input = test_build_original_istream(input2, msg_size +
+ input = test_build_original_istream(input2, orig_msg_size +
(i == 0 ? 1 : -1));
i_stream_unref(&input2);
while (i_stream_read_more(input, &data, &size) > 0)