Files
mailgoserver/internal/mailstore/quota.go
T

20 lines
634 B
Go

package mailstore
import "fmt"
// QuotaStatus reports a mailbox's storage usage — feeds the "≥90% full" badge on the
// mailboxes list and the dashboard tile in a later milestone.
func (s *Store) QuotaStatus(mailboxID int64) (used, quota int64, pctFull float64, err error) {
mbox, err := s.DB.GetMailboxByID(mailboxID)
if err != nil {
return 0, 0, 0, err
}
if mbox == nil {
return 0, 0, 0, fmt.Errorf("mailstore: mailbox %d not found", mailboxID)
}
if mbox.QuotaBytes == 0 {
return mbox.UsedBytes, 0, 0, nil
}
return mbox.UsedBytes, mbox.QuotaBytes, float64(mbox.UsedBytes) / float64(mbox.QuotaBytes) * 100, nil
}