Archived
1
0

fix sa hook

This commit is contained in:
Jeff Becker 2017-11-07 14:57:05 -05:00
parent d3ca9dfa33
commit a88334e985
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 10 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import (
var ErrSpamFilterNotEnabled = errors.New("spam filter access attempted when disabled") var ErrSpamFilterNotEnabled = errors.New("spam filter access attempted when disabled")
var ErrSpamFilterFailed = errors.New("spam filter failed") var ErrSpamFilterFailed = errors.New("spam filter failed")
var ErrMessageIsSpam = errors.New("message is spam")
type SpamFilter struct { type SpamFilter struct {
addr string addr string
@ -55,6 +56,9 @@ func (sp *SpamFilter) Rewrite(msg io.Reader, out io.WriteCloser) error {
return err return err
} }
l = strings.TrimSpace(l) l = strings.TrimSpace(l)
if strings.HasPrefix(l, "Spam: True ") {
return ErrMessageIsSpam
}
log.Println("SpamFilter:", l) log.Println("SpamFilter:", l)
if l == "" { if l == "" {
_, err = io.CopyBuffer(out, r, buff[:]) _, err = io.CopyBuffer(out, r, buff[:])

View File

@ -465,11 +465,9 @@ func (self *articleStore) ProcessMessage(wr io.Writer, msg io.Reader, spamfilter
if self.spamd.Enabled() { if self.spamd.Enabled() {
pr_in, pw_in := io.Pipe() pr_in, pw_in := io.Pipe()
pr_out, pw_out := io.Pipe() pr_out, pw_out := io.Pipe()
ec := make(chan error)
go func() { go func() {
e := self.spamd.Rewrite(pr_in, pw_out) ec <- self.spamd.Rewrite(pr_in, pw_out)
if e != nil {
log.Println("failed to check spam", e)
}
}() }()
go func() { go func() {
var buff [65536]byte var buff [65536]byte
@ -491,6 +489,10 @@ func (self *articleStore) ProcessMessage(wr io.Writer, msg io.Reader, spamfilter
} }
writeMIMEHeader(wr, m.Header) writeMIMEHeader(wr, m.Header)
read_message_body(m.Body, m.Header, self, wr, false, process) read_message_body(m.Body, m.Header, self, wr, false, process)
er := <-ec
if er != nil {
return er
}
} else { } else {
r := bufio.NewReader(msg) r := bufio.NewReader(msg)
m, e := readMIMEHeader(r) m, e := readMIMEHeader(r)