Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ the [releases page](https://github.com/c9dev/penguin-mail/releases).

### New

- Add a company Exchange Server account, for mail on an Exchange server your company runs itself that is reachable only through its web address. Choose Exchange Server when you add an account, then give your email address, the server address (the form starts from `https://mail.<your domain>/EWS/Exchange.asmx`), your user name and your password. A user name such as `DOMAIN\user` signs in with NTLM, the way Outlook does, including on servers that require Extended Protection; a server that offers only Negotiate or Basic over HTTPS works too, and a plain `http://` server never gets your password. You get your folders, new mail, reading, read and unread, flags, moving, deleting, searching, drafts and sending, and a server certificate your computer does not trust goes through the same review as other accounts. Microsoft 365 stays on Microsoft Graph. Exchange accounts have so far run only against a test server, not a real Exchange server, so please report what you find. They have no calendar, contacts or rules on the server, and they check for mail instead of being told of it.
- The label and folder picker has a search box that has focus when it opens. Type to narrow the list, press Up or Down to move through the matches, and press Enter to apply the first one or the one you moved to. With Gmail's shortcuts, `v` opens the picker.

- Accept the certificate of a server your computer does not trust, as other mail apps let you. When adding an account, and later on an account whose server shows a new or changed certificate, a review shows the server, why it was refused, the names it covers, who issued it, its dates and its SHA-256 fingerprint. Accept This Certificate trusts that one certificate for that server and account, and Penguin Mail asks again if the server shows another. It covers mail, sending, POP3, rules, calendars and contacts.
Expand Down
2 changes: 2 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Terms the code and its docs use for Gmail mail. The `domain` crate holds the cod

**JMAP account**: an account whose mail comes over JMAP (RFC 8620, RFC 8621), from any server that offers it: Fastmail, Stalwart, Cyrus, Apache James. What it offers beside mail follows its session's capabilities, never who runs the server. It signs in with the account password over Basic or a token over Bearer, kept in the keyring under `penguin-mail-jmap`. `Provider::Jmap`, served by `mailrs_sync::services::Jmap`, with its session URL in `jmap_accounts`. _Avoid_: Fastmail API account.

**Exchange account**: an account on an on-premises Exchange server, read and written over Exchange Web Services (EWS) at an address such as `https://mail.example.com/EWS/Exchange.asmx`. It signs in with NTLM (with channel binding), Negotiate carrying NTLM, or Basic over HTTPS, as `DOMAIN\user`, `user@domain` or a plain name, and the password is kept in the keyring beside the IMAP passwords. NTLM signs in a connection, so each account owns one kept-alive connection (`mailrs_ews::Connection`) that signs in again once when the server drops it. A move gives a message a new item id, so the store sees a deletion and a new message. Mail only, by polling; Microsoft 365 stays on Graph. `Provider::Ews`, served by `mailrs_sync::services::Ews`, with its address and user name in `ews_accounts`. _Avoid_: Outlook account, Exchange Online account.

**Session URL**: where a JMAP account's session lives (RFC 8620 section 2), which names every other URL the account's calls go to and what the server offers. Discovery finds it from the provider table, the `_jmap._tcp` SRV record or the domain's `/.well-known/jmap`. _Avoid_: JMAP endpoint, API URL (which is one URL the session names).

**JMAP calendar**: the calendar of a JMAP account whose session offers JMAP Calendars in the shape draft-ietf-jmap-calendars-32 defines (`mailrs_jmap::calendars::fits`), read and written as JSCalendar by the same adapter that serves the account's mail. JMAP's change feed covers the whole account, so each of its calendars' tokens is the account's CalendarEvent state. Shared calendars are listed from every compatible server account in the session. Their calendar ids, event ids and change tokens carry the owning server account, so reads and writes cannot confuse identical ids in different accounts; personal ids keep their old form. Every other account's calendar stays on CalDAV, and invitations still travel as iTIP mail. `AnyCalendar::Jmap`. _Avoid_: calendar API, JMAP CalDAV.
Expand Down
107 changes: 107 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "3"
members = ["domain", "tls", "mime", "gmail", "graph", "jmap", "discover", "imap", "dav", "sieve", "pop3", "store", "sync", "pgp", "smime", "ai", "cli", "client", "app", "testmail"]
members = ["domain", "tls", "mime", "gmail", "graph", "jmap", "ews", "discover", "imap", "dav", "sieve", "pop3", "store", "sync", "pgp", "smime", "ai", "cli", "client", "app", "testmail"]
exclude = ["vendor/ksni", "vendor/zbus"]

[workspace.package]
Expand All @@ -20,6 +20,7 @@ mailrs-mime = { path = "mime" }
mailrs-gmail = { path = "gmail" }
mailrs-graph = { path = "graph" }
mailrs-jmap = { path = "jmap" }
mailrs-ews = { path = "ews" }
mailrs-discover = { path = "discover" }
mailrs-imap = { path = "imap" }
mailrs-dav = { path = "dav" }
Expand Down Expand Up @@ -50,6 +51,9 @@ rrule = "0.14.0"
clap = { version = "4.6.10", features = ["derive"] }
dirs = "7.0.0"
encodify = "1.0.3"
# Thunderbird's Exchange Web Services types (MPL-2.0); mailrs-ews sends
# them over its own connection.
ews = "0.1.2"
encoding_rs = "0.8.44"
futures = "0.3.34"
# A `.pkpass` is a zip of a few small files; mime reads its `pass.json`
Expand All @@ -63,6 +67,11 @@ gtk = { package = "gtk4", version = "0.11.5" }
# The tokenizer behind the sanitizer, which reads mail HTML without a
# browser; ammonia already brings it.
html5ever = "0.40.1"
# NTLMv2 sign-in to Exchange: the keyed hash and the two digests it uses.
# hmac and md-5 are already in the tree through other crates.
hmac = "0.13.0"
md-5 = "0.11.0"
md4 = "0.11.0"
# The MX and SRV lookups discovery makes, through the system's DNS servers.
hickory-resolver = "0.26.4"
icalendar = "0.17.17"
Expand Down Expand Up @@ -106,6 +115,11 @@ thiserror = "2.0.21"
tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "net", "time", "sync", "io-util", "signal", "process", "fs"] }
# reqwest already brings it; discovery's probe runs TLS over tokio with it.
tokio-rustls = "0.26.6"
# The HTTP/1.1 client connection EWS signs in on; reqwest already brings all
# three. A pooled client cannot keep one NTLM connection per account.
http-body-util = "0.1.5"
hyper = { version = "1.13.0", default-features = false, features = ["client", "http1"] }
hyper-util = { version = "0.1.21", default-features = false, features = ["tokio"] }
toml = "1.2.3"
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ in. To change it, remove the account and add it again.
## Features

