IMAP同步 [英] IMAP synchronization

查看:132
本文介绍了IMAP同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现IMAP客户端,但是IMAP邮箱同步存在问题.

I'm implementing a IMAP client, and I have a problem with IMAP mailbox synchronization.

首先,可以从IMAP服务器获取新邮件,但是我不知道如何从邮箱中查找已删除的邮件.

First, it is okay to fetch new mails from IMAP server, but I don't know how to find deleted messages from a mailbox.

我应该从服务器获取所有消息并将其与本地数据进行比较以进行同步吗?

Should I fetch all messages from the server and compare it with local data to synchronize?

推荐答案

通常的方法是为每个文件夹执行以下两个IMAP命令:

The usual approach is to execute the following two IMAP commands for each folder:

. EXAMINE "<foldername>"
. FETCH 1:* (UID FLAGS)

第一个命令选择一个文件夹,并返回该文件夹的 UIDVALIDITY .如果此值与该文件夹先前返回的 UIDVALIDITY 相匹配,则可以依赖 UIDs .第二个命令为选定文件夹中的每个邮件至少返回 UID 和所有 FLAGS .

The first command selects a folder and returns the UIDVALIDITY of this folder. If this value matches the previously returned UIDVALIDITY for this folder, you can rely on the UIDs. The second command returns (at least) the UID and all FLAGS for each mail in the selected folder.

  • 您应该使用 UID 来检测已添加或删除的邮件.请注意,如果不更改 UID ,则不能更改电子邮件的内容.
  • 在基本IMAP中, FLAGS 是唯一可以更改电子邮件的属性.这些标志包含有关已读邮件(\Seen)和已删除邮件(\Deleted)的信息.
  • You should use the UID to detect which mails have been added or removed. Note that the content of an email can not be changed without also changing the UID.
  • In basic IMAP, the FLAGS are the only attributes that can be changed for an email. The flags contain information about read mails (\Seen) and deleted mails (\Deleted).

许多IMAP客户端都使用此方法,并且大多数IMAP服务器都针对它们进行了优化.限制因素通常是客户端和服务器之间的可用网络带宽.

This approach is used by many IMAP clients, and most IMAP servers are optimized for them. The limiting factor is usually the available network bandwidth between client and server.

以下情况更加复杂:

  • 如果 UIDVALIDITY 不匹配,该怎么办? IMAP规范要求服务器尽最大努力避免对此值进行不必要的更改.
  • 是否应该对移动的邮件(实际复制的邮件)进行优化?在基本IMAP中,无论源文件夹中的电子邮件仍然存在还是已经被删除和清除,您都无法检测到该电子邮件是另一封电子邮件的副本.
  • What should be done if UIDVALIDITY does not match? The IMAP specification requires that servers do their best to avoid unnecessary changes to this value.
  • Should there be an optimization for moved mails (actually copied mails)? In basic IMAP, you can not detect that an email is a copy of another email - regardless whether the email in the source folder still exists or whether it has already been deleted and expunged.

这篇关于IMAP同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