邮件协议-IMAP

  • Connect:
telnet  143

openssl s_client -connect mail.qq.com:993 -crlf
  • Login/Logout:
A01 LOGIN username password
A01 OK LOGIN completed.

A01 LOGOUT
* BYE Microsoft Exchange Server 2013 IMAP4 server signing off.
A01 OK LOGOUT completed.
  • Capability:
A capability
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI UIDPLUS MOVE ID XPROXY3 CHILDREN IDLE NAMESPACE LITERAL+
A OK CAPABILITY completed.
  • Folder:
//CREATE 
//CREATE可以创建指定名字的新邮箱。邮箱名称通常是带路径的文件夹全名。(有些IMAP客户机使用邮件夹称呼新邮箱)
A003 CREATE owatagusiam/                 
A003 OK CREATE completed.

A004 CREATE owatagusiam/blurdybloop         
A004 OK CREATE completed.

//DELETE 
//DELETE命令删除指定名字的文件夹。文件夹名字通常是带路径的文件夹全名,当邮箱被删除后,其中的邮件也不复存在。
A683 DELETE blurdybloop
A683 OK DELETE completed.

A684 DELETE foo
A684 NO Name "foo" has inferior hierarchical names

A685 DELETE foo/bar
A685 OK DELETE Completed.

//RENAME 
//RENAME命令可以修改文件夹的名称,它使用两个参数:当前邮箱名和新邮箱名,两个参数的命名符合标准路径命名规则。
C: A683 RENAME blurdybloop sarasoop
S: A683 OK RENAME completed
C: A684 RENAME stuff/junk newbox        
S: A684 OK RENAME Completed
  • List of Folder:
//All Folder
A02 LIST "" *
* LIST (\HasChildren) "/" Folder
* LIST (\HasNoChildren) "/" Folder/Folder_1
* LIST (\HasNoChildren) "/" Folder/Folder_2
* LIST (\HasNoChildren) "/" &T797Og-
* LIST (\Marked \HasNoChildren) "/" &g0l6Pw-
* LIST (\HasNoChildren) "/" &U9FO9nux-
* LIST (\HasNoChildren) "/" &V4NXPpCuTvY-
* LIST (\HasChildren) "/" &gFR8+066-
* LIST (\HasNoChildren) "/" &TvtSoQ-
* LIST (\HasNoChildren) "/" &ZeWLsA-
* LIST (\HasNoChildren) "/" &ZeVThg-
* LIST (\Marked \HasNoChildren) "/" INBOX
* LIST (\Marked \HasNoChildren) "/" &XfJT0ZABkK5O9g-
* LIST (\Marked \HasNoChildren) "/" &XfJSIJZkkK5O9g-
A02 OK LIST completed.

//Children Folder:
A04 LIST "Folder" *
* LIST (\HasChildren) "/" Folder
* LIST (\HasNoChildren) "/" Folder/Folder_1
* LIST (\HasNoChildren) "/" Folder/Folder_2
A04 OK LIST completed.

//Like Folder:
A05 LIST "" "Fol*"
* LIST (\HasChildren) "/" Folder
* LIST (\HasNoChildren) "/" Folder/Folder_1
* LIST (\HasNoChildren) "/" Folder/Folder_2
A05 OK LIST completed.
  • LSUB
//SUBSCRIBE 
//SUBSCRIBE命令用来在客户机的活动邮箱列表中增加一个邮箱,该命令只有一个参数,希望添加的邮箱名。
A114 SUBSCRIBE new/anotherbox
A114 OK SUBSCRIBE completed

//UNSUBSCRIBE 
//UNSUBSCRIBE命令用来从活动列表中去掉一个邮箱,一个参数:希望去掉的邮箱名。
A115 UNSUBSCRIBE new/anotherbox
A115 OK SUBSCRIBE completed

//LSUB 
//LSUB命令修正了LIST命令,LIST返回用户$HOME目录下所有的文件,但LSUB命令只显示那些使用SUBSCRIBE命令设置为活动邮箱的文件。两个参数:邮箱路径和邮箱名。
A116 LSUB “” *
* LSUB () “/” stuff/junk
* LSUB () “/” neebox
* LSUB () “/” new/anotherbox
A116 OK LSUB completed
  • Status
A status inbox (messages)
* STATUS INBOX (messages 1051) 
A OK STATUS completed.

B STATUS INBOX (MESSAGES UNSEEN RECENT)
* STATUS INBOX (MESSAGES 1051 UNSEEN 0 RECENT 0) 
B OK STATUS completed.
  • Select Folder:
A03 SELECT INBOX
* 1051 EXISTS
* 1 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UIDVALIDITY 14] UIDVALIDITY value
* OK [UIDNEXT 14260] The next unique identifier value
A03 OK [READ-WRITE] SELECT completed.
  • CLOSE
