【问题标题】:Using mailkit to retrieve email chains, returns only the first email of the conversation使用 mailkit 检索电子邮件链,仅返回对话的第一封电子邮件
【发布时间】:2020-04-09 22:28:55
【问题描述】:

我正在使用 mailkit 开发一个电子邮件客户端。我需要将电子邮件显示为对话,就像它在网络邮件客户端中的显示方式一样。当我尝试使用 mailkit 获取完整电子邮件线程的数据时,我只能检索对话的第一封电子邮件。

我已经使用 mailkit 检查了 ImapCapabilitites.Thread 的值,它返回 false。所以我试图获取一个包含 3 条消息的电子邮件线程,我只得到第一条消息作为输出,并且线程对象的子项计数始终为零。请检查下面的代码,如果我缺少任何需要传递的标志,请告诉我

var summaries = targetFolder.Fetch(requestFilter, MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.References); 
var orderBy = new OrderBy[] { OrderBy.ReverseDate };
var threads = MessageThreader.Thread (summaries, ThreadingAlgorithm.References, orderBy);

其中requestFilterIList<UniqueId>targetFolder 是收件箱内存储邮件线程的子文件夹。

【问题讨论】:

  • targetFolder.Fetch() 中返回了多少条消息?它是否包含线程中的所有消息?我猜它不是从它的声音。请记住,所有 MessageThreader.Thread() 所做的只是将属于同一“对话”的消息分组在一起,它不会再去获取它们。
  • targetFolder.Fetch() 中只返回一条消息,因为我在 requestFilter 中只有一个 uniqueId。
  • MessageThreader.Thread() 至少需要对话中的所有消息。如果你只给它 1 条消息,它只能返回 1 条带有 0 个孩子的消息。

标签: c# .net mailkit mimekit


【解决方案1】:

一般来说,您需要所有条消息才能正确地串接它们。

所以你的代码应该是这样的:

var summaries = targetFolder.Fetch(0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.InternalDate | MessageSummaryItems.Envelope | MessageSummaryItems.References); 
var orderBy = new OrderBy[] { OrderBy.ReverseDate };
var threads = MessageThreader.Thread (summaries, ThreadingAlgorithm.References, orderBy);

您也不需要Flags 来对它们进行线程化,但由于您是按Date 排序的,因此如果邮件的Date 标头不是设置。

【讨论】:

  • 按照建议,我使用了您的代码而不是我的代码。摘要将目标文件夹中可用的所有 5 个电子邮件线程作为 MessageSummary 对象返回,但线程返回 5 个 MessageThread 对象,所有这些对象都返回 Children 0 和 UniqueId {0}。
  • 抱歉,您还需要MessageSummaryItems.UniqueId 以确保每个线程节点的 UniqueId 不为 0。我必须查看每个 MessageSummary 中包含的实际信息才能告诉您为什么线程算法不是t 以您期望的方式处理事情。
  • 因为我为银行客户工作,所以我无法发布我的监视窗口的照片。添加 UniqueId 标志后,我得到了线程中预期的 UniqueId 值,但仍为 0。您能否告诉 MessageSummary 中您需要哪些字段数据。
  • 我需要MessageSummary.Envelope.InReplyTo 值和MessageSummary.References 值。
  • MessageSummary.Envelope.InReplyTo 为 null,MessageSummary.References 为 {},计数为 0
猜你喜欢
  • 2015-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多