mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-02-22 23:23:57 +01:00

Avoid importing code from worker/lib into lib. It should only be the other way around. Move the message parsing code used by maildir, notmuch, mbox and the eml viewer into a lib/rfc822 package. Adapt imports accordingly. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
29 lines
728 B
Go
29 lines
728 B
Go
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
|
|
}
|