//CLOSE命令表示Client结束对当前Folder(文件夹/邮箱)的访问,关闭邮箱该邮箱中所有标志为、DELETED的邮件就被从物理上删除。CLOSE没有命令参数。随后可以SELECT另一Folder。
A341 CLOSE
A341 OK CLOSE completed
  • Search:
//All uid
A01 Search ALL
* SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
A01 OK SEARCH completed.

//Recent uid
A02 Search NEW
* SEARCH 1052 1053
* 2 RECENT
A02 OK SEARCH completed.
  • Fetch:
//flags
A01 fetch 1:* FLAGS
* 1 FETCH (FLAGS (Seen))
* 2 FETCH (FLAGS (Seen))
* 3 FETCH (FLAGS (\Seen \Answered))
A01 OK FETCH complete.

//internal date
A02 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")
A02 OK FETCH complete

//uid
A03 fetch 1:* UID
* 1 FETCH (UID 32)
* 2 FETCH (UID 124)
* 3 FETCH (UID 165)
A03 OK FETCH completed.

//see more
A04 fetch 1:10 (UID FLAGS INTERNALDATE)  
* 1 FETCH (UID 32 FLAGS (\Seen) INTERNALDATE "29-Aug-2017 17:32:54 +0800")
* 2 FETCH (UID 124 FLAGS (\Seen) INTERNALDATE "30-Sep-2017 12:09:21 +0800")
* 3 FETCH (UID 165 FLAGS (\Seen) INTERNALDATE "30-Sep-2017 17:29:21 +0800")
A04 OK FETCH completed.

//Header of index 5 
A06 Fetch 5 full
* 5 FETCH (INTERNALDATE "27-Jun-2006 14:00:27 +0800" FLAGS (/Seen) ENVELOPE ("Tue, 27 Jun 2006 13:56:51 +0800" "test " (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) (("xxxxxx" NIL "xxxx" "xxxxxx")) ((NIL NIL "xxx" "xxxxx")) NIL NIL NIL "<[email protected] >") BODY (("text" "plain" ("charset" "gb2312") NIL NIL "base64" 14 2) ("text" "html" ("charset" "gb2312") NIL NIL "base64" 420 7) "alternative") RFC822.SIZE 1396)
A06 OK Fetch completed.

//Index 5 completed content
A07 Fetch 5 rfc822
* 5 FETCH (RFC822 {1396}
....
A07 OK Fetch completed.

//Index 5 flags
* 5 FETCH (FLAGS (\Seen))
* 3 RECENT
A08 OK FETCH completed.

//Header
A09 fetch 1 body[header]
* 1 FETCH (BODY[HEADER] {1316}
Return-Path: 
... email ...
A09 OK FETCH complete.

//index range header
A10 fetch 1:* body[header]
Return-Path: 
... email ...
Return-Path: 
... email ...
Return-Path: 
... email ...
A09 OK FETCH complete.

//Show(from、to、subject、date)
A10 fetch 1:1 (body[header.fields (from to subject date)])
* 1 FETCH (BODY[HEADER.FIELDS (from to subject date)] {183}
From: IT 
To: AllStaff 
Subject:
    =?gb2312?B?udjT2rmry77Tyrz+zfi52L38xtq/qsb0U1BGvMfCvLzssum5psTczajWqg==?=
Date: Tue, 29 Aug 2017 17:30:40 +0800

 FLAGS (\Seen))
A10 OK FETCH completed.

//Showing subject
a fetch 1:1 (body[header.fields (subject)])
* 1 FETCH (BODY[HEADER.FIELDS (subject)] {88}
Subject:
    =?gb2312?B?udjT2rmry77Tyrz+zfi52L38xtq/qsb0U1BGvMfCvLzssum5psTczajWqg==?=

 FLAGS (\Seen))
a OK FETCH completed.
  • Noop:
A01 noop
A01 OK NOOP completed.
  • Set
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)

//STORE 
//STORE 命令用于修改指定邮件的属性,包括给邮件打上已读标记、删除标记,等等。STORE命令当前只有两个数据项类型可用,FLAGS:表示邮件的一组标志; FLAGS.SLIENT,表示一组邮件的标志,通过在两种数据项前加上加号或者减号可以进一步改变它们的执行情况,加号表示数据项的值添加到邮件中,减号表示将数据项的值从邮件中删除。
A003 STORE 2:4 +FLAGS (\Deleted)     
* 2 FETCH FLAGS (\Deleted \Seen)
* 3 FETCH FLAGS (\Deleted)
* 4 FETCH FLAGS (\Deleted \Flagged \Seen)
A003 OK STORE completed
  • 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.
A01 expunge
* 2 EXPUNGE
A01 OK EXPUNGE complete.

你可能感兴趣的:(邮件协议-IMAP)