CLI - checking all of the email addresses of a user for new email

mec-forum

Member
Jun 18, 2019
23
4
3
Italy
cPanel Access Level
Root Administrator
I would like to print the number of unread messages for all the email accounts belonging to a certain user. Is there a way to do it without root permissions?
One idea is to get the mailboxes with
Bash:
cpapi2 --user=username Email browseboxes account=someuser
and use something like the mailcheck tool for ubuntu, but I see there is no package for it on yum. Maybe there is a simpler way. I wanted an output similar to this:

Code:
[email protected]: NOTHING NEW
[email protected]: 2 UNREAD
[email protected]: 23 UNREAD
Eventually I would like to create a page in cPanel for this, and/or add the actual count as a column in the email account list, but I'm not skilled enough on extending cPanel like that so for now I'll settle for a script that dumps the email count. Maybe put it in a php script later if I can run it in unpriviledged context somehow. ;)
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
I'm not sure in browseboxes will give you a list of new email Well if you're using maildir new mail is stored in /home/$user/mail/$domain.tld/$emailuser/new/ you could use something like the one-liners discussed here to provide a report How to count number of files in each directory? as long as you retain the command to your home dir (/home/$user) and you have shell access you shouldn't have a problem.