Free Support Forum - aspose.com

How to extract the guid and name of a named mapi property using its tag in MapiMessage?


#1

Hi,
I’m trying to find the name and guid of a named mapi property in a MapiMessage loaded from a pst file exported from Outlook.

Sample code:
import com.aspose.email.FolderInfo;
import com.aspose.email.MapiMessage;
import com.aspose.email.PersonalStorage;

public class Test2 {
public static void main(String[] args) {
PersonalStorage pst = null;
try {
// read message from pst
pst = PersonalStorage.fromFile(“outlook-1.pst”);
FolderInfo inboxFolder = pst.getRootFolder().getSubFolder(“Inbox”);
MapiMessage message = null;
for (MapiMessage message1: inboxFolder.enumerateMapiMessages()) {
message = message1;
}

boolean foundInNamedPropertyMapping = false;
int numberOfNamedProperties = 0;
for(Object tag: message.getProperties().getKeys()) {
if(message.getProperties().get_Item((Long)tag).isNamed()) {
if(message.getNamedPropertyMapping().getProperties().containsKey((Long)tag)) {
foundInNamedPropertyMapping = true;
}
numberOfNamedProperties++;
}
}

System.out.println("Number of named mapi properties set in mapi message: " + numberOfNamedProperties);
System.out.println("Number of mappings found in MapiNamedPropertyMappingStorage: " + message.getNamedPropertyMapping().getProperties().size());
if(!foundInNamedPropertyMapping) {
System.out.println(“Could not find mapping for any of the named property tag”);
System.out.println(“Note: I’m trying to find the guid and name of the named mapi property from its tag”);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(pst != null) {
pst.dispose();
}
}
}
}

outlook-1.pst file used can be found here.


#2

@nandhini.r.17.96,

I have observed your requirements and suggest you to please visit this documentation link for your convenience to fetch MAPI properties. If you encounter any issue then please share which property from message you desire to fetch and is not getting fetched.


#3

I do not wish to fetch property value for a particular tag. I want to get the key of the property as guid and name instead of tag.

As you see in this snippet,

I wish to iterate through all the properties set, and try to find the name of the named MAPI property (0x8000 to 0xFFFE). Is there any possible way to find the name of the property from its tag.

I also tried this:

message.getProperties().get_Item((Long)tag).getDescriptor().getName()

The value is null for most of the properties. Moreover the property descriptor returned by that method was PidTagPropertyDescriptor and not PidNamePropertyDescriptor or PidLidPropertyDescriptor.

My question is how to use MapiNamedPropertyMappingStorage to adress my requirement.


#4

I’m trying to achieve something like this.

newPst = PersonalStorage.create(“new.pst”, 0);
MapiMessage newMapiMessage = new MapiMessage();
for(Object tag: message.getProperties().getKeys()) {
newMapiMessage.setProperty(message.getProperties().get_Item((Long)tag).getDescriptor(), message.getProperties().get_Item((Long)tag).getValue());
}
newPst.getRootFolder().addSubFolder(“Inbox”).addMessage(newMapiMessage);

If you import this new pst into outlook, you can see that some properties like to are missing.
Note: I do not want to use com.aspose.email.MapiMessage.deepClone() as I need to change some property values and add new Properties.

In short, I would like to build a new MapiMessage object with just properties. (Which will be in either one of these data structures:

  • A Long tag and Object value — for type PidTagPropertyDescriptor
  • A UUID guid, String name and Object value — for type PidNamePropertyDescriptor
  • A UUID guid, Long id and Object value — for type PidLidPropertyDescriptor)

With these properties I will be using this method to set it to MapiMessage object.

com.aspose.email.MapiMessageItemBase.setProperty()

When I do that for named properties, the pst could not be imported to outlook. It says “something went wrong”. If I skip named properties, it gets imported but some of the important fields are missing in the imported item.


#5

@nandhini.r.17.96,

I have shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.sample code.zip (734 Bytes)


#6

@Adnan.Ahmad,
Thank for your reply. The source code you have shared helped me get those name identifiers and guid.

Now, here is my next requirement.
I now have the properties and its identifiers read from an existing pst in this format:

  • A Long tag and Object value — for type PidTagPropertyDescriptor
  • A UUID guid, String name and Object value — for type PidNamePropertyDescriptor
  • A UUID guid, Long id and Object value — for type PidLidPropertyDescriptor

Using these I’m creating a new pst that could not be imported in outlook.
Source code: sample code.zip (17.3 KB)


#7

@nandhini.r.17.96,

Thank you for your feedback. I have tried opening the attached PST on my end and it got opened in MS Outlook on my end without any issue. For your kind reference, I have attached following snapshot as well. Can you please share which Outlook fails to open the provided PST on your end.


#8

Do not just open it in Outlook. It will work fine.
Try to import that newly created PST (new.pst) into a mailbox in Outlook client. That’s where the issue occurred.
Outlook version: 2013


#9

@nandhini.r.17.96,

I have observed your comments. An issue with ID EMAILJAVA-34532 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


#10

Thank you! I request you to address this as soon as possible. We need this to be resolved for our high priority release.


#12

@nandhini.r.17.96,

I like to inform as per our company policy, the first priority for investigation is given to the Paid Support i.e. Enterprise and Priority Support on first come first serve basis. After that the issues from normal support forum are scheduled for investigation on first come first serve basis. I request for your patience. We will share good news with you soon regarding your issue.


#13

I understand, we will be expecting your response on this issue.


#14

@nandhini.r.17.96,

Sure, we will share good news with you soon.