We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting Error when Extracting Messages from PST File

When attempting to extract messages from a PST file we are getting the following error:

class com.aspose.email.system.exceptions.InvalidOperationException: Could not read message. The message data is probably corrupted. —> class com.aspose.email.system.exceptions.ArgumentNullException: Could not find the data block by its identifier.
Parameter name: entry
com.aspose.email.zaqn.b(SourceFile:318)
com.aspose.email.zaqn.d(SourceFile:1360)
com.aspose.email.zzm.h(SourceFile:526)
com.aspose.email.zzm.(SourceFile:98)
com.aspose.email.zavq.(SourceFile:66)
com.aspose.email.zahr.a(SourceFile:328)
com.aspose.email.zavz.b(SourceFile:347)
com.aspose.email.zavz.a(SourceFile:305)
com.aspose.email.PersonalStorage.extractMessage(SourceFile:691)
com.aspose.email.PersonalStorage.extractMessage(SourceFile:707)

This should also reproduce with Aspose sample code for message extraction. A sample file has been provided.erosenfeld@DTISandbox.onmicrosoft.com.zip (3.8 MB)

1 Like

@dmckinney,
Thank you for the issue description. To help you, we need to know the following:

  • The code example reproducing the error
  • The version of Aspose.Email you used

But first, please check the issue with the latest version of Aspose.Email.

I am attaching an another sample file and sample project that we used to replicate the issue. The version we used of Aspose.Email are 21.2. and 21.3. <a class=“attachment” href="/uploads/discoursExtractPst.zip (879 Bytes)
e_instance3/50443">AsposeTicket.zip (8.5 MB)

@dmckinney,
Unfortunately, your AsposeTicket.zip file has not been uploaded. Please try again.

AsposeTicket.zip (8.5 MB)
Upload of AsposeTicket.zip

@dmckinney,
Thank you for the additional data. I reproduced the error and got the same result. I’ve logged the issue in our tracking system with ID EMAILJAVA-34872. Our development team will investigate this case. You will be notified when it is fixed.

Hello @Andrey_Potapov, is there any news on this issue?

Thanks,
Aaron

@aweech,
I requested an estimated time to fix this issue from our development team. I will let you know as soon as possible.

@Andrey_Potapov , have you heard anything?

@aweech,
Our development team has investigated the issue. The exception occurs because some data in the source file is corrupted. We explored the possibility to recover corrupted data, but it did not bring any results. Now we are testing the file with new API methods that allow reading without throwing exceptions, skipping the corrupted data. This API will be available in version 21.8 (closer to the beginning of September).

@Andrey_Potapov Thank you for the update. Will there be a way to still report on the corrupted data with the new API?

@aweech,
I requested this information from our development team. I will let you know soon.

@aweech,
Our developers confirmed such a capability to detect corrupted data with the new API.

The issues you have found earlier (filed as EMAILJAVA-34872) have been fixed in this update.

@dmckinney, @aweech,
With Aspose.Email 21.8, you can extract all PST items without throwing out exceptions, even if some data of the original file is corrupted. Code snippet:

TraversalExceptionsCallback exceptionsCallback = new TraversalExceptionsCallback() {
    @Override
    public void invoke(TraversalAsposeException exception, String itemId) {
        /* Exception handling  code. */
    }
};

//Loading and traversal exceptions will be available through the callback method.
try (PersonalStorage pst = new PersonalStorage(exceptionsCallback)) 
{
    // ...
}

The PersonalStorage.Load method returns ‘true’ if a file is loaded successfully and further traversal is possible. If the file is corrupted and no traversal is possible, ‘false’ is returned.

For this case, PST extraction could be implemented like this:

static Map<String, Exception> exceptions = new HashMap<String, Exception>();

public static void main(String[] args) {
    TraversalExceptionsCallback exceptionsCallback = new TraversalExceptionsCallback() {
        @Override
        public void invoke(TraversalAsposeException exception, String itemId) {
            exceptions.put(itemId, exception);
        }
    };

    try (PersonalStorage pst = new PersonalStorage(exceptionsCallback)) {
        pst.load("erosenfeld.pst");
        FolderInfo rootFolder = pst.getRootFolder();
        extractFolder(pst, rootFolder, "out\\");
    }
} 

private static void extractFolder(PersonalStorage pst, FolderInfo folder, String outDirectory) {
    System.out.println("Processing folder " + folder.getDisplayName());
    int messageNumber = 0;

    for (String messageEntryId : folder.enumerateMessagesEntryId()) {
        String fileName = outDirectory + messageNumber;
        System.out.println("Processing messageEntryId " + messageEntryId);
        MapiMessage message = pst.extractMessage(messageEntryId);

        if (!exceptions.containsKey(messageEntryId)) {
            if ("IPM.Contact".equals(message.getMessageClass())) {
                IMapiMessageItem item = message.toMapiMessageItem();
                ((MapiContact) item).save(fileName + ".vcf", 0);
            } else {
                message.save(fileName + ".msg", new MsgSaveOptions(MailMessageSaveType.getOutlookMessageFormat()));
            }

            messageNumber++;
        }
    }
    for (FolderInfo subFolder : folder.getSubFolders()) {
        extractFolder(pst, subFolder, outDirectory);
    }
}

API Reference: TraversalExceptionsCallback Class, PersonalStorage Class