Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3758|回复: 1
打印 上一主题 下一主题

imap邮件同步原理

[复制链接]

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
跳转到指定楼层
楼主
发表于 2016-9-6 09:47:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 hechengjin 于 2016-9-6 11:14 编辑

------thunderbird---------
139账号测试
3 login "15388888888" "xxx"
3 OK login completed

6 list "" "*"
* LIST () "/" "INBOX"
* LIST (\Drafts) "/" "&g0l6P3ux-"
* LIST (\Sent) "/" "&XfJT0ZAB-"
* LIST (\Trash) "/" "&XfJSIJZk-"
* LIST (\Junk) "/" "&V4NXPpCuTvY-"
* LIST () "/" "&YhF2hA-"
* LIST () "/" "&YhF2hA-/11"
6 OK list completed


11 select "INBOX"
* 19 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UIDs valid
* FLAGS (\Answered \Seen \Deleted \Draft)
* OK [PERMANENTFLAGS (\Answered \Seen \Deleted \Draft)] Limited
11 OK [READ-WRITE] select completed

//根据序号获取所有UID
12 UID fetch 1:* (FLAGS)
* 1 FETCH (UID 1 FLAGS (\Seen))
* 2 FETCH (UID 2 FLAGS (\Seen))
* 3 FETCH (UID 7 FLAGS (\Seen \Answered))
* 4 FETCH (UID 9 FLAGS (\Seen))
* 5 FETCH (UID 12 FLAGS (\Seen))
* 6 FETCH (UID 13 FLAGS (\Seen))
* 7 FETCH (UID 15 FLAGS (\Seen))
* 8 FETCH (UID 20 FLAGS (\Seen))
* 9 FETCH (UID 21 FLAGS (\Seen))
* 10 FETCH (UID 22 FLAGS (\Seen))
* 11 FETCH (UID 23 FLAGS (\Seen))
* 12 FETCH (UID 27 FLAGS (\Seen))
* 13 FETCH (UID 28 FLAGS (\Seen))
* 14 FETCH (UID 30 FLAGS (\Seen))
* 15 FETCH (UID 32 FLAGS (\Seen))
* 16 FETCH (UID 239 FLAGS (\Seen))
* 17 FETCH (UID 539 FLAGS (\Seen))
* 18 FETCH (UID 540 FLAGS (\Seen))
* 19 FETCH (UID 541 FLAGS (\Seen))
12 OK Fetch completed


//根据UID获取邮件头相关字段信  这里的序号是从小到大,所以收信顺序就是先收老邮件再收新邮件 ---把所有邮件头都收取了下来
13 UID fetch 1:2,7:541 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)])
* 1 FETCH (UID 1 FLAGS (\Seen) RFC822.SIZE 3901 BODY[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)] {405}
From: mail139 <mail139@139.com>
To: 15313159857 <15313159857@139.com>
Subject: =?UTF-8?B?5Lqy54ix55qE55So5oi377yM5bCP57yW57uZ5oKo5LuL57uN6YKu566x5L2/55So5bCP55+l6K+G5ZWm77yB?=
Date: Sat, 14 Nov 2015 23:43:23 +0800 (CST)
Message-ID: <2b2c55e24466c1c-06de6.Richmail.00003040608096963097@139.com>
X-Priority: 3
Content-Type: multipart/alternative; boundary="----=_Part_432_1817293019.1447515803834"


)
* 2 FETCH (UID 2 FLAGS (\Seen) RFC822.SIZE 4356 BODY[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)] {369}
From: hcj <hechengjin88@sina.com>
To: 15313159857@139.com
Subject: =?UTF-8?B?RndkOiBGd2Q6IGFhYWFhYWFhYWFh?=
Date: Sat, 14 Nov 2015 23:46:33 +0800
Message-ID: <56475759.8060309@sina.com>
References: <56474FB7.4060807@kingsoft.com>
In-Reply-To: <56474FB7.4060807@kingsoft.com>
Content-Type: multipart/alternative;boundary="------------000905020206030002050602"


)
* 3 FETCH (UID 7 FLAGS (\Seen \Answered) RFC822.SIZE 1038 BODY[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)] {332}
From: hcj <hechengjin88@sina.com>
To: 139 <15313159857@139.com>
Subject: =?UTF-8?B?UmU6IOS8muivnea1i+ivlTE=?=
Date: Sat, 05 Dec 2015 18:19:31 +0800
Message-ID: <5662BA33.3080708@sina.com>
References: <5662BA1F.9070402@139.com>
In-Reply-To: <5662BA1F.9070402@139.com>
Content-Type: text/plain; charset=UTF-8; format=flowed


)

........省略n个


