Skip to content

Instantly share code, notes, and snippets.

@avleen
Created July 21, 2019 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avleen/a6d9398fdff724eedfd60bffb140dff3 to your computer and use it in GitHub Desktop.
Save avleen/a6d9398fdff724eedfd60bffb140dff3 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"github.com/saintienn/go-spamc"
"io/ioutil"
"log"
"os"
)
func checkit(files chan string, done chan bool) {
mail_new := "/mail/Maildir/new/"
mail_spam := "/mail//Maildir/.SPAM/new/"
client := spamc.New("xxx.xxx.xxx.xxx:783", 10)
for {
j, more := <-files
if more {
mail_file := mail_new + j
if _, err := os.Stat(mail_file); os.IsNotExist(err) {
fmt.Println("No such file: %s", mail_file)
continue
}
dat, err := ioutil.ReadFile(mail_file)
if err != nil {
log.Fatal(err)
}
reply, checkerr := client.Check(string(dat))
if checkerr != nil {
fmt.Println(reply.Code)
fmt.Println(reply.Message)
fmt.Println(reply.Vars)
fmt.Println(checkerr)
continue
}
if reply.Vars["isSpam"] == true {
fmt.Println("Definitely spam")
err := os.Rename(mail_file, mail_spam+j)
if err != nil {
log.Print(err)
}
}
} else {
done <- true
}
}
}
func main() {
files := make(chan string, 250)
done := make(chan bool, 250)
for w := 1; w <= 100; w++ {
go checkit(files, done)
}
file, err := os.Open("/root/maillist.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
count := 0
scanner := bufio.NewScanner(file)
for scanner.Scan() {
files <- scanner.Text()
count++
fmt.Println("Counter: ", count)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment