]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3-migration: Avoid unnecessarily using stream's hdr_size.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 14 Sep 2016 16:06:29 +0000 (19:06 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 15 Sep 2016 06:01:08 +0000 (09:01 +0300)
Shouldn't change any behavior, except reduce CPU usage a little bit.

src/plugins/pop3-migration/pop3-migration-plugin.c
src/plugins/pop3-migration/pop3-migration-plugin.h
src/plugins/pop3-migration/test-pop3-migration-plugin.c

index 433ef23af63f100a339fd9c9ad1b0501db613d82..3938cda4ef657f5e56a116aa36de524efa89d9f1 100644 (file)
@@ -176,25 +176,21 @@ pop3_header_filter_callback(struct header_filter_istream *input ATTR_UNUSED,
 }
 
 int pop3_migration_get_hdr_sha1(uint32_t mail_seq, struct istream *input,
-                               uoff_t hdr_size,
                                unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN],
                                bool *have_eoh_r)
 {
-       struct istream *input2;
        const unsigned char *data;
        size_t size;
        struct sha1_ctxt sha1_ctx;
        struct pop3_hdr_context hdr_ctx;
 
        memset(&hdr_ctx, 0, sizeof(hdr_ctx));
-       input2 = i_stream_create_limit(input, hdr_size);
        /* hide headers that might change or be different in IMAP vs. POP3 */
-       input = i_stream_create_header_filter(input2,
+       input = i_stream_create_header_filter(input, HEADER_FILTER_HIDE_BODY |
                                HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR,
                                hdr_hash_skip_headers,
                                N_ELEMENTS(hdr_hash_skip_headers),
                                pop3_header_filter_callback, &hdr_ctx);
-       i_stream_unref(&input2);
 
        sha1_init(&sha1_ctx);
        while (i_stream_read_data(input, &data, &size, 0) > 0) {
@@ -234,21 +230,18 @@ static int
 get_hdr_sha1(struct mail *mail, unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN])
 {
        struct istream *input;
-       struct message_size hdr_size;
        const char *errstr;
        enum mail_error error;
        bool have_eoh;
        int ret;
 
-       if (mail_get_hdr_stream(mail, &hdr_size, &input) < 0) {
+       if (mail_get_hdr_stream(mail, NULL, &input) < 0) {
                errstr = mailbox_get_last_error(mail->box, &error);
                i_error("pop3_migration: Failed to get header for msg %u: %s",
                        mail->seq, errstr);
                return error == MAIL_ERROR_EXPUNGED ? 0 : -1;
        }
-       if (pop3_migration_get_hdr_sha1(mail->seq, input,
-                                       hdr_size.physical_size,
-                                       sha1_r, &have_eoh) < 0)
+       if (pop3_migration_get_hdr_sha1(mail->seq, input, sha1_r, &have_eoh) < 0)
                return -1;
        if (have_eoh) {
                struct index_mail *imail = (struct index_mail *)mail;
@@ -277,15 +270,13 @@ get_hdr_sha1(struct mail *mail, unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN
           So we'll try to avoid this by falling back to full FETCH BODY[]
           (and/or RETR) and we'll parse the header ourself from it. This
           should work around any similar bugs in all IMAP/POP3 servers. */
-       if (mail_get_stream_because(mail, &hdr_size, NULL, "pop3-migration", &input) < 0) {
+       if (mail_get_stream_because(mail, NULL, NULL, "pop3-migration", &input) < 0) {
                errstr = mailbox_get_last_error(mail->box, &error);
                i_error("pop3_migration: Failed to get body for msg %u: %s",
                        mail->seq, errstr);
                return error == MAIL_ERROR_EXPUNGED ? 0 : -1;
        }
-       ret = pop3_migration_get_hdr_sha1(mail->seq, input,
-                                         hdr_size.physical_size,
-                                         sha1_r, &have_eoh);
+       ret = pop3_migration_get_hdr_sha1(mail->seq, input, sha1_r, &have_eoh);
        if (ret == 0) {
                if (!have_eoh)
                        i_warning("pop3_migration: Truncated email with UID %u stored as truncated", mail->uid);
index 398ffb9c4e2a629332afba6fba5234c0377a6527..1dc84e070ebf9159099a26da9fdc20e8c570c0aa 100644 (file)
@@ -7,7 +7,6 @@ void pop3_migration_plugin_init(struct module *module);
 void pop3_migration_plugin_deinit(void);
 
 int pop3_migration_get_hdr_sha1(uint32_t mail_seq, struct istream *input,
-                               uoff_t hdr_size,
                                unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN],
                                bool *have_eoh_r);
 
index 0fea11b75080b9a056218d86b7e02f2fde36666b..a102a8f359b7678276bbf3777c7e2a64d860e4a1 100644 (file)
@@ -31,8 +31,7 @@ static void test_pop3_migration_get_hdr_sha1(void)
        for (i = 0; i < N_ELEMENTS(tests); i++) {
                input = i_stream_create_from_data(tests[i].input,
                                                  strlen(tests[i].input));
-               test_assert_idx(pop3_migration_get_hdr_sha1(1, input, strlen(tests[i].input),
-                                                           digest, &have_eoh) == 0, i);
+               test_assert_idx(pop3_migration_get_hdr_sha1(1, input, digest, &have_eoh) == 0, i);
                test_assert_idx(strcasecmp(binary_to_hex(digest, sizeof(digest)), tests[i].sha1) == 0, i);
                test_assert_idx(tests[i].have_eoh == have_eoh, i);
                i_stream_unref(&input);