dmarc

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package dmarc contains reader and parser for DMARC xml reports.

Index

Constants

View Source
const (
	// MimeTypeGZIP is the mimetype for *.gz files
	MimeTypeGZIP = "application/x-gzip"
	// MimeTypeZIP is the mimetype for *.zip files
	MimeTypeZIP = "application/zip"
	// MimeTypeXML is the mimetype for *.xml files
	MimeTypeXML = "text/xml"
)
View Source
const ReportIDDateTime = "2006-01-02"

ReportIDDateTime is the DateTime format for Report.ID

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResults

type AuthResults struct {
	DKIM DKIMAuthResult `xml:"dkim" json:"dkim"`
	SPF  SPFAuthResult  `xml:"spf" json:"spf"`
}

AuthResults represents feedback>record>auth_results section

type DKIMAuthResult

type DKIMAuthResult struct {
	Domain   string `xml:"domain" json:"domain"`
	Result   string `xml:"result" json:"result"`
	Selector string `xml:"selector" json:"selector"`
}

DKIMAuthResult represnets feedback>record>auth_results>dkim sections

type DateRange

type DateRange struct {
	Begin DateTime `xml:"begin" json:"begin"`
	End   DateTime `xml:"end" json:"end"`
}

DateRange represents feedback>report_metadata>date_range section

type DateTime

type DateTime struct {
	time.Time
}

DateTime is the custom time for DateRange.Begin and DateRange.End values

func (*DateTime) UnmarshalXML

func (t *DateTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals unix timestamp to time.Time

type Identifiers

type Identifiers struct {
	HeaderFrom   string `xml:"header_from" json:"header_from"`
	EnvelopeFrom string `xml:"envelope_from" json:"envelope_from"`
}

Identifiers represents feedback>record>identifiers section

type MessagesStats

type MessagesStats struct {
	// All it is the total amount of email messages
	All int `json:"all"`
	// Failed it is the total amount of failed email messages
	Failed int `json:"failed"`
	// Passed it is the total amount of passed email messages
	Passed int `json:"passed"`
	// PassedPercent it is the percent of passed email messages
	PassedPercent float64 `json:"passed_percent"`
}

MessagesStats includes some statistic calculated from report.

type PolicyEvaluated

type PolicyEvaluated struct {
	Disposition string `xml:"disposition" json:"disposition"`
	DKIM        string `xml:"dkim" json:"dkim"`
	SPF         string `xml:"spf" json:"spf"`
}

PolicyEvaluated represents feedback>record>row>policy_evaluated section

type PolicyPublished

type PolicyPublished struct {
	Domain  string `xml:"domain" json:"domain"`
	ADKIM   string `xml:"adkim" json:"adkim"`
	ASPF    string `xml:"aspf" json:"aspf"`
	Policy  string `xml:"p" json:"p"`
	SPolicy string `xml:"sp" json:"sp"`
	Pct     string `xml:"pct" json:"pct"`
}

PolicyPublished represents feedback>policy_published section

type Record

type Record struct {
	Row         Row         `xml:"row"`
	Identifiers Identifiers `xml:"identifiers"`
	AuthResults AuthResults `xml:"auth_results"`
}

Record represents feedback>record section

func (Record) IsPassed

func (r Record) IsPassed() bool

IsPassed returns true if DKIM or SPF policies are passed

func (Record) MarshalJSON

func (r Record) MarshalJSON() ([]byte, error)

MarshalJSON marshals Record struct to json, adds additional "_is_passed" field.

type Report

type Report struct {
	XMLName         xml.Name        `xml:"feedback"`
	ReportMetadata  ReportMetadata  `xml:"report_metadata"`
	PolicyPublished PolicyPublished `xml:"policy_published"`
	Records         []Record        `xml:"record"`
	MessagesStats   MessagesStats
}

Report represents root of dmarc report struct

func Parse

func Parse(b []byte, lookupAddr bool) (Report, error)

Parse parses input xml data b to Report struct. If lookupAddr is true, performs a reverse lookups for feedback>record>row>source_ip

func ReadParse added in v0.6.2

func ReadParse(r io.Reader, lookupAddr bool) (Report, error)

ReadParse reads any data from reader r, detects mimetype, and parses it to Report struct (if mimetype is supported). If lookupAddr is true, performs reverse lookups for feedback>record>row>source_ip

func ReadParseGZIP

func ReadParseGZIP(r io.Reader, lookupAddr bool) (Report, error)

ReadParseGZIP reads gzipped xml data from r and parses it to Report struct. If lookupAddr is true, performs a reverse lookups for feedback>record>row>source_ip

func ReadParseXML

func ReadParseXML(r io.Reader, lookupAddr bool) (Report, error)

ReadParseXML reads xml data from r and parses it to Report struct. If lookupAddr is true, performs a reverse lookups for feedback>record>row>source_ip

func ReadParseZIP

func ReadParseZIP(r io.Reader, lookupAddr bool) (Report, error)

ReadParseZIP reads zipped xml data from r and parses it to Report struct. If lookupAddr is true, performs a reverse lookups for feedback>record>row>source_ip

func (*Report) CalculateStats

func (r *Report) CalculateStats()

CalculateStats calculates messages statistic and updates Records.MessagesStats struct.

func (Report) ID

func (r Report) ID() string

ID returns report identifier with format YEAR-MONTH-DAY-DOMAIN/EMAIL-ID (can be used in config to calculate filename), where date is the begin date of report.

func (Report) MarshalJSON

func (r Report) MarshalJSON() ([]byte, error)

MarshalJSON calculates report messages statistic and marshals Report struct to json, adds this statistic as additional fields:

"messages_stats" {
	"all": 0,
	"failed": 0,
	"passed": 0,
	"passed_percent": 0,
}

func (*Report) MergeRecord

func (r *Report) MergeRecord(rec Record)

MergeRecord merges new record rec to the report r.

func (*Report) MergeReport

func (r *Report) MergeReport(rep Report)

MergeReport merges another report rep to the report r. Keeps the earliest Begin date and the oldest End date. Merges all records from report rep to the r. Doesn't touch another r fields.

func (*Report) SortRecords

func (r *Report) SortRecords()

SortRecords sorts records list by Row.Count

func (Report) TodayID

func (r Report) TodayID() string

TodayID returns report identifier in format YEAR-MONTH-DAY-DOMAIN/EMAIL-ID (can be used in config to calculate filename), where date is the current date.

type ReportMetadata

type ReportMetadata struct {
	OrgName          string    `xml:"org_name" json:"org_name"`
	Email            string    `xml:"email" json:"email"`
	ExtraContactInfo string    `xml:"extra_contact_info" json:"extra_contact_info"`
	ReportID         string    `xml:"report_id" json:"report_id"`
	DateRange        DateRange `xml:"date_range" json:"date_range"`
}

ReportMetadata represents feedback>report_metadata section

type Row

type Row struct {
	SourceIP        string          `xml:"source_ip" json:"source_ip"`
	Count           int             `xml:"count" json:"count"`
	PolicyEvaluated PolicyEvaluated `xml:"policy_evaluated" json:"policy_evaluated"`
	SourceHostname  string          `json:"source_hostname"`
}

Row represents feedback>record>row section

type SPFAuthResult

type SPFAuthResult struct {
	Domain string `xml:"domain" json:"domain"`
	Result string `xml:"result" json:"result"`
	Scope  string `xml:"scope" json:"scope"`
}

SPFAuthResult represnets feedback>record>auth_results>spf section

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL