add kerio format support

This commit is contained in:
2026-07-17 11:42:34 +07:00
parent 5d296c39b1
commit b352cda166
8 changed files with 393 additions and 2 deletions
+12 -1
View File
@@ -14,6 +14,17 @@ import (
"github.com/vasyansk/imap-copier/internal/store"
)
// parseImportRows picks the CSV dialect from the "format" form field. A Kerio
// Connect export holds one login/password pair and no domain, so the operator
// supplies the domain alongside the file; anything else is the plain 4-column
// src/dst format.
func parseImportRows(r *http.Request, file io.Reader) ([]csvimport.Row, error) {
if r.FormValue("format") == "kerio" {
return csvimport.ParseKerio(file, r.FormValue("domain"))
}
return csvimport.Parse(file)
}
func (s *Server) handleImportCSV(w http.ResponseWriter, r *http.Request) {
taskID, err := pathID(r, "id")
if err != nil {
@@ -26,7 +37,7 @@ func (s *Server) handleImportCSV(w http.ResponseWriter, r *http.Request) {
return
}
defer file.Close()
rows, err := csvimport.Parse(file)
rows, err := parseImportRows(r, file)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return