* 19 FETCH (UID 541 FLAGS (\Seen) RFC822.SIZE 40491 BODY[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)] {319}
From: 3281571787 <3281571787@qq.com>
To: ioswpstest123 <ioswpstest123@163.com>
Subject: =?UTF-8?B?57uP5YW45Z+6552j5pWZ?=
Date: Thu, 21 Apr 2016 14:26:49 +0800
Message-ID: <727q7q2h70u4m0sf89es7gi5.1461220009998@email.kingsoft.com>
Content-Type: multipart/mixed; boundary="--_com.kingsoft.email_625497412866570"

)
13 OK Fetch completed

//根据UID 收取某些邮件的邮件体
14 UID fetch 23,27:28,30,32,239,539,541 (UID RFC822.SIZE BODY.PEEK[])

* 11 FETCH (UID 23 RFC822.SIZE 3134 BODY[] {3134}
X-Richmail-Antispam: sCL2rVi0borhSzeOjpgspNVjVikRHTFk2JnCCts2acblSkRHTBg1cg==                     
X-RM-SPAM-FLAG:00000000
Received:from smtpbg321.qq.com (unknown[14.17.32.30])
.by rmmx-cloud_rmmx_9_12-12071 (RichMail) with SMTP id 2f27569a2b89d5c-38ad1;
.Sat, 16 Jan 2016 19:37:46 +0800 (CST)
X-RM-TRANSID:2f27569a2b89d5c-38ad1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512;
.t=1452944205; bh=VPPg+1IiMPl6Ki8iUPObomZplx15o5xyqiLZ1EhaHAs=;
.h=Message-IDate:From:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding;
.b=VMxIUHVWq0oSvI6KGyACUnRMHXxo+ZSgOIpoHsxfw/qxqRt0AHmh0/2TDoMAT91k6
. oAh5nKhCNIyKpe1Keh/uxYkuzhwZi4sMBXtiD/8ftRNZSd3YkEyKT1q84XrkygMuB1
. oVG20Eko5zhRG2Q8SCr041vBsP1ZOoGIvDAXKVog=
X-QQ-mid: esmtp31t1452944205t014t13426
Received: from [192.168.134.107] (unknown [114.255.44.132])
.by esmtp4.qq.com (ESMTP) with SMTP id 0
.for <15313159857@139.com>; Sat, 16 Jan 2016 19:36:44 +0800 (CST)
X-QQ-SSF: 00010000000000F0F3100F00000000Z
X-QQ-FEAT: fRZXSXmk0O3vJYaxGUipko31JqUPgMWI2h8o6BqWPWmvOGCeJUfzW/z28sLWF
.dn3ohdSrp8M5OaOg2KmCrYQ2hwW8ikzTqZBTCafauL3+nkQkJY5qrbVUJTgDAZU9rBgM129
.XnLOTsE/lK2yaDaFLAOlKn6ZDpeMTBxwoPX89kvqn+fDhP87JG4bZw5brCTJhNu0ZwqAqeQ
.qQnouYgQQ3/V7DxSHIXRTFZWWalYaMukujQ2TGN9AZNMbYwIcKhi54Go5hND+JC4=
X-QQ-GoodBg: 2
Message-ID: <569A2B4C.3040707@qq.com>
Date: Sat, 16 Jan 2016 19:36:44 +0800
From: qq <254452118@qq.com>
User-Agent: Firemail/1.0.0
MIME-Version: 1.0
To: 15313159857@139.com
Subject: =?UTF-8?B?5L2/55SocGdw6L+b6KGM5Yqg5a+G5ZKM562+5ZCN?=
X-Enigmail-Version: 1.6
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-QQ-SENDSIZE: 520




-----BEGIN PGP MESSAGE-----
Charset: UTF-8
Version: GnuPG v2
Comment: Using GnuPG with Firemail - http://www.enigmail.net/
=20
hQEMA1k6f2toECwcAQf+M8Z7an4Io3po3af9n+GkIpwzPAdBIwFBrsu9SYYYqOkh
/C4EH7Z6rwFl3PQCVghbYVakp3vnSY7VH1T78ui6bgOTi22sWmNxt+DwC/tar03p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xppDW9i12sm2RNyOYYc8vjkp6OUkVhwfI/hZZ8swizcQPhSEW
nNC9HOSxheT/2g=3D=3D
=3DfLUd
-----END PGP MESSAGE-----




)

....省略n个邮件体


//再收取某些邮件体 ----与界面的操作相关?
15 UID fetch 1 (UID RFC822.SIZE BODY[])
....
16 UID fetch 2 (UID RFC822.SIZE BODY[])
....




