func (h *Header) FieldsByKey(k string) HeaderFields {
	return &headerFieldsByKey{h, textproto.CanonicalMIMEHeaderKey(k), -1}
}
FieldsByKey iterates over all fields having the specified key.

The header may not be mutated while iterating, except using HeaderFields.Del.
package textproto
import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"net/textproto"
	"sort"
	"strings"
)
type headerField struct {
	b []byte  
	k string
	v string
}
func newHeaderField(k, v string, b []byte) *headerField {
	return &headerField{k: textproto.CanonicalMIMEHeaderKey(k), v: v, b: b}
}
func (f *headerField) raw() ([]byte, error) {
	if f.b != nil {
		return f.b, nil
	} else {
		for pos, ch := range f.k {
			if !(ch >= '!' && ch < ':' || ch > ':' && ch <= '~') {
				return nil, fmt.Errorf("field name contains incorrect symbols (\\x%x at %v)", ch, pos)
			}
		}
		if pos := strings.IndexAny(f.v, "\r\n"); pos != -1 {
			return nil, fmt.Errorf("field value contains \\r\\n (at %v)", pos)
		}
		return []byte(formatHeaderField(f.k, f.v)), nil
	}
}
type Header struct {
	l []*headerField
	m map[string][]*headerField
}
func makeHeaderMap(fs []*headerField) map[string][]*headerField {
	if len(fs) == 0 {
		return nil
	}
	m := make(map[string][]*headerField, len(fs))
	for i, f := range fs {
		m[f.k] = append(m[f.k], fs[i])
	}
	return m
}
func newHeader(fs []*headerField) Header {
	for i := len(fs)/2 - 1; i >= 0; i-- {
		opp := len(fs) - 1 - i
		fs[i], fs[opp] = fs[opp], fs[i]
	}
	return Header{l: fs, m: makeHeaderMap(fs)}
}
func HeaderFromMap(m map[string][]string) Header {
	fs := make([]*headerField, 0, len(m))
	for k, vs := range m {
		for _, v := range vs {
			fs = append(fs, newHeaderField(k, v, nil))
		}
	}
	sort.SliceStable(fs, func(i, j int) bool {
		return fs[i].k < fs[j].k
	})
	return newHeader(fs)
}
func (h *Header) AddRaw(kv []byte) {
	colon := bytes.IndexByte(kv, ':')
	if colon == -1 {
		panic("textproto: Header.AddRaw: missing colon")
	}
	k := textproto.CanonicalMIMEHeaderKey(string(trim(kv[:colon])))
	v := trimAroundNewlines(kv[colon+1:])
	if h.m == nil {
		h.m = make(map[string][]*headerField)
	}
	f := newHeaderField(k, v, kv)
	h.l = append(h.l, f)
	h.m[k] = append(h.m[k], f)
}
func (h *Header) Add(k, v string) {
	k = textproto.CanonicalMIMEHeaderKey(k)
	if h.m == nil {
		h.m = make(map[string][]*headerField)
	}
	f := newHeaderField(k, v, nil)
	h.l = append(h.l, f)
	h.m[k] = append(h.m[k], f)
}
func (h *Header) Get(k string) string {
	fields := h.m[textproto.CanonicalMIMEHeaderKey(k)]
	if len(fields) == 0 {
		return ""
	}
	return fields[len(fields)-1].v
}
func (h *Header) Raw(k string) ([]byte, error) {
	fields := h.m[textproto.CanonicalMIMEHeaderKey(k)]
	if len(fields) == 0 {
		return nil, nil
	}
	return fields[len(fields)-1].raw()
}
func (h *Header) Values(k string) []string {
	fields := h.m[textproto.CanonicalMIMEHeaderKey(k)]
	if len(fields) == 0 {
		return nil
	}
	l := make([]string, len(fields))
	for i, field := range fields {
		l[len(fields)-i-1] = field.v
	}
	return l
}
func (h *Header) Set(k, v string) {
	h.Del(k)
	h.Add(k, v)
}
func (h *Header) Del(k string) {
	k = textproto.CanonicalMIMEHeaderKey(k)
	delete(h.m, k)
	for i := len(h.l) - 1; i >= 0; i-- {
		if h.l[i].k == k {
			h.l = append(h.l[:i], h.l[i+1:]...)
		}
	}
}
func (h *Header) Has(k string) bool {
	_, ok := h.m[textproto.CanonicalMIMEHeaderKey(k)]
	return ok
}
func (h *Header) Copy() Header {
	l := make([]*headerField, len(h.l))
	copy(l, h.l)
	m := makeHeaderMap(l)
	return Header{l: l, m: m}
}
func (h *Header) Len() int {
	return len(h.l)
}
func (h *Header) Map() map[string][]string {
	m := make(map[string][]string, h.Len())
	fields := h.Fields()
	for fields.Next() {
		m[fields.Key()] = append(m[fields.Key()], fields.Value())
	}
	return m
}
type HeaderFields interface {
	Next() (more bool)
	Key() string
	Value() string
	Raw() ([]byte, error)
	Del()
	Len() int
}
type headerFields struct {
	h   *Header
	cur int
}
func (fs *headerFields) Next() bool {
	fs.cur++
	return fs.cur < len(fs.h.l)
}
func (fs *headerFields) index() int {
	if fs.cur < 0 {
		panic("message: HeaderFields method called before Next")
	}
	if fs.cur >= len(fs.h.l) {
		panic("message: HeaderFields method called after Next returned false")
	}
	return len(fs.h.l) - fs.cur - 1
}
func (fs *headerFields) field() *headerField {
	return fs.h.l[fs.index()]
}
func (fs *headerFields) Key() string {
	return fs.field().k
}
func (fs *headerFields) Value() string {
	return fs.field().v
}
func (fs *headerFields) Raw() ([]byte, error) {
	return fs.field().raw()
}
func (fs *headerFields) Del() {
	f := fs.field()
	ok := false
	for i, ff := range fs.h.m[f.k] {
		if ff == f {
			ok = true
			fs.h.m[f.k] = append(fs.h.m[f.k][:i], fs.h.m[f.k][i+1:]...)
			if len(fs.h.m[f.k]) == 0 {
				delete(fs.h.m, f.k)
			}
			break
		}
	}
	if !ok {
		panic("message: field not found in Header.m")
	}
	fs.h.l = append(fs.h.l[:fs.index()], fs.h.l[fs.index()+1:]...)
	fs.cur--
}
func (fs *headerFields) Len() int {
	return len(fs.h.l)
}
func (h *Header) Fields() HeaderFields {
	return &headerFields{h, -1}
}
type headerFieldsByKey struct {
	h   *Header
	k   string
	cur int
}
func (fs *headerFieldsByKey) Next() bool {
	fs.cur++
	return fs.cur < len(fs.h.m[fs.k])
}
func (fs *headerFieldsByKey) index() int {
	if fs.cur < 0 {
		panic("message: headerfields.key or value called before next")
	}
	if fs.cur >= len(fs.h.m[fs.k]) {
		panic("message: headerfields.key or value called after next returned false")
	}
	return len(fs.h.m[fs.k]) - fs.cur - 1
}
func (fs *headerFieldsByKey) field() *headerField {
	return fs.h.m[fs.k][fs.index()]
}
func (fs *headerFieldsByKey) Key() string {
	return fs.field().k
}
func (fs *headerFieldsByKey) Value() string {
	return fs.field().v
}
func (fs *headerFieldsByKey) Raw() ([]byte, error) {
	return fs.field().raw()
}
func (fs *headerFieldsByKey) Del() {
	f := fs.field()
	ok := false
	for i := range fs.h.l {
		if f == fs.h.l[i] {
			ok = true
			fs.h.l = append(fs.h.l[:i], fs.h.l[i+1:]...)
			break
		}
	}
	if !ok {
		panic("message: field not found in Header.l")
	}
	fs.h.m[fs.k] = append(fs.h.m[fs.k][:fs.index()], fs.h.m[fs.k][fs.index()+1:]...)
	if len(fs.h.m[fs.k]) == 0 {
		delete(fs.h.m, fs.k)
	}
	fs.cur--
}
func (fs *headerFieldsByKey) Len() int {
	return len(fs.h.m[fs.k])
}