Using the WEBDav libraries from Troy Wolf
I am using the following query to pull results from the Exchange Server
$search = <<<END
<?xml version="1.0"?><a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/">
<a:sql>SELECT "DAV:displayname",
"urn:schemas:httpmail:from",
"urn:schemas:httpmail:subject",
"urn:schemas:httpmail:textdescription",
"urn:schemas:httpmail:htmldescription",
"urn:schemas:httpmail:hasattachment",
"urn:schemas:httpmail:attachmentfilename",
"urn:schemas:httpmail:sender" FROM "$mailbox" WHERE "DAV:isfolder"=False AND "http://schemas.microsoft.com/exchange/outlookmessageclass"='IPM.NOTE'</a:sql>
</a:searchrequest>
END
This works however the return comes back as
array
0 =>
object(stdClass)[10]
public '_attr' =>
object(stdClass)[11]
public 'A_STATUS' =>
array
0 =>
object(stdClass)[12]
public '_attr' =>
object(stdClass)[13]
...
public '_text' => string 'HTTP/1.1 200 OK' (length=15)
public 'A_PROP' =>
array
0 =>
object(stdClass)[14]
public '_attr' =>
object(stdClass)[15]
...
public 'A_DISPLAYNAME' =>
array
...
public 'D_FROM' =>
array
...
public 'D_SUBJECT' =>
array
...
public 'D_TEXTDESCRIPTION' =>
array
...
public 'D_HTMLDESCRIPTION' =>
array
...
public 'D_HASATTACHMENT' =>
array
...
1 =>
object(stdClass)[28]
public '_attr' =>
object(stdClass)[29]
public 'A_STATUS' =>
array
0 =>
object(stdClass)[30]
public '_attr' =>
object(stdClass)[31]
...
public '_text' => string 'HTTP/1.1 404 Resource Not Found' (length=31)
public 'A_PROP' =>
array
0 =>
object(stdClass)[32]
public '_attr' =>
object(stdClass)[33]
...
public 'D_ATTACHMENTFILENAME' =>
array
...
public 'D_SENDER' =>
array
...
Whether a file is attached or not, D_ATTACHMENTFILENAME is returned with a 404. Any ideas why?
tl;dr – cannot retrieve list of attached files for emails through a webdav service.
You can’t get the filenames of the attachments using a Search request. Instead, filter on items which have the hasattachment set to 1. Foreach each of those elements, issue an X-MS-ENUMATTS request to get the attachment properties.