Page 1 of 1

How to fix gzip-compressed Maildir messages after cPanel import

Posted: Wed Mar 25, 2026 12:21 pm
by isscbta
In some cases, after running

Code: Select all

v-import-cpanel-backup
on myVesta, email messages imported from cPanel may remain gzip-compressed inside the Maildir structure. When that happens, Dovecot and the mail stack may not read those messages properly, which can result in missing or broken inbox contents.

In /var/log/dovecot.log you may see something like this:

Code: Select all

Mar 23 15:21:07 imap([email protected])<3347150><yUjivrFNXJt/AAAB>: Error: Mailbox INBOX: UID=1: read(/home/user/mail/domain.com/account/cur/1748433712.M456713P1942205.someserver,S=80724,W=82092:2,S) failed: Cached message size larger than expected (80724 > 19442, box=INBOX, UID=1) (read reason=mail stream)
Mar 23 15:21:07 imap([email protected])<3347150><yUjivrFNXJt/AAAB>: Error: Mailbox INBOX: Deleting corrupted cache record uid=1: UID 1: Broken physical size in mailbox INBOX: read(/home/user/mail/domain.com/account/cur/1748433712.M456713P1942205.someserver,S=80724,W=82092:2,S) failed: Cached message size larger than expected (80724 > 19442, box=INBOX, UID=1)
Mar 23 15:21:07 imap([email protected])<3347150><yUjivrFNXJt/AAAB>: Error: Mailbox INBOX: UID=1: read(/home/user/mail/domain.com/account/cur/1748433712.M456713P1942205.someserver,S=80724,W=82092:2,S) failed: Cached message size larger than expected (80724 > 19442, box=INBOX, UID=1)
Mar 23 15:21:07 imap([email protected])<3347150><yUjivrFNXJt/AAAB>: Info: FETCH failed: Internal error occurred. Refer to server log for more information. [2026-03-23 15:21:07] in=337 out=1273 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
The procedure below safely detects gzip-compressed mail files, decompresses them in place while preserving timestamps, removes Dovecot index files, and then restarts Dovecot so indexes can be rebuilt correctly.

Important:
  • Run this only after confirming that imported mail files are actually gzip-compressed.
  • Make sure to replace

    Code: Select all

    /home/user/mail/
    with the correct mail path for the affected account.
  • It is strongly recommended to create a backup before making any changes.
Step 1, go to the mail directory

Code: Select all

cd /home/user/mail/
Step 2, detect and decompress gzip-compressed Maildir files

Code: Select all

find ./ -type f -exec sh -c '
  for f; do
    if file "$f" | grep -q "gzip compressed data"; then
      tmp=$(mktemp) || exit 1

      if gunzip -c "$f" > "$tmp"; then
        touch -r "$f" "$tmp" && mv "$tmp" "$f"
      else
        rm -f "$tmp"
      fi
    fi
  done
' sh {} +
What this does:
  • scans all files under the selected mail directory
  • checks whether a file is gzip-compressed
  • decompresses the file into a temporary file
  • preserves the original timestamp
  • replaces the original compressed file with the decompressed version
Step 3, remove Dovecot index files

Code: Select all

find \( -name "dovecot.index" -or -name "dovecot.index.cache" -or -name "dovecot.index.log" -or -name "dovecot.index.log.2" -or -name "dovecot.mailbox.log" -or -name "dovecot.index.log.newlock" \) -delete
Why this is needed:
Dovecot may still keep old mailbox index information. Deleting these index files forces Dovecot to rebuild them based on the now-correct message files.

Step 4, restart Dovecot

Code: Select all

systemctl restart dovecot
Result

After this procedure, the imported Maildir messages should be readable normally, and the mailbox indexes should be rebuilt correctly.