Example #1
0
func Parse(mail mailfile.Mail) (*post.Post, error) {

	//JavaTWO即 將於 7/20盛 大舉辦!即日起可享早鳥優惠, 將New iPad帶 回家!
	if !strings.HasPrefix(mail.Subject(), "JWorld@TW") {
		return nil, ErrNotSupport
	}

	//JWorld@TW新文章通知:Hello JavaFX! Part 3
	for _, prefix := range []string{"JWorld@TW新文章通知:"} {
		if strings.HasPrefix(mail.Subject(), prefix) {
			return article.Parse(mail.Content())
		}
	}

	//JWorld@TW, 回覆通知
	if strings.HasPrefix(mail.Subject(), "JWorld@TW, 回覆通知") {
		return general.Parse(mail.Content())
	}

	//JWorld@TW新話題通知:*.class如何反編譯回*.java還能正常執行?
	//JWorld@TW話題更新通知:Guava 教學系列文章
	for _, prefix := range []string{"JWorld@TW新話題通知:", "JWorld@TW話題更新通知:", "JWorld@TW話題更新通知:"} {
		if strings.HasPrefix(mail.Subject(), prefix) {
			return general.Parse(mail.Content())
		}
	}

	return nil, ErrNotSupport
}
func (spmf *SubjectPrefixMatchFilter) Filter(mail mailfile.Mail) Result {
	log.Printf("Run %s, Mail:%s\n", spmf, mail.Name())
	spmf.total.Inc(1)

	matched := false
	for _, subjectPrefix := range spmf.subjectPrefixes {
		if strings.HasPrefix(mail.Subject(), subjectPrefix) {
			matched = true
			spmf.matched.Inc(1)
			break
		}
	}

	if !matched {
		return Incoming
	}

	return spmf.next.Filter(mail)
}
func (cif *ContentInspectionFilter) Key(mail mailfile.Mail) string {
	return mail.Subject()
}