views:

522

answers:

2

I have previously used webdav to access the sent messages on an exchange 2003 server based on the subject and time and this has worked.

I now need to implement another feature which means dragging a message from client outlook (not web access) on to a windows form then querying webdav on exchange to get all the information about this message.

I can get the messages href using the following code:

Dim msg As MAPI.Message = CType(session.GetMessage(mail.EntryID), MAPI.Message)
Dim id as string = CType(CType(msg.Fields(), MAPI.Fields).Item(&H6707001E), MAPI.Field).Value.ToString

However there are two issues;

1) The encoding on the URL is different between what I get from the dragged message and what is brought back from webdav (I can see these if I ask for all mail).

2) No matter how I format the query it never brings back results even if I copy the href from the list when I bring back all messages.

Here is a sample of a search request that fails (works if you remove the where clause):

    <?xml version="1.0" ?>
    <D:searchrequest xmlns:D="DAV:">
        <D:sql>SELECT "DAV:contentclass","DAV:href", "DAV:displayname","urn:schemas:httpmail:datereceived","urn:schemas:httpmail:subject" 
FROM "https://server/exchange/mailbox" WHERE "DAV:href"='/Inbox/email.EML'</D:sql>
    </D:searchrequest>

I have been using relative syntax as per this article but have tried many combinations.

A: 

When I wanted to figure out how to send WebDav to Exchange 2003, I fired up Fiddler2 and looked at the messages Outlook Web Access was sending. You need Fiddler2 if you want to unpack the https responses.

Cheeso
+2  A: 

This is quite long winded, but I have yet to find a better way of doing this:

The Outlook.MailItem.EntryID contains 4 Guids, although I am not sure what they all map to. The last guid contains the information you are after.

00000000E6053DD369FAB340B6B8C4D77A0
B37D30700173A23D2AA06A3488E75E759DD
1ACBBB00000A6F78CC00007B9F3D877B316
4499DE695FBB7FCDE5F00000 EBD83B9 0000

The bold part is the Messages ID that we can use (Of all the messages in my inbox, only these 7 digits were different between their entry IDs).

Next, modify your webDAV query to bring back the DAV:permanenturl property. This will look like the following:

https://SERVER%5FNAME/exchange/MAILBOX@DOMAIN>COM/-FlatUrlSpace-/173a23d2aa06a3488e75e759dd1acbbb-a6f78cc/7b9f3d877b3164499de695fbb7fcde5f-ebd83b9

So all you need to do for matching is to do a webDAV query for all the items in the specified mailbox, loop through comparing the PermanentURL with part of the EntryID to find your match.

I would be happier if there was an EntryID on the webDAV, but there does not seem to be a directly accessible one.

Pondidum