]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Removed useless parameters from message_get_body_size(). Also did some small
authorTimo Sirainen <tss@iki.fi>
Wed, 4 Jun 2003 23:00:44 +0000 (02:00 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 4 Jun 2003 23:00:44 +0000 (02:00 +0300)
optimizations to it.

--HG--
branch : HEAD

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

index 90e5bb0b8ceab16262adb7ba779353475aba783d..cf571691683c36e15046cf1c157b7b16bf542c3e 100644 (file)
@@ -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 {
index 00c2766f74f5493ec9f80987355bc79c263a8f1f..63dcc637391be0e0ef67a8f42b358cf541192840 100644 (file)
@@ -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,
index 8b559a65eced4b98130cff825704e5dce1c7ab07..0ce3bc322f5a39d84d75b2c1b4cb024eb11ced31 100644 (file)
@@ -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. */
index 3b56fd59086142fdeb02baf93cc499a93cfa70ae..fca46806d63c635671adfdc93646ad242b688ba3 100644 (file)
@@ -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;
                }