说明
本文是 node-imap-sync-client imap客户端库的使用方案
分为, 同步用 和 快速显示用
https://blog.csdn.net/eli960/article/details/146049717
主要用于同步
首先, 建立连接
// 创建对象
let ic = new imapSyncClient({
host,
port,,
ssl,
user,
pass,
startTLS,
})
ic.setDebugMode()
// open,包括 连接,STARTTLS,认证,ID,CAPABILITY 等
if (!await ic.open()) {
console.error("imap connect, error: ", ic.getLastReadedBuffer().toString())
return
}
console.log("connect, success")
第一步, 获取文件夹列表
// 获取最详细的信息
await ic.getAllMboxInfos()
// 或者, 获取基本的列表
await ic.getMboxList()
第二步, 遍历每个文件夹,获取邮件的UID列表
注意: 同一个文件夹下, UID递增, 一封邮件的UID是不变的
// select 文件夹
await ic.selectMbox("inbox")
// 获取 UID 列表,和 标记(已读,星标等)
await ic.fetchUidListWithFlags()
第三步, 按 UID 获取 信件原始数据
await ic.fetchMailData(...)
主要用于快速显示
第一步和第二步 和 上面的相同
第三步, 根据需要显示的邮件的UID获取信封信息
用于快速显示,主题/发件人/收件人/已读/星标等信息
await ic.fetchMailEnvelope()
第四步, 根据UID显示具体的信件
// 获取详细信息
await.fetchMailInfo()
// 或者分步获取信封和结构
await ic.fetchMailEnvelope()
await ic.fetchMailStructure()
返回的结构信息的属性
export type BodyStructure = {
textMimes: MimeNode[], // 文本可读可显示的节点
showMimes: MimeNode[], // 如上, 且首先需要显示的
attachmentMimes: MimeNode[], // 附件类节点
topMime: MimeNode,
}
根据 showMimes, 显示正文
根据 attachmentMimes, 显示内嵌附件, 或现在附件
1111

被折叠的 条评论
为什么被折叠?



