Data convert

  "1703967": {
    "PropertyTagName": "PR_MESSAGE_CLASS_W",
    "Name": "__substg1.0_001A001F",
    "Identifier": 26,
    "Tag": 1703967,
    "DataType": 31,
    "Data": "SQBQAE0ALgBOAG8AdABlAAAA",
    "MVEntries": {
      "$type": "System.Collections.ArrayList, System.Runtime.Extensions",
      "$values": []
    },

I’m pulling mapiMessage.Properties each item returned from a folderInfo.EnumerateMapiMessages()

How do I convert these into something actually viewable… Data is stored in datatype of 31… lets say I want a string so the data can actually be read…

@paulbright,

Thank you for contacting Aspose support team.

Data type 31 corresponds to PT_UNICODE in the enumerator MapiPropertyType. We get byte array value from such properties and convert them to string as shown in the following sample code. Please give it a try and share the feedback.

MapiMessage mapiMsg = MapiMessage.FromFile(@"source.msg");
MapiPropertyCollection properties = mapiMsg.Properties;
System.IO.StreamWriter file = new System.IO.StreamWriter(@"output.txt");
foreach (MapiProperty mapiProp in properties.Values)
{
    MapiPropertyType type = (MapiPropertyType)mapiProp.DataType;

    if (type == MapiPropertyType.PT_UNICODE)
    {
        string mystring = Encoding.Unicode.GetString(mapiProp.Data);

        if (mapiProp.PropertyTagName != "")
        {
            file.WriteLine("Name = " + mapiProp.PropertyTagName + ", value = " + mystring);
        }
    }
}

Thank you so much…

how about the following data types, or is there documentation you can point me to that will handle all data types or explain what they are… thanks

“DataType”: 2,

“DataType”: 3,

“DataType”: 11,

“DataType”: 20,

“DataType”: 64,

“DataType”: 258,

@paulbright,

You may please visit Working with MAPI Properties for detailed information. For setting variety of properties, please go through this section.

Thanks… the documentation shows really good info on taking the original data type and putting it into a prop… but doesn’t show the reverse… how to take the raw stored property data and reverse it Not experienced in data conversion… would be nice to have detailed examples on how to pull out a datatype 64, 258, 11, 3 etc…

I think I’m doing something wrong on the date conversion…lol

{
“PropertyTagName”: “PR_MESSAGE_DELIVERY_TIME”,
“Identifier”: 3590,
“Tag”: 235274304,
“DataType”: 64,
“Data”: “DmcLqiVGxwE=”,
“DataConvertedString”: “2/1/0407 5:23:18 PM”
},

//DataType 64
case MapiPropertyType.PT_SYSTIME:
long longVar = BitConverter.ToInt64(propvalue.Data, 0);
//Convert to datetime.
DateTime dateTimeVar = new DateTime(longVar);
propObject.DataConvertedString = dateTimeVar.ToString();
break;

So there are built in converters for some to the data types…

Date - 64

propObject.DataConvertedString = propvalue.GetDateTime().ToString();

{
“PropertyTagName”: “PR_MESSAGE_DELIVERY_TIME”,
“Identifier”: 3590,
“Tag”: 235274304,
“DataType”: 64,
“Data”: “DmcLqiVGxwE=”,
“DataConvertedString”: “2/1/2007 12:23:18 PM”
},

These seem to work, but still having issues convert
“DataType”: 258, and not sure what Datatype 20 is…

   var type = (MapiPropertyType)propvalue.DataType;

                                    switch (type)
                                    {
                                        case MapiPropertyType.PT_UNICODE:

                                            propObject.DataConvertedString =
                                                Encoding.Unicode.GetString( propvalue.Data );

                                            break;

                                        case MapiPropertyType.PT_SYSTIME:

                                            propObject.DataConvertedString = propvalue.GetDateTime().ToString(CultureInfo.InvariantCulture);

                                            break;

                                        case MapiPropertyType.PT_BOOLEAN:

                                            propObject.DataConvertedString = propvalue.GetBoolean().ToString();

                                            break;

                                        case MapiPropertyType.PT_DOUBLE:

                                            propObject.DataConvertedString = propvalue.GetDouble().ToString(CultureInfo.InvariantCulture);

                                            break;

                                        case MapiPropertyType.PT_FLOAT:

                                            propObject.DataConvertedString = propvalue.GetFloat().ToString(CultureInfo.InvariantCulture);

                                            break;

                                        case MapiPropertyType.PT_LONG:

                                            propObject.DataConvertedString = propvalue.GetLong().ToString();

                                            break;

                                        case MapiPropertyType.PT_SHORT:

                                            propObject.DataConvertedString = propvalue.GetShort().ToString();

                                            break;
                                    }

@paulbright,

Data type 258 is binary array and Data type 20 is LongLong Data Type. LongLong ( LongLong integer) variables are stored as signed 64-bit (8-byte) numbers ranging in value from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. LongLong is a valid declared type only on 64-bit platforms. Following is a sample where both type of values are first written and then read. Please give it a try and share the feedback. If it does not fulfill requirement, please share the sample MSG file for our analysis here.

// Create a sample Message
MapiMessage msg = new MapiMessage("user1@gmail.com", "user2@gmail.com", "This is subject", "This is body");
IList values = new ArrayList();


//Signed or unsigned 64-bit integer. This property type is the same as PT_I8 and the OLE type VT_I8.
//PT_LONGLONG = 20,

//Write longlong data
values = new ArrayList();
values.Add((long)30456);
values.Add((long)40655);
msg.SetProperty(new MapiProperty(0x23901014, values));

//Read longlong data
MapiProperty longlongProp = msg.Properties[0x23901014];
var value2 = (long[])longlongProp.GetValue();
foreach (var lng in value2)
    Console.WriteLine(lng);

//SBinary structure value, a counted byte array.
//PT_BINARY = 258,

//Write binary property data
values = new ArrayList();
values.Add(new byte[] { 1, 2, 4, 5, 6, 7, 5, 4, 3, 5, 6, 7, 8, 6, 4, 3, 4, 5, 6, 7, 8, 6, 5, 4, 3, 7, 8, 9, 0, 2, 3, 4, });
msg.SetProperty(new MapiProperty(0x23901102, values));

//Read Binary property data
MapiProperty binaryProp = msg.Properties[0x23901102];
var value = ((byte[][])binaryProp.GetValue())[0];
foreach (var byt in value)
    Console.WriteLine(byt);