email/cmd/addhashheader/addhashheader.go
Bill Thiede 12199604c1 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.
2014-03-28 21:46:34 -07:00

37 lines
486 B
Go

package main
import (
"flag"
"fmt"
"io"
"net/mail"
"os"
"github.com/golang/glog"
"xinu.tv/email"
)
func main() {
flag.Parse()
defer glog.Flush()
msg, err := mail.ReadMessage(os.Stdin)
if err != nil {
glog.Fatal(err)
}
h, err := email.HashMessage(msg)
if err != nil {
glog.Fatal(err)
}
for k, vs := range msg.Header {
for _, v := range vs {
fmt.Printf("%s: %s\n", k, v)
}
}
fmt.Println("X-Xinu-Hash:", h)
fmt.Println()
io.Copy(os.Stdout, msg.Body)
}