Skip to content

Add Exchange Server accounts over EWS with NTLM - #299

Merged
g0shed merged 17 commits into
mainfrom
ews-accounts
Dec 4, 2026
Merged

g0shed merged 17 commits into
mainfrom
ews-accounts

Conversation

@g0shed

@g0shed g0shed commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Adds Exchange Server accounts for companies that run Exchange on their own servers and keep IMAP closed. Penguin Mail talks to the server's Exchange Web Services address (https://host/EWS/Exchange.asmx) and signs in as DOMAIN\user with NTLM.

Fixes #207

What it does

  • Add Account has an Exchange Server choice with the email address, the server address (a bare host becomes the EWS address; it starts as https://mail.<domain>/EWS/Exchange.asmx), the user name and the password.
  • Sign-in uses NTLM when the server offers it, then NTLM inside Negotiate, then Basic over HTTPS. Basic over plain HTTP is refused. NTLM carries the target name and the TLS channel binding, which Exchange 2019 CU14 and later require by default (Extended Protection). Each account keeps its own connection.
  • A server certificate the system does not trust goes through the review from Accept a server certificate the system does not trust #296.
  • Mail: folders, new mail by polling, reading, read and unread, flags, move, delete and Delete Forever, search, drafts and sending with a copy in Sent Items. Marking read and deleting suppress Exchange's own read receipts, so the app's receipt prompt stays in charge. A saved draft goes out with SendItem, so its Bcc comes from the server's copy.
  • Contacts and rules stay on this computer, as for POP3 accounts.

The new mailrs-ews crate builds on Thunderbird's ews crate (MPL-2.0) for the SOAP types. NTLM is our own, on md4, md-5 and hmac. Two requests are written by hand because ews 0.1.2 gets them wrong or lacks them: the flag update (the crate drops the t: prefix on FlagStatus) and FindItem with QueryString.

How it was checked

There is no Exchange server to test against, so this has run against a fake EWS server in the tests, not a real Exchange. The fake server checks the NTLM proof, the MIC, the target name and the channel binding. The NTLM client was also checked against two implementations we did not write: curl --ntlm against the fake server, and pyspnego as the server, with a non-ASCII password, SHA-256 and SHA-384 certificates, and a wrong channel binding that it refused.

Known limits

  • A message moved on the server gets a new id, so it is removed and added again here.
  • Search uses Exchange's query syntax as Microsoft 365 reads it; on-premises servers may differ.
  • No folder create, rename or delete yet.
  • After a folder's sync state is lost, mail deleted on the server during the gap stays here until the next full resync.

g0shed and others added 17 commits December 4, 2026 11:04
NTLMv2 with a MIC and a channel binding, since Exchange 2019 CU14 turns on Extended Protection by default.
NTLM authenticates a connection, so each account owns one and reconnects once on a drop.
Folders and items by EWS sync state, one look per folder, polled.
… new folders from the window

Marking read and deleting ask Exchange not to send read receipts itself. A saved draft goes out through SendItem, so the server uses the recipients it holds, Bcc included. A folder with no usable sync state reads only its state and files the window's mail. RSA-PSS certificates take their channel binding hash from the signature parameters, and hyper's server feature is only built for the fake server.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedews@​0.1.21001009310070
Addedmd4@​0.11.010010093100100

View full report

Comment thread app/src/add_account.rs Dismissed
Comment thread app/src/add_account.rs Dismissed
Comment thread app/src/add_account.rs Dismissed
Comment thread app/src/add_account.rs Dismissed
Comment thread app/src/add_account.rs Dismissed
Comment thread ews/src/ntlm/tests.rs Dismissed
Comment thread ews/src/ntlm/tests.rs Dismissed
Comment thread ews/src/ntlm/tests.rs Dismissed
@g0shed
g0shed merged commit 23cd046 into main Dec 4, 2026
28 checks passed
@g0shed
g0shed deleted the ews-accounts branch December 4, 2026 15:12
@g0shed g0shed mentioned this pull request Dec 4, 2026
1 task done
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

Successfully merging this pull request may close these issues.

Corporative Email server - ERROR AUTH

2 participants