Add received path to hash, and has over repeated fields.
This commit is contained in:
parent
1699182671
commit
069ea6962a
23
hash.go
23
hash.go
@ -5,10 +5,9 @@ import (
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
"sort"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// Hasher is a list of headers that should be considered when hashing an email
|
||||
@ -17,18 +16,20 @@ type Hasher []string
|
||||
|
||||
// Hash will parse r as an email, and return a hash.Hash that has been applied
|
||||
// to the values of the headers in h.
|
||||
func (h Hasher) HashMessage(msg *mail.Message) (hash.Hash, error) {
|
||||
func (hsr Hasher) HashMessage(msg *mail.Message) (hash.Hash, error) {
|
||||
// Add deterministic behavior regardless of the order the users specified.
|
||||
if !sort.IsSorted(sort.StringSlice(h)) {
|
||||
sort.Strings(h)
|
||||
if !sort.IsSorted(sort.StringSlice(hsr)) {
|
||||
sort.Strings(hsr)
|
||||
}
|
||||
hsh := sha1.New()
|
||||
for _, header := range h {
|
||||
v := msg.Header.Get(header)
|
||||
if v == "" {
|
||||
glog.V(2).Infoln("Empty", header, "header")
|
||||
for _, h := range hsr {
|
||||
h := http.CanonicalHeaderKey(h)
|
||||
vs, ok := msg.Header[h]
|
||||
if ok {
|
||||
for _, v := range vs {
|
||||
io.WriteString(hsh, v)
|
||||
}
|
||||
}
|
||||
io.WriteString(hsh, v)
|
||||
}
|
||||
return hsh, nil
|
||||
}
|
||||
@ -41,7 +42,7 @@ func (h Hasher) HashReader(r io.Reader) (hash.Hash, error) {
|
||||
return h.HashMessage(msg)
|
||||
}
|
||||
|
||||
var std = Hasher([]string{"to", "from", "cc", "date", "subject", "message-id"})
|
||||
var std = Hasher([]string{"to", "from", "cc", "date", "subject", "message-id", "received"})
|
||||
|
||||
// Hash will parse r as an email, and return the hash as a hexadecimal string
|
||||
// using a default set of headers.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user