Gestion des éléments de conversation

Aspose.Email pour Java peut être utilisé pour gérer les éléments de conversation sur Exchange Server avec le EWSClient classe. Cette classe utilise Exchange Web Services, qui ne sont disponibles que dans Exchange Server 2007 et les versions ultérieures. Cet article montre comment trouver, copier, déplacer et supprimer éléments de conversation sur Exchange Server 2010. Le Service Pack 1 d’Exchange Server 2010 est requis pour toutes les fonctionnalités de cette section.

Recherche de conversations

Pour obtenir les informations de conversation d’un dossier spécifique sur le serveur Exchange :

  1. Connectez-vous au serveur Exchange en utilisant la classe IEWSClient.
  2. Appelez la méthode IEWSClient.findConversations() pour trouver tous les éléments de conversation d’un dossier.
  3. Affichez les propriétés de l’élément de conversation comme l’ID, le sujet de la conversation et le statut du drapeau.

L’extrait de code suivant montre comment trouver des conversations.

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find Conversation Items in the Inbox folder
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
// Show all conversations
for (ExchangeConversation conversation : conversations) {
    // Display conversation properties like Id and Topic
    System.out.println("Topic: " + conversation.getConversationTopic());
    System.out.println("Flag Status: " + conversation.getFlagStatus());
    System.out.println();
}

Copie de conversations

Pour copier des conversations d’un dossier à un autre :

  1. Connectez-vous au serveur Exchange en utilisant la classe IEWSClient.
  2. Appelez la méthode IEWSClient.copyConversationItems() pour copier l’élément de conversation du dossier source vers le dossier de destination.

L’extrait de code suivant montre comment copier des conversations.

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to copy
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Copy the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email")) {
        client.copyConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
        System.out.println("Copied the conversation item to another folder");
    }
}

Déplacement de conversations

Pour déplacer des conversations d’un dossier à un autre :

  1. Connectez-vous au serveur Exchange en utilisant la classe IEWSClient.
  2. Appelez la méthode IEWSClient.moveConversationItems() pour déplacer une conversation du dossier source vers le dossier de destination.

L’extrait de code suivant montre comment déplacer des conversations.

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to move
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());

for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Move the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email") == true) {
        client.moveConversationItems(conversation.getConversationId(), client.getMailboxInfo().getDeletedItemsUri());
        System.out.println("Moved the conversation item to another folder");
    }
}

Suppression de conversations

Pour supprimer des conversations d’un dossier :

  1. Connectez-vous au serveur Exchange en utilisant la classe IEWSClient.
  2. Appelez la méthode IEWSClient.deleteConversationItems() pour supprimer l’élément de conversation du dossier source.

L’extrait de code suivant montre comment supprimer des conversations.

IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
System.out.println("Connected to Exchange 2010");

// Find those Conversation Items in the Inbox folder which we want to delete
ExchangeConversation[] conversations = client.findConversations(client.getMailboxInfo().getInboxUri());
for (ExchangeConversation conversation : conversations) {
    System.out.println("Topic: " + conversation.getConversationTopic());
    // Delete the conversation item based on some condition
    if (conversation.getConversationTopic().contains("test email") == true) {
        client.deleteConversationItems(conversation.getConversationId());
        System.out.println("Deleted the conversation item");
    }
}