Skip to content

Commit

Permalink
authres: add support for ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Dec 28, 2024
1 parent 67505da commit 999f438
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions authres/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package authres

import (
"errors"
"fmt"
"strconv"
"strings"
"unicode"
)
Expand Down Expand Up @@ -186,6 +188,42 @@ func (r *DMARCResult) format() (ResultValue, map[string]string) {
}
}

type ARCResult struct {
Value ResultValue
RemoteIP string
OldestPass int
}

func (r *ARCResult) parse(value ResultValue, params map[string]string) error {
var oldestPass int
if s, ok := params["header.oldest-pass"]; ok {
var err error
oldestPass, err = strconv.Atoi(s)
if err != nil {
return fmt.Errorf("invalid header.oldest-pass param: %v", err)
} else if oldestPass <= 0 {
return fmt.Errorf("invalid header.oldest-pass param: must be >= 1")
}
}

r.Value = value
r.RemoteIP = params["smtp.remote-ip"]
r.OldestPass = oldestPass
return nil
}

func (r *ARCResult) format() (ResultValue, map[string]string) {
var oldestPass string
if r.OldestPass > 0 {
oldestPass = strconv.Itoa(r.OldestPass)
}

return r.Value, map[string]string{
"smtp.remote-ip": r.RemoteIP,
"header.oldest-pass": oldestPass,
}
}

type GenericResult struct {
Method string
Value ResultValue
Expand All @@ -205,6 +243,9 @@ func (r *GenericResult) format() (ResultValue, map[string]string) {
type newResultFunc func() Result

var results = map[string]newResultFunc{
"arc": func() Result {
return new(ARCResult)
},
"auth": func() Result {
return new(AuthResult)
},
Expand Down

0 comments on commit 999f438

Please sign in to comment.