diff --git a/server.go b/server.go index 9225f10..3ca8707 100644 --- a/server.go +++ b/server.go @@ -120,27 +120,7 @@ func view(w http.ResponseWriter, r *http.Request) { //登陆界面 func login(w http.ResponseWriter, r *http.Request) { - email := r.PostFormValue("email") - server := r.PostFormValue("server") - password := r.PostFormValue("password") - var errStr string - if email != "" && server != "" && password != "" { - res := tools.CheckEmailPassword(server, email, password) - if !res { - errStr = "连接或验证失败" - tmpl.RenderLogin(w, errStr) - } else { - auth := fmt.Sprintf("%s|%s|%s", server, email, password) - cookie := http.Cookie{ - Name: "auth", - Value: auth, - } - http.SetCookie(w, &cookie) - http.Redirect(w, r, "/", 302) - } - } else { - tmpl.RenderLogin(w, errStr) - } + tmpl.RenderLogin(w, nil) } //验证接口 @@ -168,15 +148,9 @@ func check(w http.ResponseWriter, r *http.Request) { //邮件夹接口 func folders(w http.ResponseWriter, r *http.Request) { - values := r.URL.Query() - fid := "" - currentPage := 0 - if len(values["fid"]) != 0 { - fid = values["fid"][0] - } - if len(values["page"]) != 0 { - currentPage, _ = strconv.Atoi(values["page"][0]) - } + fid:=tools.GetUrlArg(r,"fid") + currentPage, _ :=strconv.Atoi(tools.GetUrlArg(r,"page")) + if fid == "" { fid = "INBOX" } @@ -219,20 +193,8 @@ func folders(w http.ResponseWriter, r *http.Request) { //邮件接口 func mail(w http.ResponseWriter, r *http.Request) { - values := r.URL.Query() - fid := "" - if len(values["fid"]) != 0 { - fid = values["fid"][0] - } else { - fid = "INBOX" - } - var id uint32 - if len(values["id"]) != 0 { - i, _ := strconv.Atoi(values["id"][0]) - id = uint32(i) - } else { - id = 0 - } + fid:=tools.GetUrlArg(r,"fid") + id, _ :=strconv.Atoi(tools.GetUrlArg(r,"id")) mailServer := tools.GetMailServerFromCookie(r) w.Header().Set("content-type", "text/json;charset=utf-8;") @@ -252,7 +214,7 @@ func mail(w http.ResponseWriter, r *http.Request) { }() go func() { defer wg.Done() - mail := tools.GetMessage(mailServer.Server, mailServer.Email, mailServer.Password, fid, id) + mail := tools.GetMessage(mailServer.Server, mailServer.Email, mailServer.Password, fid, uint32(id)) result["from"] = mail.From result["to"] = mail.To result["subject"] = mail.Subject diff --git a/static/html/list.html b/static/html/list.html index 113f63f..5c19c59 100644 --- a/static/html/list.html +++ b/static/html/list.html @@ -65,7 +65,7 @@ - + <{v}> @@ -75,7 +75,7 @@
- +

<{item.Subject}>

<{item.From}> 发送于 <{item.Date}>

@@ -104,28 +104,36 @@ delimiters:["<{","}>"], data: { fullscreenLoading:true, - folderlist:[], + folders:[], + mails:[], mailTotal:0, page:1, pagesize:10, - fid:"INBOX", + fid:"", }, methods: { //获取邮件夹 - getFolders: function (page,fid) { + getFolders: function (page,fid,isLeft) { this.fullscreenLoading=true; - if(page==""){ + if(typeof(page)=="undefined" || page==""){ page=1; + }else{ + this.page=page; } - var data={}; + let data={}; data.page=page; - if(fid!=""){ + if(typeof(fid)!="undefined" && fid!=""){ data.fid=fid; this.fid=fid; + }else if(this.fid!=""){ + data.fid=this.fid; } let _this = this; $.get('/folders',data, function (rs) { - _this.folderlist=rs.result; + if(!isLeft){ + _this.folders=rs.result.folders; + } + _this.mails=rs.result.mails _this.mailTotal=rs.result.total; _this.pagesize=rs.result.pagesize; _this.fid=rs.result.fid; diff --git a/tools/stringutil.go b/tools/stringutil.go index 4d4f2b3..3fe9771 100644 --- a/tools/stringutil.go +++ b/tools/stringutil.go @@ -8,9 +8,16 @@ import ( "golang.org/x/text/encoding/unicode" "golang.org/x/text/transform" "io/ioutil" + "net/http" "strings" ) - +//获取URL的GET参数 +func GetUrlArg(r *http.Request,name string)string{ + var arg string + values := r.URL.Query() + arg=values.Get(name) + return arg +} // Reverse 将其实参字符串以符文为单位左右反转。 func Reverse(s string) string { r := []rune(s) @@ -38,6 +45,7 @@ func DetermineEncoding(html string) (encoding.Encoding, string) { e, name, _ := charset.DetermineEncoding([]byte(html), "") return e, name } +//获取文件内容,可以打包到二进制 func FileGetContent(file string) string { str := "" box := packr.NewBox("../static")