fix(httpapi): trim whitespace on manually-added account login/password

Pasted app passwords (e.g. mail.ru) often carry a trailing space/newline that
the IMAP server rejects; the CSV path already trims, so make manual add match.
Source and destination passwords remain fully independent (src_pass_enc /
dst_pass_enc), verified end-to-end — this only strips surrounding whitespace.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
2026-07-02 10:38:00 +07:00
parent b8d1505329
commit 79bd55aad8
+7
View File
@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"github.com/vasyansk/imap-copier/internal/crypto" "github.com/vasyansk/imap-copier/internal/crypto"
"github.com/vasyansk/imap-copier/internal/store" "github.com/vasyansk/imap-copier/internal/store"
@@ -49,6 +50,12 @@ func (s *Server) handleCreateAccount(w http.ResponseWriter, r *http.Request) {
http.Error(w, "bad json", http.StatusBadRequest) http.Error(w, "bad json", http.StatusBadRequest)
return return
} }
// Trim surrounding whitespace — pasted app passwords / logins often carry a
// stray trailing space or newline that the IMAP server rejects.
body.SrcLogin = strings.TrimSpace(body.SrcLogin)
body.SrcPass = strings.TrimSpace(body.SrcPass)
body.DstLogin = strings.TrimSpace(body.DstLogin)
body.DstPass = strings.TrimSpace(body.DstPass)
srcEnc, err := crypto.Encrypt(s.cfg.EncKey, []byte(body.SrcPass)) srcEnc, err := crypto.Encrypt(s.cfg.EncKey, []byte(body.SrcPass))
if err != nil { if err != nil {
http.Error(w, "encrypt", http.StatusInternalServerError) http.Error(w, "encrypt", http.StatusInternalServerError)