-----foxmail------------
139账号测试
C2 LOGIN "15388888888" "xxx"
C2 OK LOGIN completed
C3 CAPABILITY
* CAPABILITY IMAP4rev1 XLIST
C3 OK CAPABILITY completed
C4 LIST "" *
* LIST () "/" "INBOX"
* LIST (\Drafts) "/" "&g0l6P3ux-"
* LIST (\Sent) "/" "&XfJT0ZAB-"
* LIST (\Trash) "/" "&XfJSIJZk-"
* LIST (\Junk) "/" "&V4NXPpCuTvY-"
* LIST () "/" "&YhF2hA-"
* LIST () "/" "&YhF2hA-/11"
C4 OK LIST completed

//所有邮件夹的状态
C7 STATUS "INBOX" (MESSAGES RECENT UIDVALIDITY)
* STATUS "INBOX" (MESSAGES 19 RECENT 0 UIDVALIDITY 1 )
C7 OK STATUS completed



C16 SELECT "INBOX"
* 19 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1] UIDs valid
* FLAGS (\Answered \Seen \Deleted \Draft)
* OK [PERMANENTFLAGS (\Answered \Seen \Deleted \Draft)] Limited
C16 OK [READ-WRITE] SELECT completed



//根据序号获取所有UID
C17 FETCH 1:19 (UID)
* 1 FETCH (UID 1)
* 2 FETCH (UID 2)
* 3 FETCH (UID 7)
* 4 FETCH (UID 9)
* 5 FETCH (UID 12)
* 6 FETCH (UID 13)
* 7 FETCH (UID 15)
* 8 FETCH (UID 20)
* 9 FETCH (UID 21)
* 10 FETCH (UID 22)
* 11 FETCH (UID 23)
* 12 FETCH (UID 27)
* 13 FETCH (UID 28)
* 14 FETCH (UID 30)
* 15 FETCH (UID 32)
* 16 FETCH (UID 239)
* 17 FETCH (UID 539)
* 18 FETCH (UID 540)
* 19 FETCH (UID 541)
C17 OK Fetch completed


//根据UID获取邮件头相关字段信  这里的序号也是从小到大,所以收信顺序就是先收老邮件再收新邮件? ---把所有邮件头都收取了下来
C18 UID FETCH 1:2,7,9,12:13,15,20:23,27:28,30,32,239,539:541 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER])
* 1 FETCH (UID 1 FLAGS (\Seen) RFC822.SIZE 3901 BODY[HEADER] {767}
X-RM-SPAM-FLAG: 00000000
Received: from mail139@139.com ( [172.16.210.52] )
.by ajax-webmail-cmudms-4-17-11052 (Richmail) with HTTP; Sat, 14 Nov 2015 23:43:23 +0800 (CST)
Date: Sat, 14 Nov 2015 23:43:23 +0800 (CST)
From: mail139 <mail139@139.com>
To: 15313159857 <15313159857@139.com>
Message-ID: <2b2c55e24466c1c-06de6.Richmail.00003040608096963097@139.com>
Subject: =?UTF-8?B?5Lqy54ix55qE55So5oi377yM5bCP57yW57uZ5oKo?=
=?UTF-8?B?5LuL57uN6YKu566x5L2/55So5bCP55+l6K+G5ZWm77yB?=
MIME-Version: 1.0
Content-Type: multipart/alternative;
.boundary="----=_Part_432_1817293019.1447515803834"
X-Priority: 3
X-RM-TRANSID: 2b2c55e24466c1c-06de6
X-RM-OA-ENC-TYPE: 0
X-CLIENT-INFO: X-TIMING=0&X-MASSSENT=0&X-SENSITIVE=0
X-Mailer: Richmail_Webapp(V1.8.7)A001


)

.....省略n条



//一条条先收取最新的邮件体?
C9 UID FETCH 541 (UID BODY.PEEK[])
...
C10 UID FETCH 541 (UID FLAGS)
* 19 FETCH (UID 541 FLAGS (\Seen))
C10 OK Fetch completed
C14 UID FETCH 540 (UID BODY.PEEK[])
...
C15 UID FETCH 540 (UID FLAGS)
* 18 FETCH (UID 540 FLAGS (\Seen))
C15 OK Fetch completed



.....
C94 UID FETCH 2 (UID BODY.PEEK[])
C95 UID FETCH 2 (UID FLAGS)

C99 UID FETCH 1 (UID BODY.PEEK[])
C100 UID FETCH 1 (UID FLAGS)



回复

使用道具 举报

388

主题

602

帖子

2218

积分

金牌会员

Rank: 6Rank: 6

积分
2218
沙发
 楼主| 发表于 2016-9-6 11:18:03 | 只看该作者
根据UID对比后,对应的收取 邮件头 、邮件体、 FLAGS
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-11-26 02:03 , Processed in 0.063844 second(s), 18 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表