message-send.c revision 907035872354e895a0c4431e1e42cd21d456f3ea
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenint message_send(OStream *output, IStream *input, MessageSize *msg_size,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen const unsigned char *msg;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if (max_virtual_size > msg_size->virtual_size - virtual_skip)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen max_virtual_size = msg_size->virtual_size - virtual_skip;
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen if (msg_size->physical_size == msg_size->virtual_size) {
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen /* no need to kludge with CRs, we can use sendfile() */
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen i_stream_set_read_limit(input, I_MIN(limit, old_limit));
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen ret = o_stream_send_istream(output, input) > 0;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen message_skip_virtual(input, virtual_skip, NULL, &cr_skipped);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen /* go through the message data and insert CRs where needed. */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen i_stream_read_data(input, &msg, &size, 0) > 0) {
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen for (i = 0; i < size && max_virtual_size > 0; i++) {
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if ((i == 0 && !cr_skipped) ||
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen /* missing CR */