Help getting MapiProperty from a message

Hello,

I could successfully set a MapiProperty for a message using the following code below:

String value = "test 123";
MapiProperty property = new MapiProperty(mapiMessage.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), value.getBytes(StandardCharsets.UTF_16LE));
mapiMessage.addCustomProperty(property, "MyProperty");

However, when I get messages from a PST folder using the code below it didn’t list “MyProperty”

MessageInfoCollection messageInfoCollection = targetFolder.getContents();
for (int j = 0; j < messageInfoCollection.size(); j++) 
{
       MessageInfo messageInfo = (MessageInfo) messageInfoCollection.get_Item(j);
			
	MapiPropertyCollection mpc = messageInfo.getProperties();
	for (MapiProperty mapiProp : (Iterable<MapiProperty>) mpc.getValues())
	{
		System.out.println(mapiProp.getPropertyTagName());	
	}
}

What can I do to get “MyProperty” from message?

Thanks

@kelberuc1,
Thank you for the issue description. To my regret, I couldn’t reproduce the problem. Could you please share a compehensive code snippet for investigation? Please also specify the version of Aspose.Email you are using.

@Andrey_Potapov,

Please find attached the full source code.
As you can see it now, it didn’t list “MyProperty”.

TestProject.zip (1.1 KB)

@kelberuc1,
Thank you for the source code. I reproduced the problem and received the same results. I have logged the issue in our tracking system with ID EMAILJAVA-34830 for further investigation. You will be notified when it is fixed.

@kelberuc1,
You should use OutlookMessageFormat.Unicode option when you create PT_UNICODE property.
By default MapiMessage.fromMailMessage creates an ASCII format message.

MapiMessage mapiMessage = MapiMessage.fromMailMessage(
    message, new MapiConversionOptions(OutlookMessageFormat.Unicode)); // <--
String value = "test 123";
MapiProperty property = 
    new MapiProperty(mapiMessage.getNamedPropertyMapping().getNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), // <--
         value.getBytes(StandardCharsets.UTF_16LE));

You can also extract the message from PST to display all message properties:

MessageInfoCollection messageInfoCollection = myFolder.getContents();
for (int j = 0; j < messageInfoCollection.size(); j++)
{
    MessageInfo messageInfo = (MessageInfo) messageInfoCollection.get_Item(j);

    System.out.println("MessageInfo: " + messageInfo.getSubject());
    System.out.println("MessageInfo Properties: ");
    MapiPropertyCollection mpc = messageInfo.getProperties();
    for (MapiProperty mapiProp : (Iterable<MapiProperty>) mpc.getValues())
    {
        System.out.println(mapiProp.getDescriptor().toString());
        //System.out.println(mapiProp.getPropertyTagName());
    }

    System.out.println("----------- Extract Message -------------");
    MapiMessage message = pst.extractMessage(messageInfo);
    System.out.println("Message: " + message.getSubject());
    System.out.println("Message Properties: ");
    mpc = message.getProperties();
    for (MapiProperty mapiProp : (Iterable<MapiProperty>) mpc.getValues())
    {
        System.out.println(mapiProp.getDescriptor().toString());
        //System.out.println(mapiProp.getPropertyTagName());
    }
}

Output:

...
Tag:'PidTagStoreSupportMask':0x340D:3
Tag:'PidTagInternetCodepage':0x3FDE:3
Tag:'':0x6619:31
Lid:'PidLidAgingDontAgeMe':0x850E:11:00062008-0000-0000-c000-000000000046
Lid:'':0x8540:258:00062008-0000-0000-c000-000000000046
Name:'':MyProperty:31:00020329-0000-0000-c000-000000000046  <---

API Reference: MapiConversionOptions class, OutlookMessageFormat class

Hi @Andrey_Potapov,

Thanks for your answer.
I would like to know if there’s a way to get this property without extracting the message?
I want to avoid extracting message for performance purposes, I’m working on a PST with aroung 150K messages.

Thanks

@kelberuc1,
To my regret, the custom properties cannot be received without extracting MAPI messages.
getContents method doesn’t load the custom properties for performance purposes.