fix: trim config before use (#1756)

* feat: ensure hosts are trimmed before saving

* feat: trim host before saving bounces
This commit is contained in:
Shivam Mishra 2024-02-26 15:12:50 +05:30 committed by GitHub
parent 12ab492701
commit d7b55cd147
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View file

@ -108,6 +108,10 @@ func handleUpdateSettings(c echo.Context) error {
set.SMTP[i].UUID = uuid.Must(uuid.NewV4()).String() set.SMTP[i].UUID = uuid.Must(uuid.NewV4()).String()
} }
// Ensure the HOST is trimmed of any whitespace.
// This is a common mistake when copy-pasting SMTP settings.
set.SMTP[i].Host = strings.TrimSpace(s.Host)
// If there's no password coming in from the frontend, copy the existing // If there's no password coming in from the frontend, copy the existing
// password by matching the UUID. // password by matching the UUID.
if s.Password == "" { if s.Password == "" {
@ -134,6 +138,10 @@ func handleUpdateSettings(c echo.Context) error {
set.BounceBoxes[i].UUID = uuid.Must(uuid.NewV4()).String() set.BounceBoxes[i].UUID = uuid.Must(uuid.NewV4()).String()
} }
// Ensure the HOST is trimmed of any whitespace.
// This is a common mistake when copy-pasting SMTP settings.
set.BounceBoxes[i].Host = strings.TrimSpace(s.Host)
if d, _ := time.ParseDuration(s.ScanInterval); d.Minutes() < 1 { if d, _ := time.ParseDuration(s.ScanInterval); d.Minutes() < 1 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("settings.bounces.invalidScanInterval")) return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("settings.bounces.invalidScanInterval"))
} }

View file

@ -112,6 +112,9 @@ export default Vue.extend({
// SMTP boxes. // SMTP boxes.
let hasDummy = ''; let hasDummy = '';
for (let i = 0; i < form.smtp.length; i += 1) { for (let i = 0; i < form.smtp.length; i += 1) {
// trim the host before saving
form.smtp[i].host = form.smtp[i].host?.trim();
// If it's the dummy UI password placeholder, ignore it. // If it's the dummy UI password placeholder, ignore it.
if (this.isDummy(form.smtp[i].password)) { if (this.isDummy(form.smtp[i].password)) {
form.smtp[i].password = ''; form.smtp[i].password = '';
@ -128,6 +131,9 @@ export default Vue.extend({
// Bounces boxes. // Bounces boxes.
for (let i = 0; i < form['bounce.mailboxes'].length; i += 1) { for (let i = 0; i < form['bounce.mailboxes'].length; i += 1) {
// trim the host before saving
form['bounce.mailboxes'][i].host = form['bounce.mailboxes'][i].host?.trim();
// If it's the dummy UI password placeholder, ignore it. // If it's the dummy UI password placeholder, ignore it.
if (this.isDummy(form['bounce.mailboxes'][i].password)) { if (this.isDummy(form['bounce.mailboxes'][i].password)) {
form['bounce.mailboxes'][i].password = ''; form['bounce.mailboxes'][i].password = '';