pull/30/head
taoshihan1991 4 years ago
parent 1f026583c7
commit d4ed409963

@ -14,6 +14,7 @@ var(
const Dir = "config/"
const AccountConf = Dir + "account.json"
const MysqlConf = Dir + "mysql.json"
const MailConf = Dir + "mail.json"
type Mysql struct{
Server string
Port string
@ -21,6 +22,9 @@ type Mysql struct{
Username string
Password string
}
type MailServer struct {
Server, Email, Password string
}
type Config struct {
Mysql *Mysql
}
@ -31,6 +35,20 @@ func CreateConfig()*Config{
}
return c
}
func CreateMailServer() *MailServer {
var imap MailServer
isExist, _ := tools.IsFileExist(MailConf)
if !isExist {
return &imap
}
info, err := ioutil.ReadFile(MailConf)
if err != nil {
return &imap
}
err = json.Unmarshal(info, &imap)
return &imap
}
func CreateMysql() *Mysql {
var mysql Mysql
isExist, _ := tools.IsFileExist(MysqlConf)

@ -2,6 +2,8 @@ package controller
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/tmpl"
"github.com/taoshihan1991/imaptool/tools"
"io/ioutil"
@ -11,7 +13,62 @@ import (
)
const PageSize = 20
func GetFolders(c *gin.Context) {
fid := c.Query("fid")
currentPage, _ := strconv.Atoi(c.Query("page"))
if fid == "" {
fid = "INBOX"
}
if currentPage == 0 {
currentPage = 1
}
mailServer := config.CreateMailServer()
var wg sync.WaitGroup
wg.Add(2)
result := make(map[string]interface{})
go func() {
defer wg.Done()
folders := tools.GetFolders(mailServer.Server, mailServer.Email, mailServer.Password, fid)
result["folders"] = folders
result["total"] = folders[fid]
}()
go func() {
defer wg.Done()
mails := tools.GetFolderMail(mailServer.Server, mailServer.Email, mailServer.Password, fid, currentPage, PageSize)
result["mails"] = mails
}()
wg.Wait()
result["pagesize"] = PageSize
result["fid"] = fid
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":result,
})
}
func GetFolderList(c *gin.Context) {
fid := c.Query("fid")
if fid == "" {
fid = "INBOX"
}
mailServer := config.CreateMailServer()
result := make(map[string]interface{})
folders := tools.GetFolders(mailServer.Server, mailServer.Email, mailServer.Password, fid)
result["folders"] = folders
result["total"] = folders[fid]
result["fid"] = fid
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":result,
})
}
//输出列表
func ActionFolder(w http.ResponseWriter, r *http.Request) {
fid := tools.GetUrlArg(r, "fid")

@ -58,6 +58,10 @@ func main() {
engine.GET("/setting_mysql", tmpl.PageSettingMysql)
//网页部署
engine.GET("/setting_deploy", tmpl.PageSettingDeploy)
//邮箱列表
engine.GET("/mail_list", tmpl.PageMailList)
//邮件夹列表
engine.GET("/folders", controller.GetFolders)
engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlGetConf)
engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlSetConf)

@ -1,4 +1,4 @@
{{.Header}}
{{template "header" }}
<div id="app" style="width:100%">
<template>
<el-container v-loading.fullscreen.lock="fullscreenLoading">
@ -92,7 +92,7 @@
},
},
created: function () {
this.getFolders({{.CurrentPage}},{{.Fid}});
this.getFolders(1,"INBOX");
}
})

@ -0,0 +1,11 @@
package tmpl
import (
"github.com/gin-gonic/gin"
"net/http"
)
//邮箱列表界面
func PageMailList(c *gin.Context) {
c.HTML(http.StatusOK, "list.html", gin.H{})
}
Loading…
Cancel
Save