Mercurial > dovecot > core-2.2
changeset 20744:cf26a89ceb9a
pop3-migration: Avoid unnecessarily using stream's hdr_size.
Shouldn't change any behavior, except reduce CPU usage a little bit.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 14 Sep 2016 19:06:29 +0300 |
parents | b3176b1a9e68 |
children | 244720af3113 |
files | 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 |
diffstat | 3 files changed, 6 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/pop3-migration/pop3-migration-plugin.c Wed Sep 14 18:57:43 2016 +0300 +++ b/src/plugins/pop3-migration/pop3-migration-plugin.c Wed Sep 14 19:06:29 2016 +0300 @@ -176,25 +176,21 @@ } 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 @@ 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 @@ 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);
--- a/src/plugins/pop3-migration/pop3-migration-plugin.h Wed Sep 14 18:57:43 2016 +0300 +++ b/src/plugins/pop3-migration/pop3-migration-plugin.h Wed Sep 14 19:06:29 2016 +0300 @@ -7,7 +7,6 @@ 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);
--- a/src/plugins/pop3-migration/test-pop3-migration-plugin.c Wed Sep 14 18:57:43 2016 +0300 +++ b/src/plugins/pop3-migration/test-pop3-migration-plugin.c Wed Sep 14 19:06:29 2016 +0300 @@ -31,8 +31,7 @@ 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);