Rename the identifiers that carried the upstream name
ci / fork-checks (pull_request) Successful in 16s
ci / build (pull_request) Successful in 7m53s

Everything clients, users and operators meet now carries the fork's name,
with no aliases (SPEC.md §2.4, changed here from "protocol identifiers
stay"):

- JMAP: upstream's registry capability is urn:inbuxa:jmap:registry, beside
  the fork's own urn:inbuxa:jmap.
- WebDAV lock and sync tokens are urn:inbuxa:dav*; clients resync once.
- Sieve: vnd.inbuxa.while and vnd.inbuxa.expressions. sieve-rs spells these
  into its compiler, so it's vendored (vendor/sieve-rs, 0.7.3) and patched in;
  a unit test fails if Cargo.lock ever moves past the vendored copy. The
  trusted runtime now names itself too, rather than answering sieve-rs's
  default.
- The web interface's OAuth client is inbuxa-webui. On every start the old
  stalwart-webui client is removed and any application naming it is moved
  over.
- The spam filter's blobs are INBUXA_SPAM_*; every start moves any left
  under the old keys, so a trained model survives.
- SQL stores and log files default to inbuxa, in the code and in the
  schema served to the admin (checksum regenerated).
- Settings are INBUXA_* only. A STALWART_* variable that's set where its
  INBUXA_* one isn't stops the server at startup, naming it.
- The version-upgrade messages link docs.inbuxa.org's migration page, and
  the OpenAPI description, smtp crate metadata and web-push test fixtures
  lose the name.

Kept on purpose, allowlisted with reasons: the OAuth key-derivation
contexts (renaming them would end every session and invalidate every
sealed client id) and the hashed application prefix.

Also fixes a latent start-up failure: ensure_client updated an existing
first-party client with a revision of 0, which the registry's assertion
never matches, so adding a redirect URI or changing the webmail secret
failed start-up. And the principal session test now expects
legacyProtocols (C-1, added 2026-09-21), which it had missed.

Tested: the server builds without warnings; common's 106 unit tests,
including the vendoring check; a new integration test for the two
start-up migrations; and the webdav, jmap, imap and SMTP Sieve suites.
This commit is contained in:
2026-09-22 19:33:02 -07:00
parent 4799d191a0
commit cc6f1eb298
129 changed files with 20504 additions and 168 deletions
+224
View File
@@ -0,0 +1,224 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use mail_parser::{MimeHeaders, PartType, decoders::html::html_to_text};
use crate::{
Context,
compiler::{
Number,
grammar::{
MatchType,
tests::test_body::{BodyTransform, TestBody},
},
},
};
use super::{TestResult, mime::ContentTypeFilter};
impl TestBody {
pub(crate) fn exec(&self, ctx: &mut Context) -> TestResult {
// Check Subject (not a Sieve standard)
let key_list = ctx.eval_values(&self.key_list);
if self.include_subject {
let subject = if !matches!(&self.body_transform, BodyTransform::Raw) {
ctx.message.subject().unwrap_or_default()
} else {
ctx.message.header_raw("Subject").unwrap_or_default()
};
for (key, pattern) in key_list.iter().zip(self.key_list.iter()) {
let result = match &self.match_type {
MatchType::Is => self.comparator.is(&subject, key),
MatchType::Contains => {
self.comparator.contains(subject, key.to_string().as_ref())
}
MatchType::Value(rel_match) => {
self.comparator.relational(rel_match, &subject, key)
}
MatchType::Matches(_) => self.comparator.matches(
subject,
key.to_string().as_ref(),
0,
&mut Vec::new(),
),
MatchType::Regex(_) => {
self.comparator
.regex(pattern, key, subject, 0, &mut Vec::new())
}
_ => break,
};
if result {
return TestResult::Bool(result ^ self.is_not);
}
}
}
let ct_filter = match &self.body_transform {
BodyTransform::Text | BodyTransform::Raw => Vec::new(),
BodyTransform::Content(values) => {
let mut ct_filter = Vec::with_capacity(values.len());
for ct in values {
let ct = ctx.eval_value(ct);
if ct.is_empty() {
break;
} else if let Some(ctf) = ContentTypeFilter::parse(ct.to_string().as_ref()) {
ct_filter.push(ctf);
} else {
return TestResult::Bool(false ^ self.is_not);
}
}
ct_filter
}
};
let result = if let MatchType::Count(rel_match) = &self.match_type {
let mut count = 0;
let mut result = false;
ctx.find_nested_parts(&ctx.message, &ct_filter, &mut |_part, _raw_message| {
count += 1;
false
});
for key in &self.key_list {
if rel_match.cmp(&Number::from(count), &ctx.eval_value(key).to_number()) {
result = true;
break;
}
}
result
} else {
ctx.find_nested_parts(&ctx.message, &ct_filter, &mut |part, raw_message| {
let text = match (&self.body_transform, &part.body) {
(BodyTransform::Content(_), PartType::Message(message)) => {
if let Some(part) = message.parts.first() {
String::from_utf8_lossy(
raw_message
.get(
part.raw_header_offset() as usize
..part.raw_body_offset() as usize,
)
.unwrap_or(b""),
)
} else {
return false;
}
}
(BodyTransform::Content(_), PartType::Multipart(_)) => {
if let Some(boundary) =
part.content_type().and_then(|ct| ct.attribute("boundary"))
{
let mime_body = std::str::from_utf8(
raw_message
.get(
part.raw_body_offset() as usize
..part.raw_end_offset() as usize,
)
.unwrap_or(b""),
)
.unwrap_or("");
let mut mime_part = String::with_capacity(64);
if let Some((prologue, epilogue)) =
mime_body.split_once(&format!("\n--{boundary}"))
{
mime_part.push_str(prologue);
if let Some((_, epilogue)) =
epilogue.rsplit_once(&format!("\n--{boundary}--"))
{
mime_part.push_str(epilogue);
}
}
mime_part.into()
} else {
String::from_utf8_lossy(
raw_message
.get(
part.raw_body_offset() as usize
..part.raw_end_offset() as usize,
)
.unwrap_or(b""),
)
}
}
(BodyTransform::Raw, _) => {
match &part.body {
PartType::Text(text) if part.raw_body_offset() == 0 => {
// Inserted part
text.as_ref().into()
}
_ if part.raw_end_offset() > part.raw_body_offset() => {
String::from_utf8_lossy(
raw_message
.get(
part.raw_body_offset() as usize
..part.raw_end_offset() as usize,
)
.unwrap_or(b""),
)
}
_ => return false,
}
}
(_, PartType::Text(text))
| (BodyTransform::Content(_), PartType::Html(text)) => text.as_ref().into(),
(_, PartType::Html(html)) => html_to_text(html.as_ref()).into(),
(
BodyTransform::Text,
PartType::Binary(bytes) | PartType::InlineBinary(bytes),
) if part.content_type().is_some_and(|ct| {
ct.c_type.eq_ignore_ascii_case("application")
&& ct.c_subtype.as_ref().is_some_and(|st| st.contains("xml"))
}) =>
{
html_to_text(std::str::from_utf8(bytes.as_ref()).unwrap_or("")).into()
}
(
BodyTransform::Content(_),
PartType::Binary(bytes) | PartType::InlineBinary(bytes),
) => String::from_utf8_lossy(bytes.as_ref()),
_ => {
return false;
}
};
let mut result = false;
for (key, pattern) in key_list.iter().zip(self.key_list.iter()) {
result = match &self.match_type {
MatchType::Is => self.comparator.is(&text.as_ref(), key),
MatchType::Contains => self
.comparator
.contains(text.as_ref(), key.to_string().as_ref()),
MatchType::Value(rel_match) => {
self.comparator.relational(rel_match, &text.as_ref(), key)
}
MatchType::Matches(_) => self.comparator.matches(
text.as_ref(),
key.to_string().as_ref(),
0,
&mut Vec::new(),
),
MatchType::Regex(_) => {
self.comparator
.regex(pattern, key, text.as_ref(), 0, &mut Vec::new())
}
_ => false,
};
if result {
break;
}
}
result
})
};
TestResult::Bool(result ^ self.is_not)
}
}