Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very strange situation with SortOrder #445

Open
NAlexandrov opened this issue Oct 7, 2024 · 0 comments
Open

Very strange situation with SortOrder #445

NAlexandrov opened this issue Oct 7, 2024 · 0 comments

Comments

@NAlexandrov
Copy link

I've wrote a simple script:

import * as ews from 'ews-javascript-api';

const ex = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016);

ex.Credentials = new ews.WebCredentials('username', 'password');
ex.Url = new ews.Uri('https://mail.server.local/Ews/Exchange.asmx');

ews.EwsLogging.DebugLogEnabled = true;

(async () => {
  const res = await ex.FindItems(
    ews.WellKnownFolderName.Inbox,
    'isRead:false',
    new ews.ItemView(100),
  );

  console.log(res);
})();

And I've got an empty response, but Inbox has an unread messages.

SOAP request by ews-javascript-api:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2016"></t:RequestServerVersion>
  </soap:Header>
  <soap:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>AllProperties</t:BaseShape>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="100" Offset="0" BasePoint="Beginning"></m:IndexedPageItemView>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="inbox"></t:DistinguishedFolderId>
      </m:ParentFolderIds>
      <m:QueryString>isRead:false</m:QueryString>
    </m:FindItem>
  </soap:Body>
</soap:Envelope>

Then I've rewrite this script on python exchangelib

import logging
from exchangelib import Credentials, Account, Configuration, Version
from exchangelib.util import PrettyXmlHandler
from exchangelib.version import EXCHANGE_2016
from exchangelib.util import PrettyXmlHandler

logging.basicConfig(level=logging.DEBUG, handlers=[PrettyXmlHandler()])

credentials = Credentials("username", "password")
config = Configuration(server="mail.server.local", credentials=credentials, version=Version(EXCHANGE_2016))
account = Account("[email protected]", config=config)

filtered_items = account.inbox.filter("isRead:false").order_by("datetime_received")

for item in filtered_items:
    print(item.subject, item.sender, item.datetime_received)

And I've got a list of messages.

SOAP request by exchangelib:

<?xml version='1.0' encoding='utf-8'?>
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <s:Header>
    <t:RequestServerVersion Version="Exchange2016"/>
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        <t:PrimarySmtpAddress>[email protected]</t:PrimarySmtpAddress>
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
  </s:Header>
  <s:Body>
    <m:FindItem Traversal="Shallow">
      <m:ItemShape>
        <t:BaseShape>IdOnly</t:BaseShape>
      </m:ItemShape>
      <m:IndexedPageItemView MaxEntriesReturned="100" Offset="0" BasePoint="Beginning"/>
      <m:SortOrder>
        <t:FieldOrder Order="Ascending">
          <t:FieldURI FieldURI="item:DateTimeReceived"/>
        </t:FieldOrder>
      </m:SortOrder>
      <m:ParentFolderIds>
        <t:DistinguishedFolderId Id="inbox">
          <t:Mailbox>
            <t:EmailAddress>[email protected]</t:EmailAddress>
            <t:RoutingType>SMTP</t:RoutingType>
            <t:MailboxType>Mailbox</t:MailboxType>
          </t:Mailbox>
        </t:DistinguishedFolderId>
      </m:ParentFolderIds>
      <m:QueryString>isRead:false</m:QueryString>
    </m:FindItem>
  </s:Body>
</s:Envelope>

The main difference in SOAP XML between ews-javascript-api and exchangelib is SortOrder tag. If I remove the sorting in exchangelib, I will also get an empty response. Is it possible to add SortOrder in ews-javascript-api?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant