Esempio n. 1
0
func (s *diskStorage) PutEmail(addr *webfist.EmailAddr, email *webfist.Email) error {
	emailRoot := s.emailRoot(addr)
	err := os.MkdirAll(emailRoot, 0755)
	if err != nil {
		return err
	}

	r, err := email.Encrypted()
	if err != nil {
		return err
	}
	enc, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}

	s1 := sha1.New()
	s1.Write(enc)

	addrKey := addr.HexKey()
	encSHA1 := fmt.Sprintf("%x", s1.Sum(nil))
	email.SetEncSHA1(encSHA1)

	emailPath := filepath.Join(emailRoot, encSHA1)
	if err := ioutil.WriteFile(emailPath, enc, 0644); err != nil {
		return err
	}
	return s.touchRecent(addrKey, encSHA1)
}
Esempio n. 2
0
func (s *diskStorage) emailRoot(addr *webfist.EmailAddr) string {
	return s.emailRootFromHex(addr.HexKey())
}