File: headers.go

package info (click to toggle)
aerc 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: ansic: 1,181; python: 1,000; sh: 553; awk: 360; makefile: 23
file content (29 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package lib

import (
	"strings"

	"github.com/emersion/go-message/mail"
)

// LimitHeaders returns a new Header with the specified headers included or
// excluded
func LimitHeaders(hdr *mail.Header, fields []string, exclude bool) *mail.Header {
	fieldMap := make(map[string]struct{}, len(fields))
	for _, f := range fields {
		fieldMap[strings.ToLower(f)] = struct{}{}
	}
	nh := &mail.Header{}
	curFields := hdr.Fields()
	for curFields.Next() {
		key := strings.ToLower(curFields.Key())
		_, present := fieldMap[key]
		// XOR exclude and present. When they are equal, it means we
		// should not add the header to the new header struct
		if exclude == present {
			continue
		}
		nh.Add(key, curFields.Value())
	}
	return nh
}