Skip to content

Upgraded MailKit and MimeKit to v5.0 - #1226

Merged
SommerEngineering merged 5 commits into
MindWorkAI:mainfrom
SommerEngineering:upgrade-mailkit-5
Nov 24, 2026
Merged

SommerEngineering merged 5 commits into
MindWorkAI:mainfrom
SommerEngineering:upgrade-mailkit-5

Conversation

@SommerEngineering

Copy link
Copy Markdown
Member

Summary

MailKit 5.0 and MimeKit 5.0 are major releases with many breaking changes. This pull request moves the mailboxes to them and keeps everything the index of a mailbox depends on as it was.

  • MailKit now depends on MimeKit.Core instead of the full MimeKit, so BouncyCastle.Cryptography and System.Security.Cryptography.Pkcs leave the app. AI Studio detects encrypted mails by their content types alone and needs no cryptography of MimeKit.
  • The compiler asked for little: the IMAP capabilities are a collection instead of flags (Contains(ImapCapability.X)), ContentEncoding.Default is now Unspecified, and attachments are fetched with offsets of type long.
  • MimeKit 5 no longer decodes internationalized domains: MailboxAddress.Address returns xn--mller-kva.example instead of müller.example. The new MailHeaders.ReadAddress decodes them with GetAddress(false), as MimeKit 4 did. Otherwise, on servers without OBJECTID and X-GM-MSGID, every mail from such a domain would get a new key and be embedded again, and the index would hold both forms of an address. A new test pins the keys of three mails as MimeKit 4.18.2 made them.
  • MimeKit 5 limits a single header field to 16 KB, and MailKit then hands over the mail with an empty header block instead of failing. A mail to a few hundred people, or one of a long thread, would have been indexed without sender, subject, and date, and its key would rest on its size alone. The connector raises the limit to 1 MB before the first fetch. The sync now also skips a mail whose header block is empty, as it skips one without a header block; MailKit 4 already returned an empty one for a header block it could not parse.
  • Side finding: MailKit 5 reads a BODYSTRUCTURE of any depth without recursion, which left our encryption detection as the only recursive walk over it. It now uses a stack of its own, so a mail nested deeply on purpose cannot end the app with a stack overflow.

Users should notice no change.

Related proposal or issue

none

How did you test it?

  • dotnet run -- verify: all 5 checks passed.
  • The first commit pins the keys of three mails, among them one from an internationalized domain, under MimeKit 4.18.2. They stay the same after the upgrade. A counter-check with Address instead of GetAddress(false) made them fail.
  • New tests: a header block whose To field lists 1,000 recipients is read as a whole, while MimeKit's default limit refuses it; a structure 100,000 levels deep; the first encrypted part decides.
  • Manual test: AI Studio still connects to a real mailbox.
  • Not tested by hand: Exchange without OBJECTID, senders from internationalized domains, and mails with very long header fields. The unit tests cover these with MimeKit itself.

Wiki

none

Required statements

  • Review: I have reviewed every change in this pull request and can explain it when asked.
  • License: I license my contribution in this pull request, including all commits I add to it later, under the MIT License, and I agree that it is distributed as part of MindWork AI Studio under the project license or under the MIT License.
  • Right to contribute: The contribution is my own work, or I have permission to submit it, including the consent of my employer or client where needed. To the best of my knowledge, it does not infringe the rights of others, and AI-generated parts do not reproduce third-party code under incompatible terms.
  • Changes by maintainers: I understand that the maintainers will change this pull request to fit the product, and that they may close it.

@SommerEngineering SommerEngineering self-assigned this Nov 24, 2026
@SommerEngineering
SommerEngineering marked this pull request as ready for review November 24, 2026 07:35
@SommerEngineering
SommerEngineering requested a review from a team as a code owner November 24, 2026 07:35
@SommerEngineering
SommerEngineering merged commit f6a4348 into MindWorkAI:main Nov 24, 2026
8 checks passed
@SommerEngineering
SommerEngineering deleted the upgrade-mailkit-5 branch November 24, 2026 07:36
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.

1 participant