From: Timo Sirainen Date: Wed, 4 Jun 2003 23:00:44 +0000 (+0300) Subject: Removed useless parameters from message_get_body_size(). Also did some small X-Git-Tag: 1.1.alpha1~4563 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7834c4baef139975368433cb890e0d914412e61d;p=thirdparty%2Fdovecot%2Fcore.git Removed useless parameters from message_get_body_size(). Also did some small optimizations to it. --HG-- branch : HEAD --- diff --git a/src/lib-mail/message-parser.c b/src/lib-mail/message-parser.c index 90e5bb0b8c..cf57169168 100644 --- a/src/lib-mail/message-parser.c +++ b/src/lib-mail/message-parser.c @@ -486,8 +486,7 @@ message_parse_body(struct istream *input, struct message_boundary *boundaries, 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 { diff --git a/src/lib-mail/message-size.c b/src/lib-mail/message-size.c index 00c2766f74..63dcc63739 100644 --- a/src/lib-mail/message-size.c +++ b/src/lib-mail/message-size.c @@ -62,63 +62,53 @@ void message_get_header_size(struct istream *input, struct message_size *hdr, } 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, diff --git a/src/lib-mail/message-size.h b/src/lib-mail/message-size.h index 8b559a65ec..0ce3bc322f 100644 --- a/src/lib-mail/message-size.h +++ b/src/lib-mail/message-size.h @@ -11,11 +11,8 @@ struct message_size { 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. */ diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 3b56fd5908..fca46806d6 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -435,8 +435,7 @@ static uoff_t get_size(struct mail *_mail) 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; } @@ -567,7 +566,7 @@ static struct istream *get_stream(struct mail *_mail, 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; }