To test a IMAP connection and login over telnet use this commands.
To quickly test an imap server using telnet use:
telnet server 143
01 LOGIN username password
02 LIST "" *
03 SELECT mailbox
Line 02 shows you all available mailboxes.
To show the information about a mailbox:
04 STATUS mailbox (MESSAGES)