Mercurial > dovecot > original-hg > dovecot-1.2
changeset 1543:7ac153f21949 HEAD
Removed useless parameters from message_get_body_size(). Also did some small
optimizations to it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 05 Jun 2003 02:00:44 +0300 |
parents | e3275092817e |
children | ac6ee442376d |
files | src/lib-mail/message-parser.c src/lib-mail/message-size.c src/lib-mail/message-size.h src/lib-storage/index/index-mail.c |
diffstat | 4 files changed, 27 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-mail/message-parser.c Wed Jun 04 20:39:37 2003 +0300 +++ b/src/lib-mail/message-parser.c Thu Jun 05 02:00:44 2003 +0300 @@ -486,8 +486,7 @@ 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 {
--- a/src/lib-mail/message-size.c Wed Jun 04 20:39:37 2003 +0300 +++ b/src/lib-mail/message-size.c Thu Jun 05 02:00:44 2003 +0300 @@ -62,63 +62,53 @@ } 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[0] == '\n') + missing_cr_count++; - if (msg[i] == '\0') { - if (has_nuls != NULL) - *has_nuls = TRUE; - } else if (msg[i] == '\n') { - if (i == 0 || msg[i-1] != '\r') { + do { + for (i = 1; i < size; i++) { + if (msg[i] > '\n') + continue; + + if (msg[i] == '\n') { + if (msg[i-1] != '\r') { /* missing CR */ missing_cr_count++; - - if (max_virtual_size == 0) { - cr = 2; - break; - } - - max_virtual_size--; } /* 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; + } while (i_stream_read_data(input, &msg, &size, 1) > 0); - body->physical_size += i - 1; - } - i_stream_skip(input, startpos); - body->physical_size += startpos; + 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,
--- a/src/lib-mail/message-size.h Wed Jun 04 20:39:37 2003 +0300 +++ b/src/lib-mail/message-size.h Thu Jun 05 02:00:44 2003 +0300 @@ -11,11 +11,8 @@ 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. */
--- a/src/lib-storage/index/index-mail.c Wed Jun 04 20:39:37 2003 +0300 +++ b/src/lib-storage/index/index-mail.c Thu Jun 05 02:00:44 2003 +0300 @@ -435,8 +435,7 @@ 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 @@ 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; }