The AT command +CPMS (Preferred Message Storage) is used to figure out,
Select the message storage area that will be used when sending, receiving, reading, writing or deleting SMS messages.
Find the number of messages that are currently stored in the message storage area.
Find the maximum number of messages that can be stored in the message storage area.
try AT+CPMS?
to list the available spaces. and issue a command like this,
AT+CPMS="SM","SM","SM"
the response should show used space,available space repeatedly like this,
+CPMS: "SM",19,20,"SM",19,20,"SM",19,20
here is SM signifies SIM card space and a list of available options is below. A typical response shows,
+CPMS: used1,max1,used2,max2,used3,max3
Based on the count, read each response using AT+CMGR=x (x is the index of the message) and parse the response for "REC UNREAD" and subtract to get read messages.
PS:
here, SM is storage area in SIM card. others are,
SM. msg storage area on the SIM card.
ME. msg storage area on the GSM/GPRS modem or device. A larger storage
space than SIM card(SM).
MT. all msg storage areas associated with the your modem or device.
BM. broadcast message storage area.
(In some devices, ME & MT -> Flash message storage.)
SR. It refers to the status report message storage area. It is used to
store status reports.
TA. Terminal Adaptor msg storage area.