fix: quita cualquier espacio (no solo bordes) de host/usuario/remitente/destino SMTP
trim() no corregia un espacio colado a mitad del host (ej. "mail.linkedcorp. net"), que es exactamente el caso real que seguia fallando en produccion tras el fix anterior. Un dominio o correo nunca lleva espacios: ahora se remueven todos. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,11 @@ import { HttpError } from '../../utils/http.js';
|
||||
|
||||
const SMTP_KEYS = ['smtp_host', 'smtp_port', 'smtp_user', 'smtp_from', 'smtp_pass_enc'];
|
||||
|
||||
// Host/usuario/remitente/destino son identificadores tecnicos (dominio o correo): nunca llevan
|
||||
// espacios, ni al borde ni en medio. trim() no alcanza para un espacio colado a mitad de un
|
||||
// dominio (ej. "mail.linkedcorp. net" tecleado por error) — se quita CUALQUIER espacio.
|
||||
const stripSpaces = (s) => (s || '').replace(/\s+/g, '');
|
||||
|
||||
export async function getSmtpConfig() {
|
||||
const values = await repo.getAll(SMTP_KEYS);
|
||||
return {
|
||||
@@ -31,9 +36,9 @@ export async function getSmtpConfigInternal() {
|
||||
}
|
||||
|
||||
export async function updateSmtpConfig(payload, actorId) {
|
||||
const host = (payload.host || '').trim();
|
||||
const user = (payload.user || '').trim();
|
||||
const from = (payload.from || '').trim();
|
||||
const host = stripSpaces(payload.host);
|
||||
const user = stripSpaces(payload.user);
|
||||
const from = stripSpaces(payload.from);
|
||||
if (!host || !user) throw new HttpError(400, 'Host y usuario son obligatorios');
|
||||
const entries = {
|
||||
smtp_host: host,
|
||||
@@ -53,10 +58,10 @@ export async function updateSmtpConfig(payload, actorId) {
|
||||
// (credenciales invalidas, host inalcanzable, certificado vencido, etc.) — es una accion de
|
||||
// diagnostico explicita del superadmin, no un envio "de negocio".
|
||||
export async function testSmtpConfig(payload, actorId) {
|
||||
const to = (payload.to || '').trim();
|
||||
const host = (payload.host || '').trim();
|
||||
const user = (payload.user || '').trim();
|
||||
const from = (payload.from || '').trim();
|
||||
const to = stripSpaces(payload.to);
|
||||
const host = stripSpaces(payload.host);
|
||||
const user = stripSpaces(payload.user);
|
||||
const from = stripSpaces(payload.from);
|
||||
if (!to) throw new HttpError(400, 'Indica un correo destino para la prueba');
|
||||
if (!host || !user) throw new HttpError(400, 'Host y usuario son obligatorios para probar');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user