- mail-oci: OCI Email Delivery client (signed REST), per-customer domain/DKIM/sender onboarding, suppression mirror, sending limits - mail-mta: RelayPool transport with OCI primary, optional secondary, health/back-off/quota failover; direct MTA kept but off - mail-inbound: DSN/ARF/DMARC/TLS-RPT parsing + HMAC-signed POST /inbound/raw ingest (no port 25) - workers/inbound-forwarder: Cloudflare Email Routing worker forwarding raw mail over HTTPS Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
68 lines
2.9 KiB
Rust
68 lines
2.9 KiB
Rust
//! Runs the inbound MX locally with `LoggingSink`, plus the HTTPS ingest
|
|
//! when `INBOUND_HTTP_SECRET` (and optionally `INBOUND_HTTP_LISTEN`) is set.
|
|
//!
|
|
//! ```sh
|
|
//! INBOUND_DOMAINS=dev.test INBOUND_DEV_SELF_SIGNED=1 cargo run -p mail-inbound --example serve
|
|
//! INBOUND_HTTP_SECRET=<32+ chars> INBOUND_HTTP_LISTEN=127.0.0.1:8585 ... cargo run -p mail-inbound --example serve
|
|
//! ```
|
|
//! `INBOUND_DEV_SELF_SIGNED=1` generates a self-signed certificate under
|
|
//! `DEV_DIR` (default `/tmp/scribase-mail-dev`) when no TLS files are given.
|
|
//! If `INBOUND_DNS_OVERRIDES_FILE` is unset but `DEV_DIR/dns-overrides.txt`
|
|
//! exists (written by `mail-mta`'s `send_local`), it is used.
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use mail_inbound::{InboundConfig, InboundServer, IngestConfig, LoggingSink, TlsFiles};
|
|
|
|
fn self_signed(dir: &std::path::Path, hostname: &str) -> Result<TlsFiles, Box<dyn std::error::Error>> {
|
|
let cert_path = dir.join("inbound-cert.pem");
|
|
let key_path = dir.join("inbound-key.pem");
|
|
if !cert_path.exists() || !key_path.exists() {
|
|
let certified = rcgen::generate_simple_self_signed(vec![hostname.to_owned(), "localhost".to_owned()])?;
|
|
std::fs::write(&cert_path, certified.cert.pem())?;
|
|
std::fs::write(&key_path, certified.signing_key.serialize_pem())?;
|
|
println!("generated self-signed certificate for {hostname} at {}", cert_path.display());
|
|
}
|
|
Ok(TlsFiles { cert_path, key_path })
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "info,mail_inbound=debug".into()),
|
|
)
|
|
.init();
|
|
let dir = PathBuf::from(std::env::var("DEV_DIR").unwrap_or_else(|_| "/tmp/scribase-mail-dev".into()));
|
|
std::fs::create_dir_all(&dir)?;
|
|
if std::env::var("INBOUND_DOMAINS").is_err() {
|
|
// SAFETY-free: single-threaded at this point; edition 2021 set_var is safe.
|
|
std::env::set_var("INBOUND_DOMAINS", "dev.test");
|
|
}
|
|
let mut cfg = InboundConfig::from_env()?;
|
|
if cfg.tls.is_none() && std::env::var("INBOUND_DEV_SELF_SIGNED").is_ok() {
|
|
cfg.tls = Some(self_signed(&dir, &cfg.hostname)?);
|
|
}
|
|
if cfg.dns_overrides_file.is_none() {
|
|
let candidate = dir.join("dns-overrides.txt");
|
|
if candidate.exists() {
|
|
cfg.dns_overrides_file = Some(candidate);
|
|
}
|
|
}
|
|
let server = InboundServer::bind(cfg, Arc::new(LoggingSink)).await?;
|
|
println!("listening on {}", server.local_addr()?);
|
|
if IngestConfig::enabled_by_env() {
|
|
let ingest = server.http_ingest(IngestConfig::from_env()?).await?;
|
|
println!("http ingest on {}", ingest.local_addr()?);
|
|
tokio::spawn(async move {
|
|
if let Err(e) = ingest.run().await {
|
|
tracing::error!(error = %e, "http ingest stopped");
|
|
}
|
|
});
|
|
}
|
|
server.run().await?;
|
|
Ok(())
|
|
}
|