views:

1311

answers:

2

Hello -- I'm trying to get all property names / values from an Outlook item. I have custom properties in addition to the default outlook item properties. I'm using redemption to get around the Outlook warnings but I'm having some problems with the GetNamesFromIDs method on a Redemption.RDOMail Item....

I'm using my redemption session to get the message and trying to use the message to get the names of all the properties.

Dim rMessage as Redemption.RDOMail = _RDOSession.GetMessageFromID(EntryID, getPublicStoreID())
Dim propertyList As Redemption.PropList = someMessage.GetPropList(Nothing)
For i As Integer = 1 To propertyList.Count + 1
    Console.WriteLine(propertyList(i).ToString())
    Console.WriteLine(someMessage.GetNamesFromIDs(________, propertyList(i)))
Next

I'm not totally sure what to pass in as the first parameter to getNamesFromIDs. The definition of GetNamesFromIDs is as follows:

GetNamesFromIDs(MAPIProp as Object, PropTag as Integer) As Redemption.NamedProperty

I'm not totally sure what should be passed in as the MAPIProp object. I don't see this property referenced in the documentation. http://www.dimastr.com/redemption/rdo/MAPIProp.htm#properties

Any help or insight would be greatly appreciated.

+1  A: 

Well, for background info, the author suggests using something like OutlookSpy to see how Outlook stores the properties.

Looking at this exchange (make sure to read through all the follow-up responses), there isn't much more (in fact, I think at one point the Outlook MVP types GetNamesFromIDs when he means GetIDsFromNames).

What you might try is using GetIDsFromNames to see what that returns, and then use that to pass to GetNamesFromIDs.

I've used Redemption before, but not in this particular manner, so that's all I've got for you ...

Dave DuPlantis
+2  A: 

I think I figured it out. I have used VBA only, so you need to "think around" it's limitations, it will follow the same scheme in VB.NET.

The function signature is this:

Function GetNamesFromIDs(MAPIProp As Unknown, PropTag As Long) As NamedProperty

As the first parameter it requires an object which supports the IUnknown interface. Looking at the Redemption docs it became clear that there is an interface named _MAPIProp, from which many other RDO objects are derived (IRDOMail is among them). So this must be the very RDOMail you are trying to get data out of.

Knowing that, it needed only one other subtle hint from the docs to get it working:

Given a prop tag (>= 0x80000000), returns the GUID and id of the named property.

So property tag must be >= 0x80000000, this means it wont work for all properties, but just for the custom ones (I guess that is the distinction in this case, correct me if I'm wrong.) Passing in property tags not fulfilling this condition raises an error message (0x8000ffff "unexpected results").

Here is my code. It is VBA, so forgive me the Hex() blunder, as VBAs long integer overflows for numbers that big. I am sure you will get the picture.

Sub GetNamesFromIds()

  Dim rSession As New Redemption.RDOSession
  Dim rMessage As Redemption.RDOMail
  Dim PropertyList As Redemption.PropList
  Dim PropTag As Long
  Dim EntryId As String
  Dim i As Integer

  rSession.MAPIOBJECT = Application.Session.MAPIOBJECT

  ' retrieve first random mail for this example '
  EntryId = ActiveExplorer.CurrentFolder.Items(1).EntryId
  Set rMessage = rSession.GetMessageFromID(EntryId)
  Set PropertyList = rMessage.GetPropList(0)

  For i = 1 To PropertyList.Count
    PropTag = PropertyList(i)
    If "0x" & Right("00000000" & Hex(PropTag), 8) > "0x80000000" Then
      Debug.Print
      If IsArray(rMessage.Fields(PropTag)) Then
        Debug.Print Hex(PropTag), "(Array:", UBound(rMessage.Fields(PropTag)), "items)"
      Else
        Debug.Print Hex(PropTag), "(", rMessage.Fields(PropTag), ")"
      End If
      Debug.Print "    GUID:", rMessage.GetNamesFromIds(rMessage, PropTag).GUID
      Debug.Print "      ID:", rMessage.GetNamesFromIds(rMessage, PropTag).ID
    End If
  Next

End Sub

First snippet from the output:

8041001E      (             urn:content-classes:message )
    GUID:     {00020386-0000-0000-C000-000000000046}
      ID:     content-class
Tomalak