IMAP常用命令汇总

转自http://busylog.net/telnet-imap-commands-note/


Sometimes I need to debug issues on email box… manually on IMAP port.
Sometimes I need to see my notes.
Here some notes just to use as cut&modify&paste.
>(extra notes here)<

#0 IMAP PORT 143

telnet <IP> 143

#1 Commands format

Command Input :
<RandomStringID> Command

Answer :
<RandomStringID> OK <ANSWER DETAIL>

Example :
  axyz login test@dom.it p4ssw0rd
  axyz OK login successful

where <RandomStringID> is chars axyz or simply char a

#2 Commands:

A command, usually, has to be executed in the proper sequence and only if IMAP automa has the correct status for that command.
In sequence…

2.1 Login Authorization

telnet <SERVER> 143
Trying <SERVER-IP>...
Connected to <SERVER-IP>
Escape character is '^]'.
* OK IMAP4 server ready

login <username>@<domain> <password>
a OK login successful

2.2 CAPABILITY

a capability
* CAPABILITY IMAP4rev1 UIDPLUS IDLE LOGIN-REFERRALS NAMESPACE QUOTA CHILDREN ...
a OK capabilities listed

2.3 LIST of folder

  • system defined folder is “INBOX”.
  • Format : ‘LIST “(folder directory)” “(search argument)”.
    • “(search argument)” is case-sensitive and accept *
    • “(folder directory)” if empty list shows all content from root

(=> all folder)

a LIST "" "*"
* LIST (HasNoChildren) "/" folder-name-1
* LIST (HasNoChildren) "/" folder-name-2
* LIST (HasChildren) "/" folder-name-3
* LIST (HasNoChildren) "/" folder-name-1/folder-name-1.2
...
* LIST (HasNoChildren) "/" INBOX
...
* LIST (HasNoChildren) "/" Trash
a OK LIST completed

(=> folder “folder-name-1”)

a LIST "folder-name-1" "*"
* LIST (HasNoChildren) "/" folder-name-1/folder-name-1.2
a OK LIST completed

(=> all folder fol*)

a LIST "" "fol*"
* LIST (HasNoChildren) "/" folder-name-1
* LIST (HasNoChildren) "/" folder-name-2
* LIST (HasChildren) "/" folder-name-3
* LIST (HasNoChildren) "/" folder-name-1/folder-name-1.2
a OK LIST completed

2.4 Status of a Folder

(=> number of MESSAGES)

a STATUS INBOX (MESSAGES)
* STATUS INBOX (MESSAGES 22)
a OK STATUS complete

(=>number of MESSAGES and number flaged as UNSEEN RECENT)
see more about flags at end of this post #3 and #4 below.

a STATUS INBOX (MESSAGES UNSEEN RECENT)
* STATUS INBOX (MESSAGES 22 RECENT 0 UNSEEN 0)
a OK STATUS complete

2.5 SELECT a folder on which work

a SELECT INBOX
* 22 EXISTS
* 0 RECENT
* FLAGS (Answered Flagged Deleted Seen Draft )
* OK [PERMANENTFLAGS (Answered Flagged Deleted Seen Draft)] flags can be changed
* OK [UIDVALIDITY 1339682095] mailbox UID validity
* OK [UIDNEXT 745] predicted next UID
a OK [READ-WRITE] SELECT complete

2.6 LIST of emails

see more about flags at end of this post #3 and #4 below.

(=> list all emails and show flags)

a fetch 1:* flags
* 1 FETCH (FLAGS (Seen))
* 2 FETCH (FLAGS (Seen))
a OK FETCH complete

(=> list all emails and show internal date)

a fetch 1:* INTERNALDATE
* 1 FETCH (INTERNALDATE "13-Jun-2012 11:04:18 +0200")
* 2 FETCH (INTERNALDATE "20-Aug-2012 16:29:21 +0200")
...
* 22 FETCH (INTERNALDATE "23-Oct-2012 15:31:05 +0200")
a OK FETCH complete

(=> show email with UID 1)

a fetch 1 body[header]
* 1 FETCH (BODY[HEADER] {1316}
Return-Path: <rmsbox@test1.priv>
... email ...
a OK FETCH complete

… Other examples which use “UID Range”

see more about flags at end of this post #3 and #4 below.
=> all emails :

a fetch 1:* body[header]

=> all emails showing from, to, subject and date :

a fetch 1:* (body[header.fields (from to subject date)])

=> all emails showing from, to, subject and date :

a fetch 1:* (body[header.fields (subject)])

2.7 SET FLAG Massively

Set massivelly (bulk set) flags such as read, unread …

a store 1:* +flags seen ... set read all emails
a store 1:* -flags seen ... set unread all emails
a store 10:100 +flags seen ... set as read emails from 10 to 100 (meaning as UID range)
a store 22 +flags deleted ... set as deleted email 22 (meaning as UID 22)
a store 22 -flags deleted ... retore, undelete ... email 22 (meaning as UID 22)

2.5 EXPURGE

Emails wich are set as “deleted” are actually still present in “trash” folder.
If you need to delete them you have to run “EXPURGE” command.

a expunge
* 2 EXPUNGE
a OK EXPUNGE complete

#3 List of Flags

  • \Seen             Message has been read
  • \Answered   Message has been answered
  • \Flagged        Message is “flagged”for urgent/special attention
  • \Deleted        Message is “deleted”for removal by later EXPUNGE
  • \Draft             Message has not completed composition
  • \Recent         Message has arrived since the previous time this mailbox was selected.
#4 UID Range

Some commands (store 1:*) have possibility to specify range (for example STORE command).
Possible sequences :

  • 1:*
  • 2,4,5,6,7,9,12,13,14,15
  • *:3,8,0

sequence-set    = (seq-number / seq-range) *(“,”sequence-set)
                    ; set of seq-number values, regardless of order.
                    ; Servers MAY coalesce overlaps and/or execute the
                    ; sequence in any order.
                    ; Example: a message sequence number set of
                    ; 2,4:7,9,12:* for a mailbox with 15 messages is
                    ; equivalent to 2,4,5,6,7,9,12,13,14,15
                    ; Example: a message sequence number set of *:4,5:7
                    ; for a mailbox with 10 messages is equivalent to
                    ; 10,9,8,7,6,5,4,5,6,7 and MAY be reordered and
                    ; overlap coalesced to be 4,5,6,7,8,9,10.


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值