cPanel reporting incorrect /mail/ directory size

Many times, cPanel is reporting an incorrect value in cPanel->Disk Usage interface. In our test case the value from the shell is 308MB:

root@web [/home/mmtest]# du -sh mail
308M    mail
root@web [/home/mmtest]#

But the value reported in cPanel is 462.99MB as shown in the image below:

mail directory size 1

This is caused by the dovecot server not updating correctly the disk usage. to fix this situation, run the commands:

# /scripts/generate_maildirsize –confirm –allaccounts –verbose $username

root@web [/home/mmtest]# /scripts/generate_maildirsize --confirm --allaccounts --verbose mmtest
Rebuilding the maildirsize files for: mmtest
Rebuilding the maildirsize files for: john@mmtest123.com
Checking user mmtest
Calculating diskusage and diskcount from reading files
Writing /home/mmtest/mail/maildirsize for user merches
Checking user john@mmtest123.com
Calculating diskusage and diskcount from reading files
Writing /home/mmtest/mail/mmtest123.com/john/maildirsize for user john
root@web [/home/mmtest]#

Now the disk usage is reported correctly in cPanel:

mail directory size 2

To run the command for all the accounts use
# /scripts/generate_maildirsize –confirm –allaccounts –verbose

More information on this cPanel script can be found by running
# /scripts/generate_maildirsize –help