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

@@ -29,9 +29,6 @@ var (
skipFiles = flag.String("skip", "maildirfolder,log,msgid.cache,razor-agent.log",
"comma separated files to skip")
// Hashed over fields from each message.
headers = []string{"to", "from", "cc", "date", "subject", "message-id"}
total = expvar.NewInt("bytes-parsed")
cnt = expvar.NewInt("messages-parsed")
dupCnt = expvar.NewInt("duplicates-found")
@@ -101,14 +98,13 @@ func Load(db *sql.DB, uid int, root string, skip *set.StringSet) error {
}
hdr_size := bytes.Index(b, CRCR)
h, err := email.Hash(bytes.NewReader(b), headers)
chksum, err := email.HashReader(bytes.NewReader(b))
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))
if _, err := hstmt.Exec(chksum, path); err != nil {
return err
}