Berbicara langsung dengan server IMAP

Untuk berbicara langsung dengan server IMAP, kita dapat menggunakan program telnet dan konek ke port IMAP (defaultnya 143, tapi dapat berbeda).

$ telnet HOSTNAME_ATAU_IP 143


Sekilas protokol IMAP

Setiap baris request dari klien perlu diprefiks (diawali) dengan sebuah string penanda. Pada contoh-contoh di artikel ini digunakan a001.

Contoh

Login:

$ telnet mail.host.com 143
Trying 1.2.3.4...
Connected to mail.host.com
Escape character is '^]'.
* OK [CAPABILITY IMAP4REV1 LITERAL+ SASL-IR LOGIN-REFERRALS AUTH=LOGIN] mail.host.com IMAP4rev1 2004.350 at Fri, 16 Mar 2007 13:51:21 -0500 (CDT)
a01 LOGIN someuser somepass
RESPONSE: a001 OK User logged in

Mengetahui capability IMAP service:

a001 CAPABILITY
* CAPABILITY IMAP4REV1 LITERAL+ IDLE NAMESPACE MAILBOX-REFERRALS BINARY UNSELECT SCAN SORT THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAPPEND SASL-IR LOGIN-REFERRALS AUTH=LOGIN
a001 OK CAPABILITY completed

Logout:

a001 LOGOUT
* BYE mail.host.com IMAP4rev1 server terminating connection
a002 OK LOGOUT completed
Connection closed by foreign host.

Melihat daftar mailbox yang ada (pada contoh, semua anak Inbox):

a001 LIST "Inbox" "*"
* LIST (\HasNoChildren) "." "INBOX.omail.log.old"
* LIST (\HasChildren) "." "INBOX.omail.log"
* LIST (\HasNoChildren) "." "INBOX.Trash"
* LIST (\HasNoChildren) "." "INBOX.Spam"
* LIST (\HasNoChildren) "." "INBOX.Sent"
* LIST (\HasNoChildren) "." "INBOX.Drafts"
* LIST (\Noselect \HasChildren) "." "INBOX.omail"
a001 OK LIST completed

Men-select sebuah mailbox (pada contoh, bernama INBOX):

a001 SELECT INBOX
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
* 1242 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1062186210]
* OK [UIDNEXT 1246]
a03 OK [READ-WRITE] Completed

Mendaftar semua message yang ada pada sebuah mailbox yang sedang di-select:

a001 FETCH 1:* FLAGS
* 1 FETCH (FLAGS (\Seen))
* 2 FETCH (FLAGS (\Seen))
* 3 FETCH (FLAGS (\Seen))
* 4 FETCH (FLAGS (\Seen))
* 5 FETCH (FLAGS (\Seen))
* 6 FETCH (FLAGS (\Seen \Answered))
...
a001 OK FETCH completed

Mengambil header-header sebuah message (pada contoh, urutan pertama dan mengambil full headers).

a001 FETCH 1 full
* 1 FETCH (FLAGS (\Seen) INTERNALDATE "15-Mar-2000 13:10:14 -0500" RFC822.SIZE 1
553 ENVELOPE ("Wed, 15 Mar 2007 13:10:11 -0600" "Perl Stuff" (("Rusty Nejdl" NIL
"rnejdl" "verio.net")) (("Rusty Nejdl" NIL "rnejdl" "verio.net")) (("Rusty Nejd
l" NIL "rnejdl" "verio.net")) ((NIL NIL "rnejdl" "verio.net")) ((NIL NIL "ttodd"
"verio.net")) NIL NIL "<20000315131011.A5381@tethys.ringofsaturn.com>") BODY ("
TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 359 9))
a001 OK FETCH completed

Mengambil bodi message:

a001 FETCH 1 body

Set quota:

a001 SETQUOTA "" (STORAGE 512)

Get quota:

a001 GETQUOTA ""
* QUOTA "" (STORAGE 10 512)
a001 OK Getquota completed

Get quota root:

a001 GETQUOTAROOT "Inbox"
 

Resita has written 705 articles