Praca z flagami wiadomości na serwerze

Zmiana flag wiadomości

Możesz zmienić flagi wiadomości, używając changeMessageFlags() metoda. Ta metoda przyjmuje dwa parametry.

  1. Numer sekwencyjny wiadomości lub unikalny identyfikator.
  2. MessageFlag.

Można ustawić następujące flagi:

Ustawianie flag wiadomości

Poniższy fragment kodu pokazuje, jak zmienić flagi wiadomości na serwerze IMAP przy użyciu Aspose.Email.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// 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.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// Remove the message flag
client.removeMessageFlags(1, ImapMessageFlags.isRead());

Ustawianie własnych flag

Możesz również ustawić własne flagi dla wiadomości używając ImapClient z API. The ImapClient AddMessageFlags umożliwia ustawianie własnych flag na wiadomościach.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// 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.IN_BOX, message);

// Add custom flags to the added messge
client.addMessageFlags(uid, com.aspose.email.ImapMessageFlags.op_BitwiseOr(ImapMessageFlags.keyword("custom1"), ImapMessageFlags.keyword("custom1_0")));

// Retreive the messages for checking the presence of custom flag
client.selectFolder(ImapFolderInfo.IN_BOX);

ImapMessageInfoCollection messageInfos = client.listMessages();
for (ImapMessageInfo inf : messageInfos) {
    ImapMessageFlags[] flags = inf.getFlags().split();

    if (inf.containsKeyword("custom1"))
        System.out.println("Keyword found");
}