add kerio format support
This commit is contained in:
+12
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user