Filter Authentication-Results to keep only local ones
This commit is contained in:
parent
b2dc479a79
commit
932bc981b5
2 changed files with 29 additions and 1 deletions
|
|
@ -270,6 +270,8 @@ func TestParseLegacyDKIM(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseLegacyDKIM_Integration(t *testing.T) {
|
func TestParseLegacyDKIM_Integration(t *testing.T) {
|
||||||
|
hostname = ""
|
||||||
|
|
||||||
// Test that parseLegacyDKIM is properly integrated into AnalyzeAuthentication
|
// Test that parseLegacyDKIM is properly integrated into AnalyzeAuthentication
|
||||||
t.Run("Legacy DKIM is used when no Authentication-Results", func(t *testing.T) {
|
t.Run("Legacy DKIM is used when no Authentication-Results", func(t *testing.T) {
|
||||||
analyzer := NewAuthenticationAnalyzer()
|
analyzer := NewAuthenticationAnalyzer()
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,16 @@ import (
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var hostname = ""
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
hostname, _ = os.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
// EmailMessage represents a parsed email message
|
// EmailMessage represents a parsed email message
|
||||||
type EmailMessage struct {
|
type EmailMessage struct {
|
||||||
Header mail.Header
|
Header mail.Header
|
||||||
|
|
@ -211,8 +218,27 @@ func buildRawHeaders(header mail.Header) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuthenticationResults extracts Authentication-Results headers
|
// GetAuthenticationResults extracts Authentication-Results headers
|
||||||
|
// If hostname is provided, only returns headers that begin with that hostname
|
||||||
func (e *EmailMessage) GetAuthenticationResults() []string {
|
func (e *EmailMessage) GetAuthenticationResults() []string {
|
||||||
return e.Header[textproto.CanonicalMIMEHeaderKey("Authentication-Results")]
|
allResults := e.Header[textproto.CanonicalMIMEHeaderKey("Authentication-Results")]
|
||||||
|
|
||||||
|
// If no hostname specified, return all results
|
||||||
|
if hostname == "" {
|
||||||
|
return allResults
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter results that begin with the specified hostname
|
||||||
|
var filtered []string
|
||||||
|
prefix := hostname + ";"
|
||||||
|
for _, result := range allResults {
|
||||||
|
// Trim whitespace and check if it starts with hostname;
|
||||||
|
trimmed := strings.TrimSpace(result)
|
||||||
|
if strings.HasPrefix(trimmed, prefix) {
|
||||||
|
filtered = append(filtered, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSpamAssassinHeaders extracts SpamAssassin-related headers
|
// GetSpamAssassinHeaders extracts SpamAssassin-related headers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue