From c162829b951b3c112cea85baed9b3382af814105 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Apr 2020 20:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=82=AE=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=B0=81=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmpl/index.html | 24 ++++++++++++++++++------ tools/imap.go | 22 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tmpl/index.html b/tmpl/index.html index dffbda4..3fb2396 100644 --- a/tmpl/index.html +++ b/tmpl/index.html @@ -11,23 +11,35 @@
-
+
    +
  • 邮件夹
  • {{ range $key, $value := .}}
  • - {{$value}} - 14 + {{$key}} + {{$value}}
  • - {{end}}} + {{end}} +
+
+
+
    +
  • 邮件列表
  • + {{ range $key, $value := .}} +
  • + {{$key}} +
  • + {{end}}
-
.col-md-8
diff --git a/tools/imap.go b/tools/imap.go index bd075c6..10abb59 100644 --- a/tools/imap.go +++ b/tools/imap.go @@ -4,8 +4,10 @@ import ( "fmt" "github.com/emersion/go-imap" "github.com/emersion/go-imap/client" + "log" "strconv" "strings" + "sync" ) //验证邮箱密码 func CheckEmailPassword(server string, email string, password string) bool { @@ -55,7 +57,7 @@ func connect(server string, email string, password string)*client.Client{ return c } //获取邮件夹 -func GetFolders(server string, email string, password string)[]string{ +func GetFolders(server string, email string, password string)map[string]int{ var c *client.Client //defer c.Logout() c=connect(server,email,password) @@ -69,9 +71,23 @@ func GetFolders(server string, email string, password string)[]string{ done <- c.List("", "*", mailboxes) }() // 存储邮件夹 - var folders []string + var folders =make(map[string]int) for m := range mailboxes { - folders=append(folders,m.Name) + folders[m.Name]=1 } + var wg sync.WaitGroup + var k string + for k,_=range folders{ + //wg.Add(1) + //go func(k string) { + mbox, _ := c.Select(k, false) + if mbox!=nil{ + log.Println(k,mbox.Messages) + folders[k]=int(mbox.Messages) + } + //wg.Done() + //}(k) + } + wg.Wait() return folders } \ No newline at end of file