Penguin Mail has mail for Gmail, Microsoft (Outlook.com, Hotmail, Live and
Microsoft 365), IMAP and POP3 accounts, a calendar, contacts, OpenPGP and
S/MIME, rules, and an optional assistant. An IMAP or POP3 account gets its
Microsoft 365), IMAP, POP3 and company Exchange Server accounts, a calendar,
contacts, OpenPGP and S/MIME, rules, and an optional assistant. An IMAP or POP3 account gets its
calendar and contacts over CalDAV and CardDAV where the provider offers them,
and an IMAP account its rules over ManageSieve.

Expand Down
92 changes: 90 additions & 2 deletions app/src/add_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,48 @@
Failed(Failure),
}

/// The EWS address an email's domain suggests for the Exchange page.
pub fn ews_server_for(email: &str) -> Option<String> {
let domain = email.trim().rsplit_once('@')?.1;
(!domain.is_empty() && !domain.contains(char::is_whitespace))
.then(|| format!("https://mail.{domain}/EWS/Exchange.asmx"))
}

/// Whether the Exchange page has what a sign-in needs: an address, where
/// the server is, and a password. The password is taken as typed.
pub fn ews_ready(email: &str, server: &str, password: &str) -> bool {
email.trim().contains('@') && !server.trim().is_empty() && !password.is_empty()
}

/// The certificate an Exchange sign-in was refused for, when the person may
/// accept it.
pub fn refused_ews_certificate(
err: &anyhow::Error,
) -> Option<std::sync::Arc<mailrs_tls::CertIssue>> {
match err.downcast_ref::<mailrs_sync::sign_in::EwsError>()? {
mailrs_sync::sign_in::EwsError::Certificate(issue) => Some(issue.clone()),
_ => None,
}
}

