Dovecot mail_crypt corrupted index cache

I have a an email server which uses dovecot as the imap server, i wanted to implement local mail encryption so i decided to use the mail_crypt dovecot plugin using the below documentation.

https://doc.dovecot.org/configuration_manual/mail_crypt_plugin/

I went for the global method using one ecc key pair for the encryption, i created the key pair and put the necessary options in 90-plugins.conf:

plugin {

mail_crypt_curve = prime256v1

mail_crypt_global_private_key = <ecprivkey.pem

mail_crypt_global_public_key = <ecpubkey.pem

mail_crypt_save_version = 2

}

And added the mail_crypt plugin to the plugin list in 20-lmtp.conf.

I sent a test email and the email was encrypted successfully.

However when i go to open the email in my email client (neomutt in this case) i am unable to open the email and the folder it is in, which was INBOX. Looking at dovecot.log the reason is due to index cache corruption, it is complaining that the size is too small.

Aug 18 15:44:15 imap(user)<33736><Hj+y6yetwKhRXM6s>: Error: Mailbox INBOX: UID=xxxx: read(/path/to/Maildir/cur/) failed: Cached message size smaller than expected (3981 < 4220, box=INBOX, UID=xxxx) (read reason=mail stream)

Aug 18 15:44:15 imap(user)<33736><Hj+y6yetwKhRXM6s>: Error: Corrupted record in index cache file /path/to/Maildir/dovecot.index.cache: UID xxxx: Broken physical size in mailbox INBOX: read(/path/to/Maildir/cur/) failed: Cached message size smaller than expected (3981 < 4220, box=INBOX UID=xxxx)

Aug 18 15:44:15 imap(user)<33736><Hj+y6yetwKhRXM6s>: Error: Mailbox INBOX: UID=xxxx: read(/path/to/Maildir/cur/) failed: Cached message size smaller than expected (3981 < 4220, box=INBOX, UID=xxxx)

Aug 18 15:44:15 imap(user)<33736><Hj+y6yetwKhRXM6s>: Info: FETCH failed: Internal error occurred. Refer to server log for more information. [2020-08-18 15:44:15] in=551 out=2369 deleted=0 expunged=0 trashed=0 hdr_count=1 hdr_bytes=68 body_count=0 body_bytes=0

I have tried moving the cache files and restarting the dovecot service which then creates new cache files but the same error occurs. Disabling the plugin, removing the encrypted email and restarting dovecot after removing the newly generated cache files has enabled me access to INBOX once again.

From my understanding dovecot should do the cache message size config automatically.

Is this issue occurring because i have had encrypted email and old unencrypted emails in inbox simultaneously and this was corrupting the cache? Do i need to remove all old unencrypted emails first before implementing the mail_crypt plugin?

Go to Source
Author: Journey Unknown