Lines Matching defs:astream

64 static void stream_add_data(struct attachment_istream *astream,
68 memcpy(i_stream_alloc(&astream->istream, size), data, size);
69 astream->istream.pos += size;
73 static void parse_content_type(struct attachment_istream *astream,
79 if (astream->part.content_type != NULL)
88 astream->part.content_type = i_strdup(str_c(content_type));
93 parse_content_disposition(struct attachment_istream *astream,
97 i_free(astream->part.content_disposition);
98 astream->part.content_disposition =
102 static void astream_parse_header(struct attachment_istream *astream,
106 stream_add_data(astream, hdr->name, hdr->name_len);
107 stream_add_data(astream, hdr->middle, hdr->middle_len);
109 stream_add_data(astream, hdr->value, hdr->value_len);
112 stream_add_data(astream, "\r\n", 2);
114 stream_add_data(astream, "\n", 1);
123 parse_content_type(astream, hdr);
125 parse_content_disposition(astream, hdr);
128 static bool astream_want_attachment(struct attachment_istream *astream,
138 if (astream->set.want_attachment == NULL)
143 ahdr.content_type = astream->part.content_type;
144 ahdr.content_disposition = astream->part.content_disposition;
145 return astream->set.want_attachment(&ahdr, astream->context);
272 static int astream_open_output(struct attachment_istream *astream)
276 i_assert(astream->part.temp_fd == -1);
278 fd = astream->set.open_temp_fd(astream->context);
282 astream->part.temp_fd = fd;
283 astream->part.temp_output = o_stream_create_fd(fd, 0);
284 o_stream_cork(astream->part.temp_output);
288 static void astream_add_body(struct attachment_istream *astream,
291 struct attachment_istream_part *part = &astream->part;
297 stream_add_data(astream, block->data, block->size);
305 astream->set.min_size);
309 if (new_size < astream->set.min_size) {
315 if (astream_open_output(astream) < 0) {
318 stream_add_data(astream, part_buf->data, part_buf->used);
319 stream_add_data(astream, block->data, block->size);
324 hash_format_loop(astream->set.hash_format,
332 hash_format_loop(astream->set.hash_format,
339 static int astream_decode_base64(struct attachment_istream *astream,
342 struct attachment_istream_part *part = &astream->part;
354 if (part->base64_bytes < astream->set.min_size ||
368 outfd = astream->set.open_temp_fd(astream->context);
378 hash_format_reset(astream->set.hash_format);
391 hash_format_loop(astream->set.hash_format,
443 astream_part_finish(struct attachment_istream *astream, const char **error_r)
445 struct attachment_istream_part *part = &astream->part;
463 info.start_offset = astream->part.start_offset;
471 hash_format_write(astream->set.hash_format, digest_str);
485 if (astream_decode_base64(astream, &extra_buf) < 0)
493 info.part = astream->cur_part;
499 hash_format_write(astream->set.hash_format, digest_str);
506 if (astream->set.open_attachment_ostream(&info, &output, error_r,
507 astream->context) < 0) {
526 if (astream->set.close_attachment_ostream(output, ret == 0, error_r,
527 astream->context) < 0)
530 stream_add_data(astream, extra_buf->data, extra_buf->used);
535 static void astream_part_reset(struct attachment_istream *astream)
537 struct attachment_istream_part *part = &astream->part;
548 hash_format_reset(astream->set.hash_format);
552 astream_end_of_part(struct attachment_istream *astream, const char **error_r)
554 struct attachment_istream_part *part = &astream->part;
566 stream_add_data(astream, part->part_buf->data,
572 old_size = astream->istream.pos - astream->istream.skip;
573 if (astream_part_finish(astream, error_r) < 0)
578 ret = astream->istream.pos -
579 astream->istream.skip - old_size;
584 astream_part_reset(astream);
588 static int astream_read_next(struct attachment_istream *astream, bool *retry_r)
590 struct istream_private *stream = &astream->istream;
602 switch (message_parser_parse_next_block(astream->parser, &block)) {
605 ret = astream_end_of_part(astream, &error);
618 astream->cur_part = NULL;
627 if (block.part != astream->cur_part && astream->cur_part != NULL) {
629 if (astream_end_of_part(astream, &error) < 0) {
635 astream->cur_part = block.part;
639 astream_parse_header(astream, block.hdr);
642 if (astream_want_attachment(astream, block.part)) {
643 astream->part.state = MAIL_ATTACHMENT_STATE_MAYBE;
644 astream->part.start_offset = stream->parent->v_offset;
647 astream_add_body(astream, &block);
657 struct attachment_istream *astream =
663 ret = astream_read_next(astream, &retry);
664 } while (retry && astream->set.drain_parent_input);
666 astream->retry_read = retry;
673 struct attachment_istream *astream =
677 if (astream->parser != NULL) {
678 message_parser_deinit(&astream->parser, &parts);
680 hash_format_deinit_free(&astream->set.hash_format);
681 pool_unref(&astream->pool);
683 i_stream_close(astream->istream.parent);
691 struct attachment_istream *astream;
698 astream = i_new(struct attachment_istream, 1);
699 astream->part.temp_fd = -1;
700 astream->set = *set;
701 astream->context = context;
702 astream->retry_read = TRUE;
707 astream->istream.max_buffer_size = input->real_stream->max_buffer_size;
709 astream->istream.read = i_stream_attachment_extractor_read;
710 astream->istream.iostream.close = i_stream_attachment_extractor_close;
712 astream->istream.istream.readable_fd = FALSE;
713 astream->istream.istream.blocking = input->blocking;
714 astream->istream.istream.seekable = FALSE;
716 astream->pool = pool_alloconly_create("istream attachment", 1024);
717 astream->parser = message_parser_init(astream->pool, input, 0,
720 return i_stream_create(&astream->istream, input,
726 struct attachment_istream *astream =
729 return astream->retry_read;