FolderInfo.deleteChildItem throwing exception

Hi,

I have the following piece of code:

for (int k = 0; k < messageInfoCollection.size(); k++)
{
MessageInfo messageInfo = (MessageInfo) messageInfoCollection.get_Item(k);
MapiMessage message = pst.extractMessage(messageInfo);

String bsId = message.getHeaders().getDecodedValue(“X-MSGID”);

if (bsId.equals(it_local.id))
{
console.println(Console.output, “DELETED_EMAIL||” + folder.fullPath + “||” + pstFile.FormatSubject(it_local.subject));

  targetFolder.deleteChildItem(messageInfo.getEntryId());
  break;

}

message.dispose();
}

When running it, it deletes the message from folder, but also throws the following exception:

Could not read message. The message data is probably corrupted.

What can I do to avoid this exception?

Thanks

Hi,

I found the solution, it was my fault.
After deleting the message, I have to call this function again to rebuild messageInfoCollection:

messageInfoCollection = targetFolder.getContents();

Thanks for your attention

@kelberuc

It’s good to know that things are resolved on your end. Please feel free to contact us if you have any further inquiry in this regard.