IMAP常用命令

IMAP(Internet Message Access Protocol)常用命令合集
相关文档https://www.rfc-editor.org/rfc/rfc3501

连接到服务器

---ssl
openssl s_client -connect imap.163.com:993 -crlf

---plain
telnet imap.tom.com 143

kongpf@SH-kongpf ~ % telnet imap.tom.com 143
Trying 106.38.219.64...
Connected to imap.tom.com.
Escape character is '^]'.
* OK IMAP4 ready

登录

--- a login username password
a login xxx@tom.com xxx

a OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY LITERAL+ NOTIFY SPECIAL-USE COMPRESS=DEFLATE QUOTA] Logged in

获取服务器功能

a capability

* CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY LITERAL+ NOTIFY SPECIAL-USE COMPRESS=DEFLATE QUOTA
a OK Capability completed (0.001 + 0.000 secs).

查看所有文件夹

a list "" "*"

* LIST (\HasNoChildren \UnMarked) "." python
* LIST (\HasNoChildren \UnMarked \Sent) "." "Sent Items"
* LIST (\HasNoChildren \UnMarked \Junk) "." "Junk E-mail"
* LIST (\HasNoChildren \UnMarked \Trash) "." Trash
* LIST (\HasNoChildren \UnMarked \Drafts) "." Drafts
* LIST (\HasNoChildren) "." INBOX
a OK List completed (0.002 + 0.000 + 0.001 secs).

查看信箱状态

a STATUS INBOX (MESSAGES UNSEEN RECENT)

a status inbox (messages unseen recent)
* STATUS inbox (MESSAGES 2 RECENT 0 UNSEEN 0)
a OK Status completed (0.001 + 0.000 secs).

选中信箱

a select INBOX

* FLAGS (\Answered \Flagged \Deleted \Seen \Draft Deleted)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft Deleted *)] Flags permitted.
* 2 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1676298412] UIDs valid
* OK [UIDNEXT 4] Predicted next UID
* OK [HIGHESTMODSEQ 29] Highest
\a OK [READ-WRITE] Select completed (0.001 + 0.000 secs).

当我们在执行这个select命令的时候,163邮箱会不会和普通邮箱一样给你选中INBOX(即收件箱)文件夹,而是返回NO SELECT Unsafe Login. Please contact kefu@188.com for help这样的返回结果,这个返回的意思是,这不是一个安全的连接,其实是网易没有遵循IMAP的规范,它强制要求你使用IMAP的ID命令,需要先执行以下命令:

a ID ("name" "test" "version" "1.0" "vendor" "abcd")

获取UID

A001 UID SEARCH ALL
* SEARCH 288 291 292 293 295 323 324 325 326 327 385 387 472 474 641 720 748
A001 OK UID SEARCH completed

//获取UID
A002 UID FETCH 1:* (UID)

//获取标记
A002 UID FETCH 1:* (UID FLAGS)

//获取信头
A002 UID FETCH 280 (ENVELOPE)

//获取BODY
A002 UID FETCH 280 BODY[]

搜索

//查看未读邮件
a uid search unseen

查看信头

a fetch 1 body[header]
---查看信头指定字段
a fetch 1 body[header.fields (date from to)]

查看正文

a fetch 1 body[text]

查看完整邮件

a fetch 1 body[text]

标记邮件

---标记为已读
a store 1 +flags \Seen

---标记为未读
a store 1 -flags \Seen

---标记为红旗邮件
a store 1 +flags \Flagged

创建文件夹

a create test

重命名文件夹

a rename test test2

删除文件夹

a delete test2

登出

a logout
posted @ 2023-02-24 12:13  南极冰川雪  阅读(713)  评论(0编辑  收藏  举报