Counting email messages should be easy, just look at RFC1939: RFC 1939 - Post Office Protocol - Version 3
The STAT command returns the number of messages in the mailbox.
You can use the LIST command to get the current message numbers, then use the RETR command to get a whole message, or the TOP command (if your POP server supports it) to get a certain number of lines from the message.