OfficeDev / ews-managed-api

Other
583 stars 317 forks source link

EWS Search Query only returns 250 items from Archive Mailbox #284

Open hpatel70 opened 2 years ago

hpatel70 commented 2 years ago

I have C# application which uses EWS Managed API (2.2.1.0)to perform search and collect data from Exchange servers. Recently client reported an issue where they noticed our application was only collecting 250 items from any folder from Archive Mailbox when user specified a date filter. We were able to replicate this issue with EWSEditor tool as well.

The following query returned all items from Archive Mailbox folder.

((Kind:Email) OR (Kind:Meetings) OR (Kind:Tasks) OR (Kind:Notes) OR (Kind:Docs) OR (Kind:Journals) OR (Kind:Contacts) OR (Kind:IM))

But the following query returned only 250 items from Archive Mailbox folders.

((Sent:1/1/1980..12/31/2022 OR Received:1/1/1980..12/31/2022)) AND ((Kind:Email) OR (Kind:Meetings) OR (Kind:Tasks) OR (Kind:Notes) OR (Kind:Docs) OR (Kind:Journals) OR (Kind:Contacts) OR (Kind:IM))

The application uses paging when making FindItems calls as shown below.

private List RetrieveItems(Folder folder, string query) { const int PAGE_SIZE = 500;

        List<Item> items = new List<Item>();
        int offset = 0;
        bool moreResults = false;

        do
        {
            ItemView view = new ItemView(PAGE_SIZE, offset);
            view.PropertySet = new PropertySet(EmailMessageSchema.Subject, EmailMessageSchema.LastModifiedTime, EmailMessageSchema.DateTimeCreated, EmailMessageSchema.Size, EmailMessageSchema.ItemClass, ItemSchema.HasAttachments);

            FindItemsResults<Item> results = null;
            Retry(() =>
            {
                results = folder.FindItems(query, view);
            });

            items.AddRange(results);

            offset += PAGE_SIZE;
            moreResults = results.MoreAvailable;
        }
        while (moreResults);

        return items;
    }

There are no restrictions on service account used for authentication per client. The issue is not seen when searching non Archive Mailbox folders.

Has anyone run into this restriction or know how to resolve this issue so we can get all matching items from Archive Mailbox folders?

Thanks, Hiren Patel

hpatel70 commented 2 years ago

Anyone ran into this issue and know how to fix it?

timanderson commented 1 year ago

Note: https://devblogs.microsoft.com/microsoft365dev/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/

Microsoft has abandoned us, it seems.

Tim

MichelZ commented 1 year ago

Note: https://devblogs.microsoft.com/microsoft365dev/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/

Microsoft has abandoned us, it seems.

Tim

What gave you that impression? The fact that they announced it 4 years ago?

"Starting July 19th 2018, Exchange Web Services (EWS) will no longer receive feature updates. "

timanderson commented 1 year ago

True, but do you know any other way to access public folders on Exchange Online programmatically?

Tim

MichelZ commented 1 year ago

I don't, and a lot of other functionality is also missing in Graph (the "replacement" for EWS). But Microsoft clearly said that this project here is dead, so we're on our own :)