const void *data;
size_t data_size;
uoff_t start_offset, send_size;
- int failed;
+ int failed, skip_cr;
/* HEADER, MIME, HEADER.FIELDS (list), HEADER.FIELDS.NOT (list) */
ctx->prefix, send_size);
if (o_stream_send_str(ctx->output, str) < 0)
return FALSE;
+
+ skip_cr = seek_partial(ctx->select_counter, mail->uid,
+ &partial, input, 0, body->skip);
+
return message_send(ctx->output, input, size,
- body->skip, send_size, NULL,
+ skip_cr, send_size, NULL,
!mail->has_no_nuls) >= 0;
}
off_t message_send(struct ostream *output, struct istream *input,
const struct message_size *msg_size,
- uoff_t virtual_skip, uoff_t max_virtual_size, int *last_cr,
+ int cr_skipped, uoff_t max_virtual_size, int *last_cr,
int fix_nuls)
{
const unsigned char *msg;
- uoff_t old_limit, limit;
size_t i, size;
off_t ret;
- int cr_skipped;
unsigned char add;
if (last_cr != NULL)
*last_cr = -1;
- if (msg_size->physical_size == 0 ||
- virtual_skip >= msg_size->virtual_size)
+ if (msg_size->physical_size == 0)
return 0;
- if (max_virtual_size > msg_size->virtual_size - virtual_skip)
- max_virtual_size = msg_size->virtual_size - virtual_skip;
-
if (msg_size->physical_size == msg_size->virtual_size && !fix_nuls) {
/* no need to kludge with CRs, we can use sendfile() */
- i_stream_skip(input, virtual_skip);
-
- old_limit = input->v_limit;
- limit = input->v_offset + max_virtual_size;
- i_stream_set_read_limit(input, I_MIN(limit, old_limit));
+ input = i_stream_create_limit(default_pool, input,
+ input->v_offset,
+ max_virtual_size);
ret = o_stream_send_istream(output, input);
- i_stream_set_read_limit(input, old_limit);
-
+ i_stream_unref(input);
return ret;
}
- message_skip_virtual(input, virtual_skip, NULL, 0, &cr_skipped);
-
/* go through the message data and insert CRs where needed. */
ret = 0;
while (max_virtual_size > 0 &&
max_virtual_size--;
if (msg[i] == '\n') {
- if ((i == 0 && !cr_skipped) ||
- (i > 0 && msg[i-1] != '\r')) {
+ if ((i > 0 && msg[i-1] != '\r') ||
+ (i == 0 && !cr_skipped)) {
/* missing CR */
add = '\r';
break;
struct message_size;
/* Send message to client inserting CRs if needed. Only max_virtual_size
- bytes if sent (relative to virtual_skip), if you want it unlimited,
- use (uoff_t)-1. Remember that if input begins with LF, CR is inserted
- before it unless virtual_skip = 1. last_cr is set to 1, 0 or -1 if not
- known. Returns number of bytes sent, or -1 if error. */
+ bytes are sent. If cr_skipped is FALSE and input begins with LF, it's
+ treated as CRLF. last_cr is set to 1, 0 or -1 if not known. Returns number
+ of bytes sent, or -1 if error. */
off_t message_send(struct ostream *output, struct istream *input,
const struct message_size *msg_size,
- uoff_t virtual_skip, uoff_t max_virtual_size, int *last_cr,
+ int cr_skipped, uoff_t max_virtual_size, int *last_cr,
int fix_nuls);
/* Skip number of virtual bytes from putfer. msg_size is updated if it's not