[英]C# MailKit get messages conversation/replies inside treeview
i'm trying to replicate the view of a mailbox, i try to use references and threads but don't work, somethimes thread has uniqueid null. 我正在尝试复制邮箱视图,我尝试使用引用和线程,但是不起作用,somethimes线程的uniqueid为null。
foreach (var rfr in Message.References ?? new MimeKit.MessageIdList())
{
var _uids = Imap.Inbox.Search(SearchQuery.HeaderContains("Message-Id", rfr));
if (_uids.Count > 0)
{
var _messages = Imap.Inbox.Fetch(_uids.ToList(), MessageSummaryItems.Envelope | MessageSummaryItems.Flags).OrderByDescending(o => o.Date);
foreach (var msg in _messages)
{
_Added.Add(msg.UniqueId);
RequestModel _model = new RequestModel
{
Address = msg.Envelope.From.Mailboxes.FirstOrDefault().Name ?? msg.Envelope.From.Mailboxes.FirstOrDefault().Address,
Subject = msg.Envelope.Subject,
Date = msg.Date.ToLocalTime().ToString(),
IsSeen = msg.Flags.Value.HasFlag(MailKit.MessageFlags.Seen),
Childs = new List<Scratch.MainWindow.RequestModel>(),
};
_retValue.Add(_model);
}
}
}
var _messages = _imapClient.Inbox.Fetch(_uids.ToList(), MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.References).OrderByDescending(o => o.Date).Take(50);
var _threads = MessageThreader.Thread(_messages, ThreadingAlgorithm.References);
The MessageThreader
class uses the References
(which contin a list of Message-Id
values tracing back to the root of the thread) in order to construct the tree of messages. MessageThreader
类使用References
(该References
继承了追溯到线程根的Message-Id
值列表)来构造消息树。 Obviously, if the list of message summaries that you give to the MessageThreader
are missing some of those references, then the returned tree will have some empty nodes. 显然,如果您提供给
MessageThreader
的消息摘要列表缺少某些引用,则返回的树将具有一些空节点。 This is why some of said nodes have a null
UniqueId
value. 这就是为什么某些所述节点具有
null
UniqueId
值的原因。
FWIW, a few tips for you: FWIW,为您提供一些技巧:
Don't do _uids.ToList()
- _uids
is already an IList<UniqueId>
, why duplicate it for no reason? 不要执行
_uids.ToList()
_uids
已经是IList<UniqueId>
,为什么无故重复它?
It's more efficient to use the orderBy
argument to MessageThreader
. 使用
MessageThreader
的orderBy
参数更有效。
Like this: 像这样:
var orderBy = new OrderBy[] { OrderBy.ReverseDate };
var threads = MessageThreader.Thread (summaries, ThreadingAlgorithm.References, orderBy);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.