IMAP connection from the command line

less than 1 minute read

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 <a href=http://blog.sjas.de/posts/imap-via-linux-shell.html>imap via linux shell</a>

Connect to server:

IMAP

nc SERVERNAME-OR-IP 143

IMAPS

openssl s_client -connect SERVERNAME-OR-IP:993

IMAP commands:

    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