telnet 127.0.0.1 143
//登陆
Q1 login [email protected] q1q1q1q1
Q1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH ACL RIGHTS=texk QUOTA] Logged in
//选择将要操作的邮箱
Q2 SELECT INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 1 EXISTS //当前存在的邮件数
* 0 RECENT //最近
* OK [UNSEEN 1] First unseen. //未读数
* OK [UIDVALIDITY 1384775818] UIDs valid //邮箱的ID
* OK [UIDNEXT 98] Predicted next UID //下一封信的UID
* OK [HIGHESTMODSEQ 1]
Q2 OK [READ-WRITE] Select completed.
//新建自定义邮箱
Q2 CREATE BOX2
Q2 OK Create completed.
Q2 CREATE LYY/LYY1 //创建子邮箱
q2 OK Create completed.
//删除自定义邮件夹:如果该邮件夹下有子邮件夹,子邮件夹将被保留
Q3 DELETE LYY
Q3 OK Delete completed.
Q3 DELETE LYY/LYY1 //删除子邮件夹
Q3 OK Delete completed.
//重命名邮件夹:如果有子邮件夹,同步命名子邮件夹
Q4 RENAME test_box test_box1
// 列出所有邮箱列表
Q4 LIST "" *
* LIST (\HasNoChildren) "/" "trash" //回收站
* LIST (\HasNoChildren) "/" "&XfJT0ZABkK5O9g-" //已发送
* LIST (\HasChildren) "/" "333"
* LIST (\HasNoChildren) "/" "333/2"
* LIST (\HasNoChildren) "/" "333/1"
* LIST (\HasNoChildren) "/" "&g0l6Pw-" //草稿箱
* LIST (\HasNoChildren) "/" "rubbishs" //垃圾箱
* LIST (\HasNoChildren) "/" "INBOX" //收件箱
Q4 OK List completed.
解释:
第一个参数为邮箱路径名(暂时没弄明白) 第二个参数为邮箱名
"*": 列出有层级关系的(包含子邮箱的) "%": 只列出本级邮箱名(不包含旗下的子邮箱)
LIST “” “rubbishs” 列出垃圾箱
这个命令式迅速返回的,没有任何延时或者其他标签性处理。
//同上
Q5 LSUB "" % || Q5 LSUB "" *
* LSUB () "/" "trash"
* LSUB () "/" "&XfJT0ZABkK5O9g-"
* LSUB () "/" "&g0l6Pw-"
* LSUB () "/" "rubbishs"
解释:
只显示SUBSCRIBE命令设置的邮箱(文件subscriptions中提到的邮箱名)
//给指定邮件添加标记
Q6 STORE 1 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Deleted \Seen))
Q6 OK Store completed.
Q7 STORE 1 +FLAGS (\Flagged)
* 1 FETCH (FLAGS (\Deleted \Seen \Flagged))
Q7 OK Store completed.
解释:mail-id:1是邮件编号并不是邮件的uid 这个一定要清楚,如果邮箱中有3封邮件,邮件编号就是1、2、3
//取邮件
Q8 FETCH 1 flags
* 1 FETCH (FLAGS (\Deleted \Seen))
Q9 FETCH 1 full
解释:FETCH的应用很复杂,用到那个说那个
//查询
Q10 SEARCH ALL
C: * SEARCH 1 2 3
S:q1 OK Search completed (0.000 secs).
C:A002 search CHARSET UTF-8 TEXT "aa" //搜索正文中包含aa的邮件
S:* SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 //返回邮件的UID
S:A002 OK Search completed (0.002 secs).
C:A003 search ALL UNSEEN //搜索所有该邮箱下未读邮件
S:* SEARCH 1 2 3 4 5 6 7 8 9 10 11
S:A003 OK Search completed (0.000 secs).
C:A004 search CHARSET UTF-8 HEADER subject "aa" //搜索该邮箱下邮件头包含aa的邮件
S:* SEARCH 10 //返回符合的邮件UID
S:A004 OK Search completed (0.000 secs).
C:A005 search CHARSET UTF-8 OR HEADER subject "aa" TEXT "aa" //搜索正文和主题包含aa的邮件
S:* SEARCH 1 2 3 4 5 6 7 8 9 10 11 //返回符合的邮件的UID
S:A005 OK Search completed (0.002 secs).
C:A006 search CHARSET UTF-8 HEADER from "aa" //搜索发件人中包含aa的邮件
S:* SEARCH //返回符合邮件的UID(该条没有符合条件的)
S:A006 OK Search completed (0.000 secs).
C:A007 search CHARSET UTF-8 HEADER to "aa" //搜索收件人中包含aa的邮件
S:* SEARCH //返回邮件的UID (该条没有符合条件的记录)
S:A007 OK Search completed (0.000 secs).
//拷贝
Q12 UID COPY 95 INBOX
Q12 UID COPY 95 INBOX
* 6 EXISTS
* 3 RECENT
解释:imap协议中没有move和delete命令,是通过命令组合实现的功能:
move: 1:copy到目的邮件夹
2:store id +flags (\Deleted)
3:expunge
彻底删除delete:
1:store id +flags (\Deleted)
2: expunge
删除到垃圾箱delete:
实际上是做move 如上的操作copy->trush
//上传邮件到邮箱
Q1 APPEND INBOX (\Seen) {310}
+OK
Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
From: Fred Foobar [email protected]
Subject: afternoon meeting
To: [email protected]
Message-Id: [email protected]
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Hello Joe, do you think we can meet at 3:30 tomorrow?
.
* 5 EXISTS
* 2 RECENT
Q1 OK [APPENDUID 1386399370 116] Append Completed
解释:
邮件头与邮件体之间是\r\n表示的;邮件一封邮件是以\r\n结束并必须加"."表示完成