/// What the Exchange page says of a sign-in that failed.
pub fn ews_problem(err: &anyhow::Error) -> String {
use mailrs_sync::sign_in::EwsError;
match err.downcast_ref::<EwsError>() {
Some(EwsError::Unauthorized) => gettext(
"The server refused the user name or password. If your company signs in with a domain, type the user name as DOMAIN\\user.",
),
Some(EwsError::Network(_) | EwsError::Tls(_) | EwsError::Certificate(_)) => gettext(
"The server did not answer at that address. Check the address and your connection.",
),
Some(EwsError::InsecureBasic) => gettext(
"This server would get your password unencrypted, so Penguin Mail does not send it.",
),
Some(EwsError::BadUrl(_)) => gettext("That does not look like an Exchange server address."),
_ => err.to_string(),
}
}

/// The certificate a failed sign-in was refused for, when the person may
/// accept it.
pub fn refused_certificate(err: &anyhow::Error) -> Option<std::sync::Arc<mailrs_tls::CertIssue>> {
Expand Down Expand Up @@ -1333,7 +1375,7 @@
match provider {
Provider::Gmail => role != mailrs_domain::Role::Archive,
Provider::Pop3 => role == mailrs_domain::Role::Inbox,
Provider::Imap | Provider::Microsoft | Provider::Jmap => true,
Provider::Imap | Provider::Microsoft | Provider::Jmap | Provider::Ews => true,
Provider::CalDav => false,
}
}
Expand Down Expand Up @@ -2249,9 +2291,55 @@

use super::*;

use mailrs_sync::sign_in::CalDavSignInError;
use mailrs_sync::sign_in::{CalDavSignInError, EwsEndpoint, EwsError};
use mailrs_sync::{BackendError, SyncError};

#[test]
fn the_exchange_page_suggests_a_server_from_the_email_domain() {
assert_eq!(
ews_server_for("ann@corp.example").as_deref(),
Some("https://mail.corp.example/EWS/Exchange.asmx")
);
assert_eq!(
ews_server_for(" ann@corp.example "),
ews_server_for("ann@corp.example")
);
assert_eq!(ews_server_for("ann"), None);
assert_eq!(ews_server_for("ann@"), None);
assert_eq!(ews_server_for("ann@bad domain"), None);
}

#[test]
fn a_bare_host_typed_on_the_exchange_page_becomes_the_ews_address() {
let url = EwsEndpoint::from_input("mail.corp.example").unwrap().url;
assert_eq!(url, "https://mail.corp.example/EWS/Exchange.asmx");
}

#[test]
fn the_exchange_page_needs_an_address_a_server_and_a_password() {
assert!(ews_ready("ann@corp.example", "mail.corp.example", "x"));
Comment thread
g0shed marked this conversation as resolved.
Dismissed
assert!(!ews_ready("ann", "mail.corp.example", "x"));
Comment thread
g0shed marked this conversation as resolved.
Dismissed
assert!(!ews_ready("ann@corp.example", " ", "x"));
Comment thread
g0shed marked this conversation as resolved.
Dismissed
assert!(!ews_ready("ann@corp.example", "mail.corp.example", ""));
Comment thread
g0shed marked this conversation as resolved.
Dismissed
// A space may be part of a password.
assert!(ews_ready("ann@corp.example", "h", " "));
Comment thread
g0shed marked this conversation as resolved.
Dismissed
}

#[test]
fn each_way_an_exchange_sign_in_fails_has_its_own_words() {
let say = |err: EwsError| ews_problem(&anyhow::Error::new(err));
assert!(say(EwsError::Unauthorized).contains("DOMAIN"));
assert!(say(EwsError::Network("refused".into())).contains("did not answer"));
assert!(say(EwsError::Tls("handshake".into())).contains("did not answer"));
assert!(say(EwsError::InsecureBasic).contains("unencrypted"));
assert!(say(EwsError::BadUrl("x".into())).contains("server address"));
assert_eq!(
say(EwsError::BadAnswer("odd".into())),
"could not read the server's answer: odd"
);
assert!(refused_ews_certificate(&anyhow::Error::new(EwsError::Unauthorized)).is_none());
}

#[test]
fn each_way_a_calendar_sign_in_fails_has_its_own_words() {
let no_calendar = "No calendar was found";
Expand Down
7 changes: 6 additions & 1 deletion app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,12 @@ impl App {
.accounts
.borrow()
.iter()
.filter(|a| matches!(a.provider, Provider::Imap | Provider::Pop3 | Provider::Jmap))
.filter(|a| {
matches!(
a.provider,
Provider::Imap | Provider::Pop3 | Provider::Jmap | Provider::Ews
)
})
.map(|a| a.id)
.collect();
let this = Rc::clone(self);
Expand Down
Loading
Loading