mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2024-11-28 09:07:32 +00:00
Fixed is_local_domain Sieve function (closes #622)
This commit is contained in:
parent
a27ac74ad5
commit
afee02024e
9 changed files with 59 additions and 73 deletions
|
@ -335,7 +335,7 @@ async fn exec_remote_(ctx: &PluginContext<'_>) -> trc::Result<Variable> {
|
|||
}
|
||||
|
||||
pub async fn exec_local_domain(ctx: PluginContext<'_>) -> trc::Result<Variable> {
|
||||
let domain = ctx.arguments[0].to_string();
|
||||
let domain = ctx.arguments[1].to_string();
|
||||
|
||||
if !domain.is_empty() {
|
||||
return match &ctx.arguments[0] {
|
||||
|
|
|
@ -88,7 +88,7 @@ impl Tracers {
|
|||
crate::config::tracers::ConsoleTracer {
|
||||
ansi: true,
|
||||
multiline: false,
|
||||
buffered: true,
|
||||
buffered: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -66,6 +66,15 @@ impl<const N: usize> AtomicBitset<N> {
|
|||
self.0[i].store(0, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
for i in 0..N {
|
||||
if self.0[i].load(Ordering::Relaxed) != 0 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> Bitset<N> {
|
||||
|
|
|
@ -291,6 +291,10 @@ impl Collector {
|
|||
Collector::reload();
|
||||
}
|
||||
|
||||
pub fn is_enabled() -> bool {
|
||||
!INTERESTS.is_empty()
|
||||
}
|
||||
|
||||
pub fn reload() {
|
||||
Event::new(EventType::Tracing(TracingEvent::Update)).send()
|
||||
}
|
||||
|
|
|
@ -325,65 +325,6 @@ impl Color {
|
|||
mod tests {
|
||||
use crate::{EventType, Level};
|
||||
|
||||
/*fn pepe() -> crate::Pop3Event {
|
||||
crate::Pop3Event::Fetch
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_test() {
|
||||
let c = 1;
|
||||
|
||||
crate::collector::Collector::collect_metrics(
|
||||
EventType::Pop3(crate::Pop3Event::Quit),
|
||||
&[(Key::AccountId, 1u32.into()), (Key::SpanId, 2u32.into())],
|
||||
);
|
||||
|
||||
event_macro::event!(
|
||||
Pop3(crate::Pop3Event::Quit),
|
||||
SpanId = "const",
|
||||
Size = 1234,
|
||||
Contents = {
|
||||
if true {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
event_macro::event!(
|
||||
Pop3(if c == 1 {
|
||||
crate::Pop3Event::RawInput
|
||||
} else {
|
||||
crate::Pop3Event::RawOutput
|
||||
}),
|
||||
SpanId = "abc",
|
||||
Size = 1234,
|
||||
Contents = {
|
||||
if true {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let tutu = pepe();
|
||||
|
||||
event_macro::event!(
|
||||
Pop3(tutu),
|
||||
SpanId = "tutu",
|
||||
Size = 1234,
|
||||
Contents = {
|
||||
if true {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
);
|
||||
}*/
|
||||
|
||||
#[test]
|
||||
fn print_all_events() {
|
||||
assert!(!Level::Disable.is_contained(Level::Warn));
|
||||
|
|
|
@ -10,3 +10,8 @@ eval "query('sql', 'INSERT OR IGNORE INTO blocked_senders (addr) VALUES (?)', 'm
|
|||
if eval "query('sql', 'SELECT 1 FROM blocked_senders WHERE addr=? LIMIT 1', [envelope.from])" {
|
||||
reject "Your address has been blocked.";
|
||||
}
|
||||
|
||||
if eval "!is_local_domain('', 'localdomain.org') || is_local_domain('', 'other.org')" {
|
||||
let "reason" "'result: ' + is_local_domain('', 'localdomain.org') + ' ' + is_local_domain('', 'other.org')";
|
||||
reject "is_local_domain function failed: ${reason}";
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ use std::path::PathBuf;
|
|||
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
use jemallocator::Jemalloc;
|
||||
#[cfg(test)]
|
||||
use trc::collector::Collector;
|
||||
|
||||
#[cfg(not(target_env = "msvc"))]
|
||||
#[global_allocator]
|
||||
|
@ -59,3 +61,14 @@ impl AssertConfig for utils::config::Config {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn enable_logging() {
|
||||
use common::config::tracers::Tracers;
|
||||
|
||||
if let Ok(level) = std::env::var("LOG") {
|
||||
if !Collector::is_enabled() {
|
||||
Tracers::test_tracer(level.parse().expect("Invalid log level"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,15 @@
|
|||
use core::panic;
|
||||
use std::{fmt::Write, fs, path::PathBuf};
|
||||
|
||||
use crate::smtp::{
|
||||
build_smtp,
|
||||
inbound::{sign::SIGNATURES, TestMessage, TestQueueEvent},
|
||||
session::{TestSession, VerifyResponse},
|
||||
TempDir, TestSMTP,
|
||||
use crate::{
|
||||
enable_logging,
|
||||
smtp::{
|
||||
build_smtp,
|
||||
inbound::{sign::SIGNATURES, TestMessage, TestQueueEvent},
|
||||
session::{TestSession, VerifyResponse},
|
||||
TempDir, TestSMTP,
|
||||
},
|
||||
AssertConfig,
|
||||
};
|
||||
use common::Core;
|
||||
|
||||
|
@ -28,6 +32,7 @@ data = "sql"
|
|||
lookup = "sql"
|
||||
blob = "sql"
|
||||
fts = "sql"
|
||||
directory = "local"
|
||||
|
||||
[store."sql"]
|
||||
type = "sqlite"
|
||||
|
@ -84,17 +89,24 @@ message-id = true
|
|||
date = true
|
||||
return-path = false
|
||||
|
||||
[directory."local"]
|
||||
type = "memory"
|
||||
|
||||
[[directory."local".principals]]
|
||||
name = "john"
|
||||
description = "John Doe"
|
||||
secret = "secret"
|
||||
email = ["john@localdomain.org", "jdoe@localdomain.org", "john.doe@localdomain.org"]
|
||||
email-list = ["info@localdomain.org"]
|
||||
member-of = ["sales"]
|
||||
|
||||
|
||||
"#;
|
||||
|
||||
#[tokio::test]
|
||||
async fn sieve_scripts() {
|
||||
/*let disable = 1;
|
||||
tracing::subscriber::set_global_default(
|
||||
tracing_subscriber::FmtSubscriber::builder()
|
||||
.with_max_level(tracing::Level::TRACE)
|
||||
.finish(),
|
||||
)
|
||||
.unwrap();*/
|
||||
// Enable logging
|
||||
enable_logging();
|
||||
|
||||
// Add test scripts
|
||||
let mut config = CONFIG.to_string() + SIGNATURES;
|
||||
|
@ -144,6 +156,7 @@ async fn sieve_scripts() {
|
|||
let stores = Stores::parse_all(&mut config).await;
|
||||
let core = Core::parse(&mut config, stores, Default::default()).await;
|
||||
let mut qr = inner.init_test_queue(&core);
|
||||
config.assert_no_errors();
|
||||
|
||||
// Build session
|
||||
let core = build_smtp(core, inner);
|
||||
|
|
|
@ -175,6 +175,7 @@ impl TestSession for Session<DummyIo> {
|
|||
)
|
||||
.await
|
||||
.unwrap();
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
self.response().assert_code(expected_code);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue