예제 #1
0
func (s *diskStorage) Emails(addr *webfist.EmailAddr) ([]*webfist.Email, error) {
	emailRoot := s.emailRoot(addr)
	file, err := os.Open(emailRoot)
	if os.IsNotExist(err) {
		return nil, nil
	}
	if err != nil {
		return nil, err
	}
	infoList, err := file.Readdir(-1)
	if err != nil {
		return nil, err
	}
	result := make([]*webfist.Email, len(infoList))
	for i, info := range infoList {
		emailPath := filepath.Join(emailRoot, info.Name())
		file, err := os.Open(emailPath)
		if err != nil {
			return nil, err
		}
		all, err := ioutil.ReadAll(addr.Decrypter(file))
		if err != nil {
			return nil, err
		}
		email, err := webfist.NewEmail(all)
		if err != nil {
			return nil, err
		}
		result[i] = email
	}
	return result, nil
}
예제 #2
0
func (DummyStorage) Emails(*webfist.EmailAddr) ([]*webfist.Email, error) {
	files := []string{
		"gmail_dkim.txt",
	}
	var res []*webfist.Email
	for _, file := range files {
		full := filepath.Join("../testdata", file)
		all, err := ioutil.ReadFile(full)
		if err != nil {
			return nil, err
		}
		e, err := webfist.NewEmail(all)
		if err != nil {
			return nil, err
		}
		res = append(res, e)
	}
	return res, nil
}
예제 #3
0
파일: smtp.go 프로젝트: jaredhanson/webfist
func (e *env) Close() error {
	em, err := webfist.NewEmail(e.buf.Bytes())
	if err != nil {
		return err
	}
	verified := em.Verify()
	log.Printf("email from %v; verified = %v", e.from.Canonical(), verified)
	if !verified {
		return errors.New("DKIM verification failed")
	}

	_, err = em.WebFist()
	if err != nil {
		return errors.New("Invalid or missing WebFist commands in email.")
	}
	from, err := em.From()
	if err != nil {
		return errors.New("Bogus From header")
	}

	return e.s.storage.PutEmail(from, em)
}
예제 #4
0
파일: add.go 프로젝트: jaredhanson/webfist
func (s *server) WebFormAdd(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		http.Error(w, "Invalid method.", 400)
		return
	}
	all := r.FormValue("email")
	all = strings.TrimLeft(all, " \t\n\r")
	em, err := webfist.NewEmail([]byte(all))
	if err != nil {
		http.Error(w, "Bogus email: "+err.Error(), 400)
		return
	}

	from, err := em.From()
	if err != nil {
		http.Error(w, "No From", 400)
		return
	}

	if !em.Verify() {
		http.Error(w, "Email didn't verify. No DKIM.", 400)
		return
	}

	webfist, err := em.WebFist()
	if err != nil {
		http.Error(w, "Email didn't contain WebFist command: "+err.Error(), 400)
		return
	}

	err = s.storage.PutEmail(from, em)
	if err != nil {
		http.Error(w, "Storage error: "+err.Error(), 500)
		return
	}
	fmt.Fprintf(w, "Saved. Extracted email = %#v", webfist)
}