From: Aki Tuomi Date: Tue, 11 Nov 2025 06:38:38 +0000 (+0200) Subject: doveadm: dsync - Search exportable mails with timestamps X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f88ed5598aae68b2b2c27b80ef8b0b819d3972e4;p=thirdparty%2Fdovecot%2Fcore.git doveadm: dsync - Search exportable mails with timestamps This speeds up dsync with -t and -e, especially over network connection. --- diff --git a/src/doveadm/dsync/dsync-brain-mailbox.c b/src/doveadm/dsync/dsync-brain-mailbox.c index 84d25c18f7..3a17511a6d 100644 --- a/src/doveadm/dsync/dsync-brain-mailbox.c +++ b/src/doveadm/dsync/dsync-brain-mailbox.c @@ -355,6 +355,8 @@ int dsync_brain_sync_mailbox_open(struct dsync_brain *brain, .last_common_uid = last_common_uid, .flags = exporter_flags, .hdr_hash_version = brain->hdr_hash_version, + .sync_since_timestamp = brain->sync_since_timestamp, + .sync_until_timestamp = brain->sync_until_timestamp, .hashed_headers = brain->hashed_headers, .parent_event = brain->event, }; diff --git a/src/doveadm/dsync/dsync-mailbox-export.c b/src/doveadm/dsync/dsync-mailbox-export.c index 57b73fe814..4d97751581 100644 --- a/src/doveadm/dsync/dsync-mailbox-export.c +++ b/src/doveadm/dsync/dsync-mailbox-export.c @@ -57,6 +57,9 @@ struct dsync_mailbox_exporter { struct dsync_mail_change change; struct dsync_mail dsync_mail; + time_t sync_since_timestamp; + time_t sync_until_timestamp; + const char *error; enum mail_error mail_error; @@ -403,6 +406,18 @@ dsync_mailbox_export_search(struct dsync_mailbox_exporter *exporter) wanted_headers = exporter->wanted_headers; } + if (exporter->sync_since_timestamp != 0) { + sarg = mail_search_build_add(search_args, SEARCH_SINCE); + sarg->value.date_type = MAIL_SEARCH_DATE_TYPE_RECEIVED; + sarg->value.time = exporter->sync_since_timestamp; + } + + if (exporter->sync_until_timestamp != 0) { + sarg = mail_search_build_add(search_args, SEARCH_BEFORE); + sarg->value.date_type = MAIL_SEARCH_DATE_TYPE_RECEIVED; + sarg->value.time = exporter->sync_until_timestamp; + } + exporter->trans = mailbox_transaction_begin(exporter->box, MAILBOX_TRANSACTION_FLAG_SYNC, __func__); @@ -528,6 +543,8 @@ dsync_mailbox_export_init(struct mailbox *box, exporter->no_hdr_hashes = (set->flags & DSYNC_MAILBOX_EXPORTER_FLAG_NO_HDR_HASHES) != 0; exporter->hashed_headers = set->hashed_headers; + exporter->sync_since_timestamp = set->sync_since_timestamp; + exporter->sync_until_timestamp = set->sync_until_timestamp; exporter->event = event_create(set->parent_event); p_array_init(&exporter->requested_uids, pool, 16); diff --git a/src/doveadm/dsync/dsync-mailbox-export.h b/src/doveadm/dsync/dsync-mailbox-export.h index f30ec8f148..0a42f657c1 100644 --- a/src/doveadm/dsync/dsync-mailbox-export.h +++ b/src/doveadm/dsync/dsync-mailbox-export.h @@ -15,6 +15,8 @@ struct dsync_mailbox_export_settings { enum dsync_mailbox_exporter_flags flags; unsigned int hdr_hash_version; const char *const *hashed_headers; + time_t sync_since_timestamp; + time_t sync_until_timestamp; struct event *parent_event; };