我想查询我的电子邮件文件夹,查找我写在其上的自定义标题的特定电子邮件。但似乎我正在创建的SOAP消息有一些问题,它总是返回空结果集。
我确定我在该文件夹中有电子邮件。如果我在删除限制部分后查询,我可以在查询结果中看到该电子邮件。如果我连接到我的帐户,让我们说Thunderbird,那么我可以看到标题就在那里。
到目前为止,我至少搜索了一周,我唯一能找到的结果是https://social.msdn.microsoft.com/Forums/exchange/en-US/8db4b750-d92f-489b-8282-d109d33314ff/using-finditem-request-to-find-the-items-with-given-header-value,最后只是告诉我我的实施应该有效。
感谢阅读。
QUERY
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
</ItemShape>
<m:Restriction>
<t:IsEqualTo>
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="String"/>
<t:FieldURIOrConstant>
<t:Constant Value="44A2F930-5E24-4F18-BC82-EC6B3A02E893"/>
</t:FieldURIOrConstant>
</t:IsEqualTo>
</m:Restriction>
<m:ParentFolderIds>
<t:FolderId Id="AQMkADAwATM0MDAAMS1jMzg1LWZkMDMtMDACLTAwCgAuAAADlxvq+JrhgkiMcRwVFQDzo9MBANxoXUHEHORLhWKXuo92RaUAAAIBDwAAAA=="/>
</m:ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
RESPONSE
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="20" MajorBuildNumber="178" MinorBuildNumber="14" Version="V2017_07_11"/>
</s:Header>
<s:Body>
<m:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:FindItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:RootFolder TotalItemsInView="0" IncludesLastItemInRange="true">
<t:Items/>
</m:RootFolder>
</m:FindItemResponseMessage>
</m:ResponseMessages>
</m:FindItemResponse>
</s:Body>
</s:Envelope>
如果我还尝试使用AllProperties基本形状查询服务器并将我的标题添加到extendedfielduri,那么我会得到我的标题作为回应。
QUERY
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties>
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="String"/>
</t:AdditionalProperties>
</ItemShape>
<ItemIds>
<t:ItemId Id="AQMkADAwATM0MDAAMS1jMzg1LWZkMDMtMDACLTAwCgBGAAADlxvq+JrhgkiMcRwVFQDzo9MHANxoXUHEHORLhWKXuo92RaUAAAIBDwAAANxoXUHEHORLhWKXuo92RaUAAS8MrxcAAAA="/>
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>
RESPONSE(部分)
<t:DateTimeReceived>2017-10-25T07:55:56Z</t:DateTimeReceived>
<t:Size>11803</t:Size>
<t:Importance>Normal</t:Importance>
<t:IsSubmitted>false</t:IsSubmitted>
<t:IsDraft>true</t:IsDraft>
<t:IsFromMe>false</t:IsFromMe>
<t:IsResend>false</t:IsResend>
<t:IsUnmodified>false</t:IsUnmodified>
<t:InternetMessageHeaders>
<t:InternetMessageHeader HeaderName="Subject">Test</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="Mime-Version">1.0 (Mac OS X Mail 11.0 \(3445.1.7\))</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="Content-Type">text/html</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-Apple-Base-Url">x-msg://1/</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-Universally-Unique-Identifier">44A2F930-5E24-4F18-BC82-EC6B3A02E893</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-Apple-Mail-Remote-Attachments">YES</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-Apple-Windows-Friendly">1</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="Date">Wed, 25 Oct 2017 09:55:56 +0200</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-My-Header">44A2F930-5E24-4F18-BC82-EC6B3A02E893</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="Content-Transfer-Encoding">quoted-printable</t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="Message-Id"><70916417-FF2F-4FA7-B98E-D0E3E6E91B71@outlook.com></t:InternetMessageHeader>
<t:InternetMessageHeader HeaderName="X-Uniform-Type-Identifier">com.apple.mail-draft</t:InternetMessageHeader>
</t:InternetMessageHeaders>
<t:DateTimeSent>2017-10-25T07:55:56Z</t:DateTimeSent>
<t:DateTimeCreated>2017-10-25T07:55:56Z</t:DateTimeCreated>
<t:ResponseObjects>
<t:ForwardItem/>
在此之后我还试着看看在我的查询中添加相同的参数是否有效。但没有运气。以下查询返回的响应与第一个完全相同。
QUERY
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow">
<ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
<t:AdditionalProperties>
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="String"/>
</t:AdditionalProperties>
</ItemShape>
<m:Restriction>
<t:IsEqualTo>
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="String"/>
<t:FieldURIOrConstant>
<t:Constant Value="44A2F930-5E24-4F18-BC82-EC6B3A02E893"/>
</t:FieldURIOrConstant>
</t:IsEqualTo>
</m:Restriction>
<m:ParentFolderIds>
<t:FolderId Id="AQMkADAwATM0MDAAMS1jMzg1LWZkMDMtMDACLTAwCgAuAAADlxvq+JrhgkiMcRwVFQDzo9MBANxoXUHEHORLhWKXuo92RaUAAAIBDwAAAA=="/>
</m:ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
答案 0 :(得分:2)
所有Internet标头都应该是纯字符串,所以在您的代码中
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="StringArray"/>
需要
另外我建议你先试着看看EWS是否会将Header作为附加属性返回,例如
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" Traversal="Shallow">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
<t:AdditionalProperties>
<t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="X-My-Header" PropertyType="String"/>
</t:AdditionalProperties>
</ItemShape>
<m:ParentFolderIds>
<t:FolderId Id="AQMkADAwATM0MDAAMS1jMzg1LWZkMDMtMDACLTAwCgAuAAADlxvq+JrhgkiMcRwVFQDzo9MBANxoXUHEHORLhWKXuo92RaUAAAIBDwAAAA=="/>
</m:ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
如果您没有看到您的财产与物品一起返回,那么限制将无效。通常使用X-Headers,他们需要配置https://msdn.microsoft.com/en-us/library/office/dn596091(v=exchg.150).aspx,然后当你使用像MFCMapi或OutlookSpy这样的Mapi编辑器查看Item时,你应该将它们看作一个单独的Extended属性。