Example #1
0
func PrintMailBoxStat(client *pop3.Client) error {
	mailCount, mailBoxSize, err := client.Stat()
	if err != nil {
		return err
	}

	fmt.Printf("Account:%s, MailCount:%d, MailBoxSize:%s\n", username, mailCount, fileutil.Humanize(uint64(mailBoxSize)))
	return nil
}
Example #2
0
func main() {
	classifier := bayesian.NewClassifier(Good, Bad)
	tokenizer, err := goseg.NewTokenizerFromFile(dictDataFilePath)
	if err != nil {
		log.Fatal(err)
	}

	for _, item := range trainingData {
		log.Printf("Traning %s", item.folder)
		totalNum := 0
		var totalSize int64

		startTime := time.Now()
		fis, err := ioutil.ReadDir(item.folder)

		if err != nil {
			log.Fatal(err)
		}

		for _, fi := range fis {
			if fi.IsDir() {
				continue
			}
			totalSize += fi.Size()

			filePath := filepath.Join(item.folder, fi.Name())
			mail := mailfile.NewPOP3Mail(filePath)
			if err = mail.Parse(); err != nil {
				log.Fatal(err)
			}

			post, err := mailpost.Parse(mail)
			mail.Close()
			if err != nil {
				log.Fatalf("Err: %v, Mail:%s", err, mail.Path())
			}

			words := analyzer.Normalize(tokenizer.Cut([]rune(post.Subject+" "+post.Content)), cutset)
			classifier.Learn(words, item.class)
			totalNum += 1
		}

		elapsed := time.Now().Sub(startTime)

		fmt.Printf("TotalNum: %d\n", totalNum)
		fmt.Printf("Elapsed: %s, TPS(Mail): %f, TPS(FileSize): %s\n",
			time.Now().Sub(startTime),
			float64(totalNum)/(float64(elapsed)/float64(time.Second)),
			fileutil.Humanize(uint64(float64(totalSize)/(float64(elapsed)/float64(time.Second)))))

	}

	classifier.WriteToFile(output)
}
Example #3
0
func main() {
	log.Printf("Mail all mails from %s to %s", folder, recipient)
	totalNum := 0
	var totalSize int64

	startTime := time.Now()
	fis, err := ioutil.ReadDir(folder)
	checkErr(err)

	auth := smtp.PlainAuth(
		"",
		user,
		passoword,
		smtpServer,
	)

	clients, err := NewSmtpClient(smtpServer+":"+strconv.Itoa(port), auth, concurrency)
	checkErr(err)
	defer clients.Close()

	wg := &sync.WaitGroup{}
	for _, fi := range fis {
		if fi.IsDir() {
			continue
		}
		totalSize += fi.Size()
		totalNum += 1

		filePath := filepath.Join(folder, fi.Name())
		rawBody, err := ioutil.ReadFile(filePath)
		checkErr(err)

		wg.Add(1)
		go func() {
			err = clients.SendMail(
				from,
				[]string{recipient},
				rawBody,
			)
			checkErr(err)
			wg.Done()
		}()
	}

	wg.Wait()
	elapsed := time.Now().Sub(startTime)
	fmt.Printf("TotalNum: %d, Elapsed: %s, TPS(Mail): %f, TPS(FileSize): %s\n",
		totalNum,
		time.Now().Sub(startTime),
		float64(totalNum)/(float64(elapsed)/float64(time.Second)),
		fileutil.Humanize(uint64(float64(totalSize)/(float64(elapsed)/float64(time.Second)))))

}
Example #4
0
func main() {
	anlz, err := analyzer.NewBayesianAnalyzer(traningDataFilePath, dictDataFilePath)
	if err != nil {
		log.Fatal(err)
	}

	for _, item := range testData {
		log.Printf("Testing %s", item.folder)

		totalNum, totalError, totalNeutral := 0, 0, 0
		var totalSize int64

		fis, err := ioutil.ReadDir(item.folder)

		if err != nil {
			log.Fatal(err)
		}

		startTime := time.Now()
		for _, fi := range fis {
			if fi.IsDir() {
				continue
			}
			totalSize += fi.Size()
			totalNum += 1

			mailFilePath := filepath.Join(item.folder, fi.Name())
			mail := mailfile.NewPOP3Mail(mailFilePath)
			if err = mail.Parse(); err != nil {
				log.Fatal(err)
			}

			post, err := mailpost.Parse(mail)
			mail.Close()
			if err != nil {
				log.Fatalf("Err: %v, Mail:%s", err, mail.Path())
			}

			class := anlz.Test(post.Subject + " " + post.Content)

			switch {
			case analyzer.Neutral == class:
				totalNeutral += 1
				fmt.Println(ansi.Color(mailFilePath, "cyan+b"))

			case item.class != class:
				totalError += 1
				fmt.Println(ansi.Color(mailFilePath, "red+b"))
			}

		}

		elapsed := time.Now().Sub(startTime)

		fmt.Printf("TotalNum: %d, TotalError: %d, ErrRate: %f, TotalNeutral:%d, Confident:%f\n",
			totalNum, totalError, float64(totalError)/float64(totalNum), totalNeutral, float64(totalNum-totalNeutral)/float64(totalNum))
		fmt.Printf("Elapsed: %s, TPS(Mail): %f, TPS(FileSize): %s\n",
			time.Now().Sub(startTime),
			float64(totalNum)/(float64(elapsed)/float64(time.Second)),
			fileutil.Humanize(uint64(float64(totalSize)/(float64(elapsed)/float64(time.Second)))))
	}
}