You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Remove dependency on mas-email and lettre in mas-config
This commit is contained in:
@ -24,7 +24,6 @@ serde = { version = "1.0.150", features = ["derive"] }
|
||||
serde_with = { version = "2.1.0", features = ["hex", "chrono"] }
|
||||
serde_json = "1.0.89"
|
||||
sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "postgres"] }
|
||||
lettre = { version = "0.10.1", default-features = false, features = ["serde", "builder"] }
|
||||
|
||||
pem-rfc7468 = "0.6.0"
|
||||
rustls-pemfile = "1.0.1"
|
||||
@ -36,11 +35,8 @@ indoc = "1.0.7"
|
||||
mas-jose = { path = "../jose" }
|
||||
mas-keystore = { path = "../keystore" }
|
||||
mas-iana = { path = "../iana" }
|
||||
mas-email = { path = "../email" }
|
||||
|
||||
[features]
|
||||
native-roots = ["mas-email/native-roots"]
|
||||
webpki-roots = ["mas-email/webpki-roots"]
|
||||
docker = []
|
||||
|
||||
[[bin]]
|
||||
|
@ -14,10 +14,7 @@
|
||||
|
||||
use std::num::NonZeroU16;
|
||||
|
||||
use anyhow::Context;
|
||||
use async_trait::async_trait;
|
||||
use lettre::{message::Mailbox, Address};
|
||||
use mas_email::MailTransport;
|
||||
use rand::Rng;
|
||||
use schemars::{
|
||||
gen::SchemaGenerator,
|
||||
@ -59,22 +56,14 @@ pub struct Credentials {
|
||||
pub enum EmailSmtpMode {
|
||||
/// Plain text
|
||||
Plain,
|
||||
|
||||
/// StartTLS (starts as plain text then upgrade to TLS)
|
||||
StartTls,
|
||||
|
||||
/// TLS
|
||||
Tls,
|
||||
}
|
||||
|
||||
impl From<&EmailSmtpMode> for mas_email::SmtpMode {
|
||||
fn from(value: &EmailSmtpMode) -> Self {
|
||||
match value {
|
||||
EmailSmtpMode::Plain => Self::Plain,
|
||||
EmailSmtpMode::StartTls => Self::StartTls,
|
||||
EmailSmtpMode::Tls => Self::Tls,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What backend should be used when sending emails
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(tag = "transport", rename_all = "snake_case")]
|
||||
@ -118,9 +107,8 @@ impl Default for EmailTransportConfig {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_email() -> Mailbox {
|
||||
let address = Address::new("root", "localhost").unwrap();
|
||||
Mailbox::new(Some("Authentication Service".to_owned()), address)
|
||||
fn default_email() -> String {
|
||||
r#""Authentication Service" <root@localhost>"#.to_owned()
|
||||
}
|
||||
|
||||
fn default_sendmail_command() -> String {
|
||||
@ -133,12 +121,12 @@ pub struct EmailConfig {
|
||||
/// Email address to use as From when sending emails
|
||||
#[serde(default = "default_email")]
|
||||
#[schemars(schema_with = "mailbox_schema")]
|
||||
pub from: Mailbox,
|
||||
pub from: String,
|
||||
|
||||
/// Email address to use as Reply-To when sending emails
|
||||
#[serde(default = "default_email")]
|
||||
#[schemars(schema_with = "mailbox_schema")]
|
||||
pub reply_to: Mailbox,
|
||||
pub reply_to: String,
|
||||
|
||||
/// What backend should be used when sending emails
|
||||
#[serde(flatten, default)]
|
||||
@ -172,30 +160,3 @@ impl ConfigurationSection<'_> for EmailConfig {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmailTransportConfig {
|
||||
/// Create a [`lettre::Transport`] out of this config
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the transport could not be created
|
||||
pub async fn to_transport(&self) -> Result<MailTransport, anyhow::Error> {
|
||||
match self {
|
||||
Self::Blackhole => Ok(MailTransport::blackhole()),
|
||||
Self::Smtp {
|
||||
mode,
|
||||
hostname,
|
||||
credentials,
|
||||
port,
|
||||
} => {
|
||||
let credentials = credentials
|
||||
.clone()
|
||||
.map(|c| mas_email::SmtpCredentials::new(c.username, c.password));
|
||||
MailTransport::smtp(mode.into(), hostname, port.as_ref().copied(), credentials)
|
||||
.context("failed to build SMTP transport")
|
||||
}
|
||||
EmailTransportConfig::Sendmail { command } => Ok(MailTransport::sendmail(command)),
|
||||
EmailTransportConfig::AwsSes => Ok(MailTransport::aws_ses().await?),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user