获取邮件夹封数

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">
<style>
body{
padding: 10px;
}
</style>
</head>
<body>
<div class="row">
<div class="col-md-4">
<div class="col-md-3">
<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">
{{$value}}
<span class="badge badge-primary badge-pill">14</span>
{{$key}}
<span class="badge badge-primary badge-pill">{{$value}}</span>
</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>
</div>
<div class="col-md-8">.col-md-8</div>
</div>
</body>
</html>

@ -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
}
Loading…
Cancel
Save