✨ (user): Respeta las preferencias por usuario
This commit is contained in:
parent
0472e698ae
commit
a29f0f2b75
24 changed files with 239 additions and 201 deletions
|
|
@ -5,7 +5,7 @@ use pagetop::prelude::*;
|
|||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::config::{self, MailTransport, SmtpSecurity};
|
||||
use crate::config;
|
||||
use crate::{Email, LOCALES_MAIL, Mailbox};
|
||||
|
||||
// Ruta de la página, relativa a la raíz del panel.
|
||||
|
|
@ -124,8 +124,8 @@ async fn test_mail_post(
|
|||
// Aviso si el transporte configurado no entrega los correos.
|
||||
fn not_delivered_warning() -> Option<Lc> {
|
||||
let key = match config::SETTINGS.transport {
|
||||
MailTransport::Log => "test_log_warning",
|
||||
MailTransport::Memory => "test_memory_warning",
|
||||
config::MailTransport::Log => "test_log_warning",
|
||||
config::MailTransport::Memory => "test_memory_warning",
|
||||
_ => return None,
|
||||
};
|
||||
Some(Lc::t(key, &LOCALES_MAIL))
|
||||
|
|
@ -138,11 +138,11 @@ fn settings_summary() -> Block {
|
|||
let text = |value: &Option<String>| value.clone().map_or_else(none, Lc::n);
|
||||
|
||||
let transport = match settings.transport {
|
||||
MailTransport::Smtp => "transport_smtp",
|
||||
MailTransport::Sendmail => "transport_sendmail",
|
||||
MailTransport::File => "transport_file",
|
||||
MailTransport::Log => "transport_log",
|
||||
MailTransport::Memory => "transport_memory",
|
||||
config::MailTransport::Smtp => "transport_smtp",
|
||||
config::MailTransport::Sendmail => "transport_sendmail",
|
||||
config::MailTransport::File => "transport_file",
|
||||
config::MailTransport::Log => "transport_log",
|
||||
config::MailTransport::Memory => "transport_memory",
|
||||
};
|
||||
let mut rows = vec![
|
||||
("test_transport", Lc::t(transport, &LOCALES_MAIL)),
|
||||
|
|
@ -153,25 +153,25 @@ fn settings_summary() -> Block {
|
|||
rows.push(("test_redirect_to", text(&settings.redirect_to)));
|
||||
}
|
||||
match settings.transport {
|
||||
MailTransport::Smtp => {
|
||||
config::MailTransport::Smtp => {
|
||||
let smtp = &settings.smtp;
|
||||
let (security, default_port) = match smtp.security {
|
||||
SmtpSecurity::None => ("security_none", 25),
|
||||
SmtpSecurity::Opportunistic => ("security_opportunistic", 25),
|
||||
SmtpSecurity::StartTls => ("security_starttls", 587),
|
||||
SmtpSecurity::Tls => ("security_tls", 465),
|
||||
config::SmtpSecurity::None => ("security_none", 25),
|
||||
config::SmtpSecurity::Opportunistic => ("security_opportunistic", 25),
|
||||
config::SmtpSecurity::StartTls => ("security_starttls", 587),
|
||||
config::SmtpSecurity::Tls => ("security_tls", 465),
|
||||
};
|
||||
let port = smtp.port.unwrap_or(default_port).to_string();
|
||||
rows.push(("test_smtp_server", Lc::n(util::join!(smtp.host, ":", port))));
|
||||
rows.push(("test_smtp_security", Lc::t(security, &LOCALES_MAIL)));
|
||||
}
|
||||
MailTransport::Sendmail => {
|
||||
config::MailTransport::Sendmail => {
|
||||
rows.push(("test_sendmail_command", text(&settings.sendmail.command)));
|
||||
}
|
||||
MailTransport::File => {
|
||||
config::MailTransport::File => {
|
||||
rows.push(("test_file_dir", Lc::n(settings.file.dir.clone())));
|
||||
}
|
||||
MailTransport::Log | MailTransport::Memory => {}
|
||||
config::MailTransport::Log | config::MailTransport::Memory => {}
|
||||
}
|
||||
|
||||
let mut table = Table::new();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
use crate::config::{self, MailTransport, SmtpSecurity, SmtpSettings};
|
||||
use crate::config;
|
||||
use crate::{Email, MailError, Mailbox, outbox};
|
||||
|
||||
use lettre::Transport as _;
|
||||
|
|
@ -289,22 +289,28 @@ impl Mailer {
|
|||
#[cfg(feature = "queue")]
|
||||
crate::queue::check_settings()?;
|
||||
let slots = match settings.transport {
|
||||
MailTransport::Smtp => slots("mail.smtp.pool_max_size", settings.smtp.pool_max_size)?,
|
||||
MailTransport::Sendmail => slots(
|
||||
config::MailTransport::Smtp => {
|
||||
slots("mail.smtp.pool_max_size", settings.smtp.pool_max_size)?
|
||||
}
|
||||
config::MailTransport::Sendmail => slots(
|
||||
"mail.sendmail.max_concurrent",
|
||||
settings.sendmail.max_concurrent,
|
||||
)?,
|
||||
MailTransport::File => slots("mail.file.max_concurrent", settings.file.max_concurrent)?,
|
||||
config::MailTransport::File => {
|
||||
slots("mail.file.max_concurrent", settings.file.max_concurrent)?
|
||||
}
|
||||
// Sin turnos: se entregan al momento.
|
||||
MailTransport::Log | MailTransport::Memory => 1,
|
||||
config::MailTransport::Log | config::MailTransport::Memory => 1,
|
||||
};
|
||||
let transport = match settings.transport {
|
||||
MailTransport::Smtp => Transport::Smtp(smtp_transport(&settings.smtp)?),
|
||||
MailTransport::Sendmail => Transport::Sendmail(match &settings.sendmail.command {
|
||||
Some(command) => AsyncSendmailTransport::new_with_command(command),
|
||||
None => AsyncSendmailTransport::new(),
|
||||
}),
|
||||
MailTransport::File => {
|
||||
config::MailTransport::Smtp => Transport::Smtp(smtp_transport(&settings.smtp)?),
|
||||
config::MailTransport::Sendmail => {
|
||||
Transport::Sendmail(match &settings.sendmail.command {
|
||||
Some(command) => AsyncSendmailTransport::new_with_command(command),
|
||||
None => AsyncSendmailTransport::new(),
|
||||
})
|
||||
}
|
||||
config::MailTransport::File => {
|
||||
let dir = PathBuf::from(&settings.file.dir);
|
||||
std::fs::create_dir_all(&dir).map_err(|source| MailError::CreateDir {
|
||||
path: dir.clone(),
|
||||
|
|
@ -312,8 +318,8 @@ impl Mailer {
|
|||
})?;
|
||||
Transport::File(AsyncFileTransport::new(dir))
|
||||
}
|
||||
MailTransport::Log => Transport::Log,
|
||||
MailTransport::Memory => Transport::Memory,
|
||||
config::MailTransport::Log => Transport::Log,
|
||||
config::MailTransport::Memory => Transport::Memory,
|
||||
};
|
||||
let redirect_to = match settings.redirect_to.as_deref().and_then(util::non_blank) {
|
||||
Some(address) => Some(address.parse::<Address>().map_err(|source| {
|
||||
|
|
@ -410,7 +416,7 @@ fn tickets(slots: usize, max_waiting: u32) -> usize {
|
|||
.min(Semaphore::MAX_PERMITS)
|
||||
}
|
||||
|
||||
fn smtp_transport(smtp: &SmtpSettings) -> Result<SmtpTransport, MailError> {
|
||||
fn smtp_transport(smtp: &config::SmtpSettings) -> Result<SmtpTransport, MailError> {
|
||||
let tls_parameters = || {
|
||||
TlsParameters::builder(smtp.host.clone())
|
||||
.dangerous_accept_invalid_certs(smtp.accept_invalid_certs)
|
||||
|
|
@ -418,10 +424,10 @@ fn smtp_transport(smtp: &SmtpSettings) -> Result<SmtpTransport, MailError> {
|
|||
.map_err(|err| invalid_setting("mail.smtp", MailError::Smtp(err)))
|
||||
};
|
||||
let (tls, default_port) = match smtp.security {
|
||||
SmtpSecurity::None => (Tls::None, 25),
|
||||
SmtpSecurity::Opportunistic => (Tls::Opportunistic(tls_parameters()?), 25),
|
||||
SmtpSecurity::StartTls => (Tls::Required(tls_parameters()?), 587),
|
||||
SmtpSecurity::Tls => (Tls::Wrapper(tls_parameters()?), 465),
|
||||
config::SmtpSecurity::None => (Tls::None, 25),
|
||||
config::SmtpSecurity::Opportunistic => (Tls::Opportunistic(tls_parameters()?), 25),
|
||||
config::SmtpSecurity::StartTls => (Tls::Required(tls_parameters()?), 587),
|
||||
config::SmtpSecurity::Tls => (Tls::Wrapper(tls_parameters()?), 465),
|
||||
};
|
||||
let mut builder = SmtpTransport::builder_dangerous(&smtp.host)
|
||||
.port(smtp.port.unwrap_or(default_port))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue