How to get the following values and what they mean in PST File via Java

Retrieve available categories from PST:

using (var pst = PersonalStorage.FromFile("mailbox.pst"))
{
   var categories = pst.GetCategories();
   
   foreach(var category in categories)
   {
       Console.WriteLine(category);
   }
}

Matching a category name with its color:

using (var pst = PersonalStorage.FromFile("mailbox.pst"))
{
    // Get all categories from the PST
    var availableCategories = pst.GetCategories();
    
    // Extract a message from the PST and retrieve the list of category names for the message
    var messageCategoryList = FollowUpManager.GetCategories(pst.ExtractMessage(messageInfo));
    
    // Iterate through each category in the message and match it with the PST category list
    foreach (var messageCategory in messageCategoryList)
    {
        var category = availableCategories.Find(c => c.Name.Equals(messageCategory, StringComparison.OrdinalIgnoreCase));

        if (category != null)
        {
            // Print the category name and its associated color
            Console.WriteLine(category);
        }
        else
        {
            Console.WriteLine($"Category: {messageCategory}, Color: Not found");
        }
    }
}

And Java examples.

Retrieve available categories fronm PST:

try (PersonalStorage pst = PersonalStorage.fromFile("mailbox.pst")) {
    List<PstItemCategory> categories = pst.getCategories();

    for (PstItemCategory category : categories) {
        System.out.println(category);
    }
}

Matching a category name with its color:

try (PersonalStorage pst = PersonalStorage.fromFile("mailbox.pst")) {
    // Get all categories from the PST
    List<PstItemCategory> availableCategories = pst.getCategories();

    // Extract a message from the PST and retrieve the list of category names for the message
    Iterable<?> messageCategoryList = FollowUpManager.getCategories(pst.extractMessage(messageInfo));

    // Iterate through each category in the message and match it with the PST category list
    for (Object messageCategory : messageCategoryList) {
        PstItemCategory category = null;
        for (PstItemCategory c : availableCategories) {
            if (c.getName().equalsIgnoreCase(messageCategory.toString())) {
                category = c;
                break;
            }
        }

        if (category != null) {
            // Print the category name and its associated color
            System.out.println(category);
        } else {
            System.out.println("Category: " + messageCategory + ", Color: Not found");
        }
    }
}

Hii @margarita.samodurova the function which you shared pst.getCategories(); is always returning an empty array though the PST contains the categories inside it any idea how to resolve it?

I tried for the below pst file.

Outlook.pst.zip (656.0 KB)

Hello @MaazHussain,

The PST you provided doesn’t contain any categories. Additionally, there are no messages in this PST that have assigned categories.

Please note that you can retrieve the category-color mapping table only if the PST was created by Outlook and contains at least one item with an assigned category.

For PST files created using Aspose.Email, the category-color mapping table is not available, although you can still add items with assigned categories. This limitation exists due to the lack of a publicly available specification for implementing such a table.

EMAILJAVA-35352 ---- Status : Resolved

@sergey.vivsiuk / @margarita.samodurova The status is shown as resolved can you let us know in which version we can find it?

@MaazHussain,

This will be available in version 25.3, expected to be released early next month.

1 Like