1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-12-07 23:23:27 +02:00

Feature: Unread statistics

This commit is contained in:
Ralph Slooten
2022-07-30 19:58:31 +12:00
parent 335b0f3876
commit a85a74bb9a
6 changed files with 156 additions and 48 deletions

View File

@@ -12,10 +12,11 @@ import (
)
type messagesResult struct {
Total int `json:"total"`
Count int `json:"count"`
Start int `json:"start"`
Items []data.Summary `json:"items"`
Total int `json:"total"`
Unread int `json:"unread"`
Count int `json:"count"`
Start int `json:"start"`
Items []data.Summary `json:"items"`
}
// Return a list of available mailboxes
@@ -49,18 +50,15 @@ func apiListMailbox(w http.ResponseWriter, r *http.Request) {
return
}
total, err := storage.Count(mailbox)
if err != nil {
httpError(w, err.Error())
return
}
stats := storage.StatsGet(mailbox)
var res messagesResult
res.Start = start
res.Items = messages
res.Count = len(res.Items)
res.Total = total
res.Total = stats.Total
res.Unread = stats.Unread
bytes, _ := json.Marshal(res)
w.Header().Add("Content-Type", "application/json")
@@ -92,24 +90,15 @@ func apiSearchMailbox(w http.ResponseWriter, r *http.Request) {
return
}
total, err := storage.Count(mailbox)
if err != nil {
httpError(w, err.Error())
return
}
// total := limit
// count := len(messages)
// if total > count {
// total = count
// }
stats := storage.StatsGet(mailbox)
var res messagesResult
res.Start = start
res.Items = messages
res.Count = len(messages)
res.Total = total
res.Total = stats.Total
res.Unread = stats.Unread
bytes, _ := json.Marshal(res)
w.Header().Add("Content-Type", "application/json")