Email: Thunderbird natively integrates with Exchange using Rust

The Thunderbird team will integrate the Exchange connection natively with Rust in the future to increase security and performance and drive modernization.

Save to Pocket listen Print view
Ein roter Briefkasten an einer blauen Holzwand.

(Bild: Fabio Balbi / Shutterstock,com)

5 min. read
Contents
This article was originally published in German and has been automatically translated.

The next major version of Thunderbird, the Extended Support Release in July 2024, will offer a native Exchange connection written in Rust. For the time being, this will only handle email, with other services such as calendar and addresses to follow later.

Until now, an Exchange connection in the mail client was only possible via a plug-in such as Eule, but the Mozilla team is now implementing the Exchange Web Services (EWS) protocol in the client itself. In detail, Mozilla is working on elements for HTTP communication, which the team does not want to take over from existing C++ code for security reasons, but create from scratch in Rust. This requires a separate HTTP API (Crate moz_http) and an Await-Async functionality (Crate xpcom_async, similar to Promise in JavaScript).

However, the biggest challenge for the Mozilla team in dealing with EWS was to harmonize the XML structure of Exchange with that of Thunderbird. The existing crates in the Rust universe did not fully meet the needs, and a custom development was required: the xml_struct crate, which is available on GitHub. Another crate (ews), which defines types and an XML API, is also available on GitHub.

More and more IT companies are migrating to Rust. The Thunderbird team explains this step in detail in the blog, with the first three arguments relating to Rust in general:

  1. Storage security: Thunderbird accepts input from anyone as mail.
  2. Performance: Rust works natively on all platforms.
  3. Ecosystem: The modularity provides access to a large ecosystem in which many people also deal with e-mail.

Four further reasons apply to Thunderbird in particular:

  1. Firefox: Thunderbird is based on Firefox code, and this common structure already supports Rust. There is also a cross-platform component model (Cross-Platform Component Object Model, XPCOM) that enables function calls between Rust, C++ and JavaScript.
  2. Tools: Rust offers a large toolbox for the secure and reliable design of APIs and the associated documentation.
  3. Technical debt: The introduction of a new language forces you to rethink your outdated architecture.
  4. Portability: Rust crates can be used for other platforms, such as Android/K-9.

The choice was not easy for the team: "Thunderbird is a big project managed by a small team ... We need powerful tools to develop complex features relatively quickly, but we need to balance that with long-term maintainability."

The authors of the blog post also describe the challenges involved in connecting Rust. In particular, there is a lot of existing, difficult-to-understand and asynchronous code that does not match the peculiarities of Rust ("there is a lot of existing code with idiosyncratic asynchronous patterns that don't integrate nicely with idiomatic Rust").

The graphic shows the logical sequence of an Exchange request and the processing of the response.

(Bild: Mozilla/Thunderbird)

Mozilla's build concept poses a concrete problem: Thunderbird is a subproject (subtree) of Firefox, and the build is done from Firefox to Thunderbird. However, this direction causes problems with Rust's cargo concept. As a solution, the team defined a separate workspace and configured the upstream build tool mach so that the build was carried out from this workspace instead of from Firefox.

Another point: Thunderbird never fully integrated the XPCOM interoperability layer mentioned above, which is now required with the integration of Rust Exchange. The team has decided to add an adapter between the existing code and the new Rust parts (as crate ews_xpcom).

Further details on the Rust move can be found in a detailed online document.

The comments on the blog range from euphoric: "I'm thrilled with this amazing evolution of my favorite email program. Can't wait to see where it goes from here!" to critical: "If security is the goal, then storage security may be necessary, but it's obviously not sufficient. And Rust lacks many security features of other languages."

Some comments point out that Microsoft will replace EWS with the Cloud API Graph in 2026. Mozilla responds that EWS will still be in use for on-premises installations for a long time, and that this is the main use for many users. There are still problems with the Graph API, but the team is working on them.

(who)