fix tests and remove filter.go

master
Carlo Strub 7 years ago
parent b887d7dd46
commit ca521d51d6

@ -1,17 +0,0 @@
package main
import (
"github.com/jbrukh/bayesian"
)
const (
// good is the class of good mails that are not supposed to be Spam
good bayesian.Class = "Good"
// junk is the class of Spam mails
junk bayesian.Class = "Junk"
)
// Classifiers contains the classifiers for mail subjects and bodies
type Classifiers struct {
Subject, Body *bayesian.Classifier
}

@ -22,10 +22,11 @@ type Mail struct {
// Index loads all mail keys from the Maildir directory for processing.
func Index(d string, junk bool) (m []*Mail, err error) {
var j []string
if junk {
j, err := maildir.Dir(d + "/.Junk").Keys()
j, err = maildir.Dir(d + "/.Junk").Keys()
} else {
j, err := maildir.Dir(d).Keys()
j, err = maildir.Dir(d).Keys()
}
if err != nil {
return m, err

@ -40,7 +40,7 @@ var _ = Describe("Mail", func() {
Context("Maildir", func() {
It("Create a slice of mail keys", func() {
result, err := s.Index("test/Maildir")
result, err := s.Index("test/Maildir", true)
Ω(err).ShouldNot(HaveOccurred())
name := func(m1, m2 *s.Mail) bool {
@ -86,6 +86,19 @@ var _ = Describe("Mail", func() {
Body: nil,
Junk: true,
},
}))
})
It("Create a slice of mail keys", func() {
result, err := s.Index("test/Maildir", false)
Ω(err).ShouldNot(HaveOccurred())
name := func(m1, m2 *s.Mail) bool {
return m1.Key < m2.Key
}
mailBy(name).Sort(result)
Ω(result).Should(Equal(
[]*s.Mail{
{
Key: "1488230510.M141612P8565.mail.carlostrub.ch,S=5978,W=6119",
Subject: nil,
@ -95,7 +108,7 @@ var _ = Describe("Mail", func() {
}))
})
It("Fail if Maildir does not exist", func() {
_, err := s.Index("test/DOESNOTEXIST")
_, err := s.Index("test/DOESNOTEXIST", false)
Ω(err).Should(HaveOccurred())
})
})

@ -140,12 +140,12 @@ func main() {
for i := range mailsGood {
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Processed"))
v := b.Get([]byte(mails[i].Key))
v := b.Get([]byte(mailsGood[i].Key))
if len(v) == 0 {
unprocessedGood = append(unprocessedGood, mails[i].Key)
unprocessedGood = append(unprocessedGood, mailsGood[i].Key)
}
if string(v) == junk {
unprocessedGood = append(unprocessedGood, mails[i].Key)
unprocessedGood = append(unprocessedGood, mailsGood[i].Key)
}
return nil
})
@ -153,12 +153,12 @@ func main() {
for i := range mailsJunk {
db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("Processed"))
v := b.Get([]byte(mails[i].Key))
v := b.Get([]byte(mailsJunk[i].Key))
if len(v) == 0 {
unprocessedJunk = append(unprocessedJunk, mails[i].Key)
unprocessedJunk = append(unprocessedJunk, mailsJunk[i].Key)
}
if string(v) == good {
unprocessedJunk = append(unprocessedJunk, mails[i].Key)
unprocessedJunk = append(unprocessedJunk, mailsJunk[i].Key)
}
return nil
})

Loading…
Cancel
Save