From: Timo Sirainen Date: Thu, 28 Nov 2019 18:28:35 +0000 (+0200) Subject: lib-storage: Add MAIL_FETCH_REFCOUNT_ID X-Git-Tag: 2.3.10~144 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dc3c2d4b35b9536ddcbef93b04f9691bd8207ac;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add MAIL_FETCH_REFCOUNT_ID This returns a unique ID for the mail that is counted by MAIL_FETCH_REFCOUNT. For example if the refcount is counted using the file's st_nlinks, then the refcount-id is the file's inode number. This is likely only going to be used by lazy_expunge_only_last_instance=yes tracking. --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-mail.c b/src/lib-storage/index/dbox-multi/mdbox-mail.c index 84b6390001..1b48f4fedf 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-mail.c +++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c @@ -186,6 +186,13 @@ mdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field, *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%u", refcount); return 0; + case MAIL_FETCH_REFCOUNT_ID: + if (mdbox_mail_lookup(mbox, _mail->transaction->view, + _mail->seq, &map_uid) < 0) + return -1; + *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%u", + map_uid); + return 0; case MAIL_FETCH_UIDL_BACKEND: if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id, offsetof(struct mdbox_index_header, flags), diff --git a/src/lib-storage/index/dbox-single/sdbox-mail.c b/src/lib-storage/index/dbox-single/sdbox-mail.c index 0357a97bdb..d53aa11a38 100644 --- a/src/lib-storage/index/dbox-single/sdbox-mail.c +++ b/src/lib-storage/index/dbox-single/sdbox-mail.c @@ -79,6 +79,19 @@ sdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field, *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%lu", (unsigned long)st.st_nlink); return 0; + case MAIL_FETCH_REFCOUNT_ID: + if (sdbox_mail_file_set(mail) < 0) + return -1; + + _mail->transaction->stats.fstat_lookup_count++; + if (dbox_file_stat(mail->open_file, &st) < 0) { + if (errno == ENOENT) + mail_set_expunged(_mail); + return -1; + } + *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%llu", + (unsigned long long)st.st_ino); + return 0; case MAIL_FETCH_UIDL_BACKEND: if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id, offsetof(struct sdbox_index_header, flags), diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 3577879469..26d22311f9 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -1601,6 +1601,7 @@ int index_mail_get_special(struct mail *_mail, case MAIL_FETCH_HEADER_MD5: case MAIL_FETCH_POP3_ORDER: case MAIL_FETCH_REFCOUNT: + case MAIL_FETCH_REFCOUNT_ID: *value_r = ""; return 0; case MAIL_FETCH_MAILBOX_NAME: diff --git a/src/lib-storage/index/maildir/maildir-mail.c b/src/lib-storage/index/maildir/maildir-mail.c index 759c717d02..c21215faba 100644 --- a/src/lib-storage/index/maildir/maildir-mail.c +++ b/src/lib-storage/index/maildir/maildir-mail.c @@ -581,6 +581,12 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, *value_r = p_strdup_printf(mail->mail.data_pool, "%lu", (unsigned long)st.st_nlink); return 0; + case MAIL_FETCH_REFCOUNT_ID: + if (maildir_mail_stat(_mail, &st) < 0) + return -1; + *value_r = p_strdup_printf(mail->mail.data_pool, "%llu", + (unsigned long long)st.st_ino); + return 0; default: return index_mail_get_special(_mail, field, value_r); } diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index fc5b1cfc07..48f2d6baf9 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -183,7 +183,8 @@ enum mail_fetch_field { MAIL_FETCH_GUID = 0x00200000, MAIL_FETCH_POP3_ORDER = 0x00400000, MAIL_FETCH_REFCOUNT = 0x00800000, - MAIL_FETCH_BODY_SNIPPET = 0x01000000 + MAIL_FETCH_BODY_SNIPPET = 0x01000000, + MAIL_FETCH_REFCOUNT_ID = 0x02000000, }; enum mailbox_transaction_flags {