Implement queue methods
This commit is contained in:
parent
7b1fa6c833
commit
fac4985ab7
|
@ -24,6 +24,33 @@ type QEntry struct {
|
||||||
Reason string
|
Reason string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewQueue() MailQ {
|
||||||
|
return MailQ{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q MailQ) AddEntry(entry QEntry) {
|
||||||
|
q.NumTotal += 1
|
||||||
|
if entry.Status == "active" {
|
||||||
|
q.NumActive += 1
|
||||||
|
} else if entry.Status == "deferred" {
|
||||||
|
q.NumDeferred += 1
|
||||||
|
} else if entry.Status == "hold" {
|
||||||
|
q.NumHold += 1
|
||||||
|
}
|
||||||
|
q.Entries = append(q.Entries, entry)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q MailQ) RemoveEntry(entry QEntry) {
|
||||||
|
var currentIndex int
|
||||||
|
var currentEntry QEntry
|
||||||
|
for currentIndex, currentEntry = range q.Entries {
|
||||||
|
if currentEntry.Id == entry.Id {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
q.Entries = append(q.Entries[:currentIndex], q.Entries[currentIndex+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
func (q MailQ) GetMessageById(id string) (QEntry, error) {
|
func (q MailQ) GetMessageById(id string) (QEntry, error) {
|
||||||
for _, entry := range q.Entries {
|
for _, entry := range q.Entries {
|
||||||
if entry.Id == id {
|
if entry.Id == id {
|
||||||
|
|
Loading…
Reference in New Issue