Skip to content

Commit 4078ba1

Browse files
committed
fix
1 parent 30d3aa0 commit 4078ba1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

emails/server.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"io"
66
"strconv"
7+
"sync"
78
"time"
89

910
"github.com/emersion/go-sasl"
@@ -20,23 +21,28 @@ type Backend struct {
2021
username string
2122
password string
2223
Emails chan Email
24+
Mutex sync.Mutex
2325
}
2426

2527
func (bkd *Backend) NewSession(c *smtp.Conn) (smtp.Session, error) {
26-
return &Session{bkd: bkd}, nil
28+
return &Session{bkd: bkd}, nil
2729
}
2830

2931
func (bkd *Backend) ClearQueue() {
32+
bkd.Mutex.Lock()
3033
for len(bkd.Emails) != 0 {
3134
<-bkd.Emails
3235
}
36+
bkd.Mutex.Unlock()
3337
}
3438

3539
func (bkd *Backend) AddEmail(email Email) {
40+
bkd.Mutex.Lock()
3641
if len(bkd.Emails) == cap(bkd.Emails) {
3742
<-bkd.Emails
3843
}
3944
bkd.Emails <- email
45+
bkd.Mutex.Unlock()
4046
}
4147

4248
type Session struct {

0 commit comments

Comments
 (0)