Documentation
¶
Overview ¶
Package spamcheck is a tiny client for Postmark's SpamCheck API (https://spamcheck.postmarkapp.com/doc/). It scores a raw RFC-822 email against SpamAssassin rules and returns the score and, optionally, the full matched-rule breakdown plus report.
Index ¶
Constants ¶
const (
// DefaultBaseURL is the public Postmark SpamCheck API base URL.
DefaultBaseURL = "https://spamcheck.postmarkapp.com"
)
Variables ¶
var ( // ErrEmptyEmail is returned when the raw email passed to Check is empty. ErrEmptyEmail = errors.New("raw email is empty") // ErrUnexpectedStatus is returned when the API responds with a non-200 status. ErrUnexpectedStatus = errors.New("unexpected response status") // ErrDecodeResponse is returned when the API response cannot be decoded. ErrDecodeResponse = errors.New("failed to decode response") // ErrAPIFailure is returned when the API responds with success=false. ErrAPIFailure = errors.New("api reported failure") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the SpamCheck API.
func New ¶
New builds a Client. With no options it uses an http.Client with a 30s timeout against the public Postmark endpoint.
type HTTPDoer ¶
HTTPDoer is the slice of *http.Client this package depends on. Swap in a fake to test without hitting the network.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithBaseURL ¶
WithBaseURL overrides the API base URL. Useful for tests or a proxy.
func WithHTTPDoer ¶
WithHTTPDoer sets a custom HTTP client — a fake in tests, or an http.Client with a specific timeout or transport.
type Result ¶
type Result struct {
Success bool `json:"success"`
Score string `json:"score"`
Rules []Rule `json:"rules"`
Report string `json:"report"`
Message string `json:"message"` // set when Success is false
}
Result is the SpamCheck API response. Rules and Report are only populated when the check was requested with ReportLong.
func Check ¶
Check runs a one-off spam check with a default client against the public Postmark endpoint. For repeated calls, build a Client with New and reuse it.
func (*Result) ScoreValue ¶
ScoreValue parses Score into a float64. The API returns the SpamAssassin score as a string; higher means more spammy.