From 79bd55aad873556acdb43208b377f6c9ecf1e9a1 Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Thu, 2 Jul 2026 10:38:00 +0700 Subject: [PATCH] fix(httpapi): trim whitespace on manually-added account login/password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd --- internal/httpapi/accounts.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/httpapi/accounts.go b/internal/httpapi/accounts.go index 09b0788..e5d6a02 100644 --- a/internal/httpapi/accounts.go +++ b/internal/httpapi/accounts.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "strconv" + "strings" "github.com/vasyansk/imap-copier/internal/crypto" "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) 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)) if err != nil { http.Error(w, "encrypt", http.StatusInternalServerError)