func (cif *ContentInspectionFilter) Filter(mail mailfile.Mail) Result {
	log.Printf("Run %s, Mail:%s\n", cif, mail.Name())
	cif.total.Inc(1)

	post, err := mailpost.Parse(mail)
	mail.Close()
	if err != nil {
		cif.malformed.Inc(1)
		log.Printf("ContentInspectionFilter: Err:%v, Mail:%s\n", err, mail.Path())
		return cif.next.Filter(mail)
	}

	class := cif.anlz.Test(post.Subject + " " + post.Content)
	cif.counters[class].Inc(1)
	if cif.allPass || analyzer.Good == class {
		return cif.next.Filter(mail)
	}

	return Quarantine
}
Ejemplo n.º 2
0
func (df *DeliverFilter) Filter(mail mailfile.Mail) Result {
	log.Printf("Run %s, Mail:%s\n", df, mail.Name())
	df.total.Inc(1)

	result := df.next.Filter(mail)

	df.counters[result].Inc(1)

	if result == None {
		log.Fatalf("DeliverFilter: the filter result should not be None, Mail:%s\n", mail.Name())
	}

	destination := filepath.Join(df.paths[result], mail.Name())
	log.Printf("Move to %s, Mail:%s\n", destination, mail.Name())

	err := os.Rename(mail.Path(), destination)
	if err != nil {
		log.Printf("DeliverFilter: Err:%v, Mail:%s\n", err, mail.Name())
	}

	return None
}
func (cih *ContentInspectionUpdater) Update(mail mailfile.Mail) {
	if leaner, ok := cih.anlz.(analyzer.Learner); ok {
		log.Printf("Run %s, Mail:%s\n", cih, mail.Name())
		cih.total.Inc(1)

		post, err := mailpost.Parse(mail)
		mail.Close()
		if err != nil {
			cih.malformed.Inc(1)
			log.Printf("ContentInspectionUpdater: Err:%v, Mail:%s\n", err, mail.Path())
			return
		}

		leaner.Learn(post.Subject, cih.class)
		leaner.Learn(post.Content, cih.class)

		err = os.Remove(mail.Path())
		if err != nil {
			log.Println(err)
		}
	}
}