Skip to content

Commit

Permalink
fix: trim config before use (#1756)
Browse files Browse the repository at this point in the history
* feat: ensure hosts are trimmed before saving

* feat: trim host before saving bounces
  • Loading branch information
scmmishra authored Feb 26, 2024
1 parent 12ab492 commit d7b55cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func handleUpdateSettings(c echo.Context) error {
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
// password by matching the UUID.
if s.Password == "" {
Expand All @@ -134,6 +138,10 @@ func handleUpdateSettings(c echo.Context) error {
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 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("settings.bounces.invalidScanInterval"))
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export default Vue.extend({
// SMTP boxes.
let hasDummy = '';
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 (this.isDummy(form.smtp[i].password)) {
form.smtp[i].password = '';
Expand All @@ -128,6 +131,9 @@ export default Vue.extend({
// Bounces boxes.
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 (this.isDummy(form['bounce.mailboxes'][i].password)) {
form['bounce.mailboxes'][i].password = '';
Expand Down

0 comments on commit d7b55cd

Please sign in to comment.