@macmanmk That's odd that it would be showing only Not Available. I assume you meant you used the one I posted since that's one of the outputs I included in my script.
I guess you could do like @thoule shows and simply calculate the size of the entire ~/Library/Mail/ directory and not worry about V2, V3, etc. folders inside that. Maybe it's not liking theV* I had in the script.
I wanted to provide another option, if this is something you really want to run across all your Macs, but maybe don't want it consuming time and resources during recons. Have it run once per day as a policy that writes values out to a local file. Then have an Extension Attribute that would pick up that information, which would be as simple as cat'ing the file for example, so it will be near instant on recons.
Here's an example of how I might do it if I was tasked with this. The script I would run, as a policy, maybe just once per day, etc.
#!/bin/bash
while read Acct; do
if [ -d "/Users/$Acct/Library/Mail" ]; then
MailDirSize=$(du -sh "/Users/$Acct/Library/Mail" | awk '{print $1}')
MailSizes+=("${Acct}: $MailDirSize")
fi
done < <(ls /Users/ | egrep -v "Shared|Deleted Users")
if [[ ! -z "${MailSizes[@]}" ]]; then
printf '%s
' "${MailSizes[@]}" > /Users/Shared/MailSizes
else
echo "No Mail Accounts" > /Users/Shared/MailSizes
fi
A little explanation. This loops over each home directory in /Users/ excluding "Shared" and any possible "Deleted Users" folders. Feel free to add to that egrep line for anything else you see that should be excluded.
It looks for a /Library/Mail/ directory in each home, and if it finds one, calculates the size, and drops the info into an array called "MailSizes" When it exits the loop it checks to see if MailSizes has any data, and if it does, it prints that, with line breaks as the final information into a local plain text file in /Users/Shared/ called "MailSizes"
Then you can have an Extension Attribute pick up the info from that file:
#!/bin/bash
if [ -e /Users/Shared/MailSizes ]; then
echo "<result>$(cat /Users/Shared/MailSizes)</result>"
else
echo "<result>Not Available</result>"
fi
Combining these 2 like that will mean you can get that information but not cause every single inventory collection to do a full calculation. It would only happen on the schedule you set for the policy that runs the script above.
Hope that helps.