Add helper to print message with hash as a header.

Broke out email.go's Hash() in to multiple functions to make this easier, and
update tools that used it.
This commit is contained in:
2014-03-28 21:46:34 -07:00
parent 4c906e9f49
commit 12199604c1
5 changed files with 193 additions and 31 deletions

View File

@@ -34,8 +34,6 @@ type Messages struct {
Statuses []Status
}
var headers = []string{"to", "from", "cc", "date", "subject"}
func (m *Messages) hashMail(path string, info os.FileInfo, err error) error {
glog.Infoln("Processing", path)
if err != nil {
@@ -58,7 +56,7 @@ func (m *Messages) hashMail(path string, info os.FileInfo, err error) error {
}
defer r.Close()
h, err := email.Hash(r, headers)
h, err := email.HashReader(r)
if err != nil {
glog.Errorf("%s not an mail file", path)
glog.Infof("%q", err.Error())
@@ -67,7 +65,7 @@ func (m *Messages) hashMail(path string, info os.FileInfo, err error) error {
md := email.NewInfo(path)
m.Statuses = append(m.Statuses, Status{
Path: path,
Hash: fmt.Sprintf("%x", h.Sum(nil)),
Hash: h,
Read: md.Seen,
})
return nil
@@ -139,14 +137,13 @@ func (m Messages) Reconcile(maildir string) error {
}
defer r.Close()
h, err := email.Hash(r, headers)
chksum, err := email.HashReader(r)
if err != nil {
glog.Errorf("%s not an mail file", path)
glog.Infof("%q", err.Error())
return nil
}
chksum := fmt.Sprintf("%x", h.Sum(nil))
md := email.NewInfo(path)
s, ok := hashMap[chksum]
if !ok {