Skip to content

Commit

Permalink
dkim: fix headerPicker.Pick with non-canonical header keys
Browse files Browse the repository at this point in the history
Closes: #58
  • Loading branch information
emersion committed Nov 20, 2023
1 parent bab2e0c commit a2108dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dkim/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func newHeaderPicker(h header) *headerPicker {
}

func (p *headerPicker) Pick(key string) string {
key = strings.ToLower(key)

at := p.picked[key]
for i := len(p.h) - 1; i >= 0; i-- {
kv := p.h[i]
Expand Down
13 changes: 12 additions & 1 deletion dkim/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ func TestHeaderPicker_Pick(t *testing.T) {
t.Errorf("Parameter %s not found in headers %s", k, headers)
}
}

})
t.Run("non-canonical header fields", func(t *testing.T) {
headers := header{
"Message-ID: asdf",
}
picker := newHeaderPicker(headers)
if v := picker.Pick("Message-Id"); v != headers[0] {
t.Errorf("Pick() = %q, want %q", v, headers[0])
}
if v := picker.Pick("Message-ID"); v != "" {
t.Errorf("Pick() = %q, want %q", v, "")
}
})
}

Expand Down

0 comments on commit a2108dd

Please sign in to comment.