Use original header bytes instead of printing parsed forms.
This commit is contained in:
parent
b79c894575
commit
646ec2864f
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -16,7 +17,8 @@ func main() {
|
||||
flag.Parse()
|
||||
defer glog.Flush()
|
||||
|
||||
msg, err := mail.ReadMessage(os.Stdin)
|
||||
hdrBuf := new(bytes.Buffer)
|
||||
msg, err := mail.ReadMessage(io.TeeReader(os.Stdin, hdrBuf))
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
}
|
||||
@ -25,12 +27,20 @@ func main() {
|
||||
if err != nil {
|
||||
glog.Fatal(err)
|
||||
}
|
||||
for k, vs := range msg.Header {
|
||||
for _, v := range vs {
|
||||
fmt.Printf("%s: %s\n", k, v)
|
||||
// Find end of header in original byte stream.
|
||||
n := bytes.Index(hdrBuf.Bytes(), []byte("\n\n"))
|
||||
if n == -1 {
|
||||
glog.Error("Couldn't find end of headers in hdrBuf")
|
||||
// Copy the original message untouched.
|
||||
io.Copy(os.Stdout, hdrBuf)
|
||||
io.Copy(os.Stdout, os.Stdin)
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Println("X-Xinu-Hash:", h)
|
||||
fmt.Println()
|
||||
|
||||
// Copy the headers out untouched.
|
||||
io.CopyN(os.Stdout, hdrBuf, int64(n))
|
||||
// Insert our new header.
|
||||
fmt.Printf("\nX-Xinu-Hash: %s\n\n", h)
|
||||
// Copy the message body out untouched.
|
||||
io.Copy(os.Stdout, msg.Body)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user