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

Search not working with Office365 #1437

Closed
RichardD2 opened this issue Sep 16, 2022 · 3 comments
Closed

Search not working with Office365 #1437

RichardD2 opened this issue Sep 16, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@RichardD2
Copy link

I'm trying to use the ImapClient to search an Office365 mailbox. Every attempt to call the Search / SearchAsync method throws an exception:

The IMAP server does not support the ESEARCH extension.

Does that mean Office365 doesn't support any search queries via IMAP?

Based on a quick scan of RFC4731, I wasn't expecting ESEARCH to be required if I specified SearchOptions.None.

Is my only option to download the envelope for all messages and search them in code?


SearchQuery query = SearchQuery.SubjectContains("invoice");
SearchResults results = client.Inbox.Search(SearchOptions.None, query);

Log:

Connected to imaps://outlook.office365.com:993/
S: * OK The Microsoft Exchange IMAP4 service is ready. [...BASE64...]
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 AUTHENTICATE PLAIN ********
S: A00000001 NO AUTHENTICATE failed.
C: A00000002 LOGIN "********" "********"
S: A00000002 OK LOGIN completed.
C: A00000003 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
S: A00000003 OK CAPABILITY completed.
C: A00000004 NAMESPACE
S: * NAMESPACE (("" "/")) NIL NIL
S: A00000004 OK NAMESPACE completed.
C: A00000005 LIST "" "INBOX"
S: * LIST (\Marked \HasChildren) "/" INBOX
S: A00000005 OK LIST completed.
C: A00000006 EXAMINE INBOX
S: * 109 EXISTS
S: * 0 RECENT
S: * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
S: * OK [PERMANENTFLAGS ()] Permanent flags
S: * OK [UNSEEN ...] Is the first unseen message
S: * OK [UIDVALIDITY ...] UIDVALIDITY value
S: * OK [UIDNEXT ...] The next unique identifier value
S: A00000006 OK [READ-ONLY] EXAMINE completed.

MailKit v3.4.1

@jstedfast
Copy link
Owner

When I added the Search(SearchOptions, SearchQuery, ...) method, it was intended for the ESEARCH extensions, but I can easily see how anyone using the API would expect that using SearchOptions.None would expect it to behave the same as Search(SearchQuery, ...).

That is an oversight on my part. Thanks for pointing it out.

@jstedfast jstedfast added the bug Something isn't working label Sep 16, 2022
@jstedfast
Copy link
Owner

Looks like Sort(SearchOptions, ...) would have the same problem...

@RichardD2
Copy link
Author

Thanks for the clarification: the SearchAsync(SearchQuery, ...) method worked for me. 👍

jstedfast added a commit that referenced this issue Sep 16, 2022
…arch(query)

Reduces code duplication and fixes issue #1437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants