struct message_size body_size;
if (boundaries == NULL) {
- message_get_body_size(input, &body_size,
- (uoff_t)-1, NULL, has_nuls);
+ message_get_body_size(input, &body_size, has_nuls);
message_size_add(msg_size, &body_size);
boundary = NULL;
} else {
}
void message_get_body_size(struct istream *input, struct message_size *body,
- uoff_t max_virtual_size, int *last_cr, int *has_nuls)
+ int *has_nuls)
{
const unsigned char *msg;
- size_t i, size, startpos, missing_cr_count;
- int cr;
+ size_t i, size, missing_cr_count;
+ int last_cr;
memset(body, 0, sizeof(struct message_size));
if (has_nuls != NULL)
*has_nuls = FALSE;
- cr = 0;
- missing_cr_count = 0; startpos = 0;
- while (max_virtual_size != 0 &&
- i_stream_read_data(input, &msg, &size, startpos) > 0) {
- cr = 0;
- for (i = startpos; i < size && max_virtual_size > 0; i++) {
- max_virtual_size--;
+ missing_cr_count = 0; last_cr = FALSE;
+ if (i_stream_read_data(input, &msg, &size, 0) <= 0)
+ return;
- if (msg[i] == '\0') {
- if (has_nuls != NULL)
- *has_nuls = TRUE;
- } else if (msg[i] == '\n') {
- if (i == 0 || msg[i-1] != '\r') {
- /* missing CR */
- missing_cr_count++;
+ if (msg[0] == '\n')
+ missing_cr_count++;
- if (max_virtual_size == 0) {
- cr = 2;
- break;
- }
+ do {
+ for (i = 1; i < size; i++) {
+ if (msg[i] > '\n')
+ continue;
- max_virtual_size--;
+ if (msg[i] == '\n') {
+ if (msg[i-1] != '\r') {
+ /* missing CR */
+ missing_cr_count++;
}
/* increase after making sure we didn't break
at virtual \r */
body->lines++;
+ } else if (msg[i] == '\0') {
+ if (has_nuls != NULL)
+ *has_nuls = TRUE;
}
}
- if (cr == 0 && i > 0 && msg[i-1] == '\r')
- cr = 1;
-
/* leave the last character, it may be \r */
i_stream_skip(input, i - 1);
- startpos = 1;
-
body->physical_size += i - 1;
- }
- i_stream_skip(input, startpos);
- body->physical_size += startpos;
+ } while (i_stream_read_data(input, &msg, &size, 1) > 0);
+
+ i_stream_skip(input, 1);
+ body->physical_size++;
body->virtual_size = body->physical_size + missing_cr_count;
i_assert(body->virtual_size >= body->physical_size);
-
- if (last_cr != NULL)
- *last_cr = cr;
}
void message_size_add(struct message_size *dest,
character in body. */
void message_get_header_size(struct istream *input, struct message_size *hdr,
int *has_nuls);
-/* Calculate size of message body. Read only max_virtual_size virtual bytes,
- if you want it unlimited, use (uoff_t)-1. If last_cr is not NULL, it's set
- to 1 if last character is CR, 2 if it's virtual CR. */
+/* Calculate size of message body. */
void message_get_body_size(struct istream *input, struct message_size *body,
- uoff_t max_virtual_size, int *last_cr,
int *has_nuls);
/* Sum contents of src into dest. */
data->hdr_size_set = TRUE;
}
if (body_size == (uoff_t)-1) {
- message_get_body_size(data->stream, &data->body_size,
- (uoff_t)-1, NULL, NULL);
+ message_get_body_size(data->stream, &data->body_size, NULL);
body_size = data->body_size.virtual_size;
data->body_size_set = TRUE;
}
data->hdr_size.physical_size);
message_get_body_size(data->stream, &data->body_size,
- (uoff_t)-1, NULL, NULL);
+ NULL);
data->body_size_set = TRUE;
}