获取邮件夹封数

pull/30/head
unknown 5 years ago
parent 830fffa353
commit c162829b95

@ -11,23 +11,35 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<style> <style>
body{
padding: 10px;
}
</style> </style>
</head> </head>
<body> <body>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-3">
<ul class="list-group"> <ul class="list-group">
<li class="list-group-item active">邮件夹</li>
{{ range $key, $value := .}} {{ range $key, $value := .}}
<li class="list-group-item d-flex justify-content-between align-items-center"> <li class="list-group-item d-flex justify-content-between align-items-center">
{{$value}} {{$key}}
<span class="badge badge-primary badge-pill">14</span> <span class="badge badge-primary badge-pill">{{$value}}</span>
</li> </li>
{{end}}} {{end}}
</ul>
</div>
<div class="col-md-9">
<ul class="list-group">
<li class="list-group-item active">邮件列表</li>
{{ range $key, $value := .}}
<li class="list-group-item d-flex justify-content-between align-items-center">
{{$key}}
</li>
{{end}}
</ul> </ul>
</div> </div>
<div class="col-md-8">.col-md-8</div>
</div> </div>
</body> </body>
</html> </html>

@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client" "github.com/emersion/go-imap/client"
"log"
"strconv" "strconv"
"strings" "strings"
"sync"
) )
//验证邮箱密码 //验证邮箱密码
func CheckEmailPassword(server string, email string, password string) bool { 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 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 var c *client.Client
//defer c.Logout() //defer c.Logout()
c=connect(server,email,password) c=connect(server,email,password)
@ -69,9 +71,23 @@ func GetFolders(server string, email string, password string)[]string{
done <- c.List("", "*", mailboxes) done <- c.List("", "*", mailboxes)
}() }()
// 存储邮件夹 // 存储邮件夹
var folders []string var folders =make(map[string]int)
for m := range mailboxes { 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 return folders
} }
Loading…
Cancel
Save