]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
memory usage fixes
authorTimo Sirainen <tss@iki.fi>
Wed, 26 Mar 2003 15:40:16 +0000 (17:40 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 26 Mar 2003 15:40:16 +0000 (17:40 +0200)
--HG--
branch : HEAD

src/lib-imap/imap-envelope.c
src/lib-imap/imap-envelope.h
src/lib-imap/imap-quote.c
src/lib-imap/imap-quote.h
src/lib-index/mail-index-update.c
src/lib-storage/index/index-mail.c

index 4014dabbb93813d42a35359cae13d3172fb6d592..ac980af80cd1c3212141044bf513dbece456c441 100644 (file)
@@ -98,13 +98,13 @@ static void imap_write_address(string_t *str, struct message_address *addr)
        str_append_c(str, '(');
        while (addr != NULL) {
                str_append_c(str, '(');
-               str_append(str, imap_quote_str_nil(addr->name));
+               imap_quote_append_string(str, addr->name);
                str_append_c(str, ' ');
-               str_append(str, imap_quote_str_nil(addr->route));
+               imap_quote_append_string(str, addr->route);
                str_append_c(str, ' ');
-               str_append(str, imap_quote_str_nil(addr->mailbox));
+               imap_quote_append_string(str, addr->mailbox);
                str_append_c(str, ' ');
-               str_append(str, imap_quote_str_nil(addr->domain));
+               imap_quote_append_string(str, addr->domain);
                str_append_c(str, ')');
 
                addr = addr->next;
@@ -138,16 +138,6 @@ void imap_envelope_write_part_data(struct message_part_envelope_data *data,
        str_append(str, NVL(data->message_id, "NIL"));
 }
 
-const char *
-imap_envelope_get_part_data(struct message_part_envelope_data *data)
-{
-       string_t *str;
-
-       str = t_str_new(2048);
-        imap_envelope_write_part_data(data, str);
-       return str_c(str);
-}
-
 static int imap_address_arg_append(struct imap_arg *arg, string_t *str,
                                   int *in_group)
 {
index 94e0406feebb123b2becb8d2873ac23408dcf06f..21916e365e87b58c819cfbdccada6360debd5f9e 100644 (file)
@@ -33,9 +33,6 @@ void imap_envelope_parse_header(pool_t pool,
 /* Write envelope to given string */
 void imap_envelope_write_part_data(struct message_part_envelope_data *data,
                                   string_t *str);
-/* Return envelope. */
-const char *
-imap_envelope_get_part_data(struct message_part_envelope_data *data);
 
 /* Parse envelope and store specified field to result. NIL is stored as NULL.
    Returns TRUE if successful. */
index 3878f694474277e4052f82b09f267708ed47d209..3a7c02070d78bf96521b3d8898d28d4b02db70b0 100644 (file)
@@ -10,6 +10,11 @@ void imap_quote_append(string_t *str, const unsigned char *value,
        size_t i, linefeeds = 0;
        int literal = FALSE;
 
+       if (value == NULL) {
+               str_append(str, "NIL");
+               return;
+       }
+
        for (i = 0; i < value_len; i++) {
                if (value[i] == 0) {
                        value_len = i;
@@ -45,22 +50,13 @@ void imap_quote_append(string_t *str, const unsigned char *value,
                str_append_c(str, '"');
 }
 
-const char *imap_quote_str_nil(const char *value)
+char *imap_quote(pool_t pool, const unsigned char *value, size_t value_len)
 {
        string_t *str;
 
        if (value == NULL)
                return "NIL";
 
-       str = t_str_new(512);
-       imap_quote_append(str, (const unsigned char *) value, (size_t)-1);
-       return str_c(str);
-}
-
-char *imap_quote(pool_t pool, const unsigned char *value, size_t value_len)
-{
-       string_t *str;
-
        str = t_str_new(value_len + MAX_INT_STRLEN + 5);
        imap_quote_append(str, value, value_len);
        return p_strndup(pool, str_data(str), str_len(str));
index 0ae7ff92b0f9eb022dc88a1045a76ffbd33de7dc..b5c6c65d1d2a5c4af8eb1aab4f17b6792493221f 100644 (file)
@@ -9,7 +9,7 @@ char *imap_quote(pool_t pool, const unsigned char *value, size_t value_len);
 void imap_quote_append(string_t *str, const unsigned char *value,
                       size_t value_len);
 
-/* If value is NULL, return NIL. */
-const char *imap_quote_str_nil(const char *value);
+#define imap_quote_append_string(str, value) \
+       imap_quote_append(str, (const unsigned char *) value, (size_t)-1)
 
 #endif
index 2d042b555ad1a207dc1df41aa0473486634d67bf..89014c0a527afc883b864f97e3f0c90916223eed 100644 (file)
@@ -4,6 +4,7 @@
 #include "buffer.h"
 #include "istream.h"
 #include "ioloop.h"
+#include "str.h"
 #include "message-date.h"
 #include "message-parser.h"
 #include "message-part-serialize.h"
@@ -529,10 +530,13 @@ void mail_index_update_headers(struct mail_index_update *update,
        }
 
        if (ctx.envelope != NULL) {
+               string_t *str;
+
                t_push();
-               value = imap_envelope_get_part_data(ctx.envelope);
+               str = str_new(data_stack_pool, 2048);
+               imap_envelope_write_part_data(ctx.envelope, str);
                update->index->update_field(update, DATA_FIELD_ENVELOPE,
-                                           value, 0);
+                                           str_c(str), 0);
                t_pop();
 
                pool_unref(ctx.envelope_pool);
index f09ed49a400ec08de172c5d8d0b196a953e44b5a..9e3aaf43e8ffe7d7af3ec506acfd49197f44614a 100644 (file)
@@ -209,11 +209,9 @@ void index_mail_parse_header(struct message_part *part __attr_unused__,
                        /* finalize the envelope */
                        string_t *str;
 
-                       t_push();
                        str = str_new(mail->pool, 256);
                        imap_envelope_write_part_data(data->envelope_data, str);
                        data->envelope = str_c(str);
-                       t_pop();
                }
        }
 
@@ -687,7 +685,9 @@ void index_mail_init(struct index_mailbox *ibox, struct index_mail *mail,
 int index_mail_next(struct index_mail *mail, struct mail_index_record *rec)
 {
        struct index_mail_data *data = &mail->data;
-       int open_mail, parse_header;
+       int ret, open_mail, parse_header;
+
+       t_push();
 
        /* close the old one */
        if (data->stream != NULL)
@@ -773,22 +773,26 @@ int index_mail_next(struct index_mail *mail, struct mail_index_record *rec)
                        open_mail(mail->ibox->index, data->rec,
                                  &data->received_date, &deleted);
                if (data->stream == NULL)
-                       return deleted ? 0 : -1;
-       }
-
-       if ((mail->wanted_fields & MAIL_FETCH_RECEIVED_DATE) &&
-           data->received_date == (time_t)-1) {
-               /* check this only after open_mail() */
-               data->received_date = get_cached_received_date(mail);
-       }
+                       ret = deleted ? 0 : -1;
+               else
+                       ret = 1;
+       } else {
+               if ((mail->wanted_fields & MAIL_FETCH_RECEIVED_DATE) &&
+                   data->received_date == (time_t)-1) {
+                       /* check this only after open_mail() */
+                       data->received_date = get_cached_received_date(mail);
+               }
 
-       if (mail->wanted_fields & MAIL_FETCH_DATE)
-               data->save_sent_time = TRUE;
-       if (mail->wanted_fields & MAIL_FETCH_IMAP_ENVELOPE)
-               data->save_envelope = TRUE;
+               if (mail->wanted_fields & MAIL_FETCH_DATE)
+                       data->save_sent_time = TRUE;
+               if (mail->wanted_fields & MAIL_FETCH_IMAP_ENVELOPE)
+                       data->save_envelope = TRUE;
 
-       data->parse_header = parse_header;
-       return 1;
+               data->parse_header = parse_header;
+               ret = 1;
+       }
+       t_pop();
+       return ret;
 }
 
 void index_mail_deinit(struct index_mail *mail)