Documentation
¶
Overview ¶
Package rspamdclient contains the Rspamd client models
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckRequest ¶
type CheckRequest struct {
// DeliverTo defines the actual delivery recipient of the message.
// Can be used for personalized statistics and user-specific options.
DeliverTo string `json:"deliver_to,omitempty"`
// IP defines the IP address from which this message was received.
// Used for IP-based filtering and reputation checks.
IP string `json:"ip,omitempty"`
// Helo defines the SMTP HELO command value.
// Used for HELO-based filtering and validation.
Helo string `json:"helo,omitempty"`
// Hostname defines the resolved hostname of the sending server.
// Used for hostname-based filtering and reverse DNS checks.
Hostname string `json:"hostname,omitempty"`
// Flags defines output flags as a comma-separated list.
// Supported flags: pass_all, groups, zstd, no_log, milter, profile, body_block, ext_urls, skip, skip_process
Flags []string `json:"flags,omitempty"`
// From defines the SMTP MAIL FROM command data (sender email address).
// Used for sender-based filtering and reputation checks.
From string `json:"from,omitempty"`
// QueueID defines the SMTP queue ID for the message.
// Can be used instead of message ID in logging for better traceability.
QueueID string `json:"queue_id,omitempty"`
// Raw indicates whether the content should be treated as raw data instead of MIME.
// If set to true, Rspamd assumes the content is not MIME and treats it as raw data.
Raw bool `json:"raw,omitempty"`
// Rcpt defines the SMTP recipient(s) of the message.
// Multiple recipients can be specified for multi-recipient messages.
Rcpt []string `json:"rcpt,omitempty"`
// Pass controls which filters should be checked for this message.
// If set to "all", all filters will be checked regardless of settings.
// #nosec G117 -- This is a legitimate API field name, not a hardcoded secret
Pass string `json:"pass,omitempty"`
// Subject defines the subject of the message.
// Used for non-MIME messages or when subject needs to be explicitly specified.
Subject string `json:"subject,omitempty"`
// User defines the username for authenticated SMTP client.
// Used for user-based filtering and authentication checks.
User string `json:"user,omitempty"`
// Message contains the actual email message content in RFC 2822 format.
// This is the raw email data that will be analyzed by Rspamd.
Message []byte `json:"message"`
}
CheckRequest represents the request structure for Rspamd spam checking
type CheckResponse ¶
type CheckResponse struct {
// Action indicates the action taken by Rspamd based on the spam score.
// Possible values: "reject", "soft reject", "add header", "rewrite subject", "greylist", "no action"
Action string `json:"action"`
// Score is the calculated spam score for the message.
// Higher scores indicate higher likelihood of spam.
Score float64 `json:"score"`
// RequiredScore is the threshold score required to trigger the action.
// This is the configured threshold for the action that was taken.
RequiredScore float64 `json:"required_score"`
// Symbols contains the triggered spam detection symbols and their details.
// Each symbol represents a specific spam detection rule that was matched.
Symbols map[string]interface{} `json:"symbols"`
// Raw holds the complete Rspamd response, field-by-field, without imposing a
// type on any value. Every key Rspamd returns (including the strictly-typed
// ones above, and everything else — milter, emails, ip_reputation, dkim, …)
// lands here as deferred JSON, so no field shape can ever break the decode.
Raw map[string]json.RawMessage `json:"-"`
}
CheckResponse represents the response from Rspamd spam checking.
Only the fields the mail pipeline actually consumes are strictly typed. Rspamd's /checkv2 response carries many more fields whose JSON shape varies by config/version (a field may be an object, an array, a string, or absent), and a single mismatch would abort a strict struct decode and silently disable spam scoring. To avoid that whole class of bug, the full response is captured losslessly in Raw via a custom UnmarshalJSON, and the decode never fails on an unexpected field shape. See UnmarshalJSON below.
func (*CheckResponse) GetAction ¶
func (r *CheckResponse) GetAction() string
GetAction returns the action taken by Rspamd
func (*CheckResponse) GetScore ¶
func (r *CheckResponse) GetScore() float64
GetScore returns the spam score
func (*CheckResponse) IsSpam ¶
func (r *CheckResponse) IsSpam() bool
IsSpam checks if the response indicates spam
func (*CheckResponse) UnmarshalJSON ¶
func (r *CheckResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes the used fields strictly and captures the entire response in Raw. Because Raw is a map[string]json.RawMessage, any value shape (object, array, string, number, null) is accepted without error — a field whose shape is unexpected can never fail the decode.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an Rspamd HTTP client for spam checking
func (*Client) CheckMessage ¶
func (c *Client) CheckMessage(req *CheckRequest) (*CheckResponse, error)
CheckMessage sends a message to Rspamd for spam checking
type Config ¶
type Config struct {
// BaseURL is the base URL of the Rspamd server.
// Should include protocol (http/https) and port if not default.
BaseURL string
// Password is the authentication password for the Rspamd server.
// Required if Rspamd is configured with password authentication.
// #nosec G117 -- This is a legitimate API field name, not a hardcoded secret
Password string
// Timeout is the HTTP timeout for requests to the Rspamd server.
// Should be set to a reasonable value to avoid hanging requests.
Timeout time.Duration
// MaxRetries is the maximum number of retry attempts for failed requests.
// Useful for handling temporary network issues or server overload.
MaxRetries int
}
Config holds the configuration for the Rspamd client
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default configuration with environment variable support