在 IMAP 服务器上设置、更改和删除消息标志
Contents
[
Hide
]
设置/更改消息标志
您可以通过使用以下方法设置新的标志来更改消息标志 ChangeMessageFlags() 方法。此方法接受两个参数。
- 消息的序列号或其唯一标识符。
- MessageFlag.
可以设置以下标记:
以下代码片段展示了如何使用 Aspose.Email 在 IMAP 服务器上更改消息标记。
// Mark the message as read
client.ChangeMessageFlags(1, ImapMessageFlags.IsRead);
移除邮件标记
也可以使用该方式移除消息标记 RemoveMessageFlags() 方法。用法类似于 ChangeMessageFlags() 方法。它接受序列号或唯一消息 ID 并 MessageFlag以下代码片段展示了如何移除消息标记。
// Remove the message flag
client.RemoveMessageFlags(1, ImapMessageFlags.IsRead);
设置自定义标志
您也可以使用该方式为消息设置自定义标记 ImapClient API 的一部分。ImapClient 的 AddMessageFlags 提供了在消息上设置自定义标志的能力。
// Create a message
MailMessage message = new MailMessage("user@domain1.com", "user@domain2.com", "subject", "message");
//Append the message to mailbox
string uid = client.AppendMessage(ImapFolderInfo.InBox, message);
//Add custom flags to the added messge
client.AddMessageFlags(uid, ImapMessageFlags.Keyword("custom1") | ImapMessageFlags.Keyword("custom1_0"));
//Retreive the messages for checking the presence of custom flag
client.SelectFolder(ImapFolderInfo.InBox);
ImapMessageInfoCollection messageInfos = client.ListMessages();
foreach (var inf in messageInfos)
{
ImapMessageFlags[] flags = inf.Flags.Split();
if (inf.ContainsKeyword("custom1"))
Console.WriteLine("Keyword found");
}