From fe6cdaddcee5905551136b1fa688995189928503 Mon Sep 17 00:00:00 2001 From: Emin Date: Thu, 28 Sep 2023 14:54:38 +0300 Subject: [PATCH] Mail syncing working, TODO fix bugs on frontend --- .gitignore | 2 +- internal/router.go | 1 - internal/sync.go | 12 +++--- internal/validate.go | 28 ++++++++++--- templates/index.html | 97 +++++++++++++++++++++----------------------- 5 files changed, 77 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 35400df..27a1834 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ tmp - imap-sync +LOG_imapsync diff --git a/internal/router.go b/internal/router.go index af91ecf..34e8e77 100644 --- a/internal/router.go +++ b/internal/router.go @@ -25,7 +25,6 @@ func InitServer() { router.GET("/api/pagination", handlePagination) router.POST("/api/validate", handleValidate) router.POST("/api/search", handleSearch) - router.POST("/api/sync", handleSync) log.Info("Server starting on http://localhost:" + *port) diff --git a/internal/sync.go b/internal/sync.go index b98a153..be7cfdb 100644 --- a/internal/sync.go +++ b/internal/sync.go @@ -10,12 +10,12 @@ import ( ) func handleSync(ctx *gin.Context) { - sourceServer := ctx.PostForm("sourceServer") - sourceAccount := ctx.PostForm("sourceAccount") - sourcePassword := ctx.PostForm("sourcePassword") - destinationServer := ctx.PostForm("destinationServer") - destinationAccount := ctx.PostForm("destinationAccount") - destinationPassword := ctx.PostForm("destinationPassword") + sourceServer := ctx.PostForm("source_server") + sourceAccount := ctx.PostForm("source_account") + sourcePassword := ctx.PostForm("source_password") + destinationServer := ctx.PostForm("destination_server") + destinationAccount := ctx.PostForm("destination_account") + destinationPassword := ctx.PostForm("destination_password") sourceDetails := Credentials{ Server: sourceServer, diff --git a/internal/validate.go b/internal/validate.go index 7d734ce..46c2a1a 100644 --- a/internal/validate.go +++ b/internal/validate.go @@ -8,9 +8,29 @@ import ( ) func handleValidate(ctx *gin.Context) { - Server := ctx.PostForm("server") - Account := ctx.PostForm("account") - Password := ctx.PostForm("password") + + sourceCreds := ctx.PostForm("source_creds") + destCreds := ctx.PostForm("destination_creds") + submitsync := ctx.PostForm("submit_sync") + + var Server, Account, Password string + + if sourceCreds != "" { + Server = ctx.PostForm("source_server") + Account = ctx.PostForm("source_account") + Password = ctx.PostForm("source_password") + } + + if destCreds != "" { + Server = ctx.PostForm("destination_server") + Account = ctx.PostForm("destination_account") + Password = ctx.PostForm("destination_password") + } + + if destCreds == "" && sourceCreds == "" && submitsync != "" { + handleSync(ctx) + return + } creds := Credentials{ Server: Server, @@ -45,10 +65,8 @@ func validateCredentials(creds Credentials) error { } log.Infof("IMAP Connected") - // Don't forget to logout defer c.Logout() - // Login if err := c.Login(creds.Account, creds.Password); err != nil { log.Error(err) return err diff --git a/templates/index.html b/templates/index.html index 0e7df40..735d4bf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -54,73 +54,70 @@ -
- - - +

Source Details

- -
-
- - -
-
- - -
-
- - -
- +
+
+ + +
+
+ +
- +
+ + +
+ + +

Destination Details

-
-
-
- - -
-
- - -
-
- - -
- +
+
+ +
- +
+ + +
+
+ + +
+ + +
-
+

Log Output

- +