Ustawianie, zmiana i usuwanie flag wiadomości na serwerze IMAP
Ustaw/Zmień flagi wiadomości
Możesz zmienić flagi wiadomości, ustawiając nowe przy użyciu ChangeMessageFlags() metoda. Ta metoda przyjmuje dwa parametry.
- Numer kolejny wiadomości lub jej unikalny identyfikator.
- MessageFlag.
Można ustawić następujące flagi:
Poniższy fragment kodu pokazuje, jak zmienić flagi wiadomości na serwerze IMAP przy użyciu Aspose.Email.
// Mark the message as read
client.ChangeMessageFlags(1, ImapMessageFlags.IsRead);
Usuwanie flag wiadomości
Flagi wiadomości można również usunąć za pomocą RemoveMessageFlags() metoda. Użycie jest podobne do ChangeMessageFlags() metoda. Przyjmuje numer sekwencyjny lub unikalny identyfikator wiadomości i MessageFlag. Poniższy fragment kodu pokazuje, jak usunąć flagi wiadomości.
// Remove the message flag
client.RemoveMessageFlags(1, ImapMessageFlags.IsRead);
Ustaw własne flagi
Możesz również ustawić własne flagi dla wiadomości używając ImapClient API. ImapClient AddMessageFlags umożliwia ustawianie własnych flag na wiadomościach.
// 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");
}