cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,301
363
Houston
HI @adamreece.webbox

I just took a look at the ticket and it appears that your disk usage discrepancy was due to compression being enabled at some point for email. The solution was to decompress the message as disabling this setting does not automatically do so. It looks like you created a one-liner to do this for all your messages, if you don't mind sharing it here, it may help others in the future.

Thanks!
 

adamreece.webbox

Well-Known Member
Nov 3, 2016
52
20
58
Penarth, United Kingdom
cPanel Access Level
Root Administrator
Hi Lauren,

Yes, it appears that the issue in this server's case was either
  • the email compression setting was enabled when the mailbox was created (and during much of its life), but the setting no longer is, or
  • the hosting account was migrated from another cPanel server that has email compression enabled.
Rex gave me the following command to help determine if a mailbox has compressed contents. This should be executed with the working directory set to a mailbox maildir location, e.g. "/home/{account}/mail/{domainname}/{mailbox}".

find . -type f -exec file {} \+ | awk -F ':[ ]+' '{ print $2; }' | sort | uniq -c | sort -n

If the mailbox contains any compressed messages you'll see this line in the response:

<count> gzip compressed data, from Unix

To decompress these messages I built this command. -- Obviously this will increase the mailbox disk usage.
  • Make a backup copy of the {mailbox} directory first.
  • Really. Make a backup copy of the whole {mailbox} directory first.
  • Are you sure you have a backup copy of the {mailbox} directory?
Again, run this with the working directory set to a mailbox maildir location.

for MSGFILE in $(find . -type f -exec file {} \+ | grep gzip | awk -F ':[ ]+' '{ print $1; }' | sort); do echo "${MSGFILE}"; gzip -c -d "${MSGFILE}" > "${MSGFILE}.plain"; if [ -s "${MSGFILE}.plain" ]; then echo "Success"; rm -f "${MSGFILE}"; mv "${MSGFILE}.plain" "${MSGFILE}"; else echo "Failed"; rm -f "${MSGFILE}.plain"; fi; done;

I'm sure a Bash guru could shorten that further, particularly the use of a temporary ".plain" file.

You will start seeing a list of email files, with either "Success" or "Failed" indicating if the message has been decompressed. Bare in mind there will be an expected (short) delay for the cPanel disk usage component to notice these changes.

----

You could wrap these commands up to work with all mailboxes for an account (all domains within) as follows, with your working directory to "/home/{account}"

for DOMAINDIR in $(find . -maxdepth 1 -type d | sort); do if [ ! -d "${DOMAINDIR}/mail" ]; then continue; fi; for MSGFILE in $(find "${DOMAINDIR}/mail" -type f -exec file {} \+ | grep gzip | awk -F ':[ ]+' '{ print $1; }' | sort); do echo "${MSGFILE}"; gzip -c -d "${MSGFILE}" > "${MSGFILE}.plain"; if [ -s "${MSGFILE}.plain" ]; then echo "Success"; rm -f "${MSGFILE}"; mv "${MSGFILE}.plain" "${MSGFILE}"; else echo "Failed"; rm -f "${MSGFILE}.plain"; fi; done; done;

I've not tested this for multiple mailboxes at once though! Verify what I've written, and backup the mailbox directories first. (Only 2 mailboxes seemed to be impacted on the server in question so I just sorted those individually.)

----

Thanks again for your support on this issue. :)
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,301
363
Houston
Hi @adamreece.webbox

This is incredibly helpful, thank you so much for sharing and including so much detailed information. I'm so happy we were able to help and that you were able to identify a solution :D !

Thank you!!!
 
  • Like
Reactions: cPanelMichael