While I connect to an SMTP server via telnet regularly, I do it seldom for IMAP servers.
More as a personal note I want to cite what I found on imap via linux shell
Connect to server:
IMAP
nc SERVERNAME-OR-IP 143
IMAPS
openssl s_client -connect SERVERNAME-OR-IP:993
IMAP commands:
1
2
3
4
5
6
7
8
9
10
11
12
enumerate/prefix commands with arbitrary labels or simply a '.'
login USERNAME "PASSWORD" # login
list "" "*" # show all mailboxes
status [mailbox]
select "MAILBOX" # switch to mailbox
fetch FIRST:LAST FLAGS
fetch MAILID BODY[HEADER]
fetch MAILID BODY[TEXT]
uid search all
uid store MAILID +flags (\Deleted) # mark as deleted
expunge # actual delete
logout # logout