Skip to content

Commit

Permalink
Introduced deliverability reporting request/models
Browse files Browse the repository at this point in the history
  • Loading branch information
ey-mailosaur authored Sep 30, 2024
1 parent aac09fe commit 657eb42
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
52 changes: 52 additions & 0 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,59 @@ type SpamAnalysisResult struct {
Score float64 `json:"score"`
}

type EmailAuthenticationResult struct {
Result string `json:"result"`
Description string `json:"description"`
RawValue string `json:"rawValue"`
Tags map[string]string `json:"tags"`
}

type BlockListResult struct {
Id string `json:"id"`
Name string `json:"name"`
Result string `json:"result"`
}

type Content struct {
Embed bool `json:"embed"`
Iframe bool `json:"iframe"`
Object bool `json:"object"`
Script bool `json:"script"`
ShortUrls bool `json:"shortUrls"`
TextSize int `json:"textSize"`
TotalSize int `json:"totalSize"`
MissingAlt bool `json:"missingAlt"`
MissingListUnsubscribe bool `json:"missingListUnsubscribe"`
}

type DnsRecords struct {
A []string `json:"a"`
Mx []string `json:"mx"`
Ptr []string `json:"ptr"`
}

type SpamAssassinResult struct {
Score int `json:"score"`
Result string `json:"result"`
Rules []*SpamAssassinRule `json:"rules"`
}

type DeliverabilityReport struct {
Spf *EmailAuthenticationResult `json:"spf"`
Dkim []*EmailAuthenticationResult `json:"dkim"`
Dmarc *EmailAuthenticationResult `json:"dmarc"`
BlockLists []*BlockListResult `json:"blockLists"`
Content *Content `json:"content"`
DnsRecords *DnsRecords `json:"dnsRecords"`
SpamAssassin *SpamAssassinResult `json:"spamAssassin"`
}

func (s *AnalysisService) Spam(id string) (*SpamAnalysisResult, error) {
result, err := s.client.HttpGet(&SpamAnalysisResult{}, "api/analysis/spam/"+id)
return result.(*SpamAnalysisResult), err
}

func (s *AnalysisService) Deliverability(id string) (*DeliverabilityReport, error) {
result, err := s.client.HttpGet(&DeliverabilityReport{}, "api/analysis/deliverability/"+id)
return result.(*DeliverabilityReport), err
}
37 changes: 37 additions & 0 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,43 @@ func TestSpamAnalysis(t *testing.T) {
}
}

func TestDeliverability(t *testing.T) {
targetId := emails[0].Id
result, _ := client.Analysis.Deliverability(targetId)

assert.NotNil(t, result)

assert.NotNil(t, result.Spf)

assert.NotNil(t, result.Dkim)
for _, dkim := range result.Dkim {
assert.NotNil(t, dkim)
}

assert.NotNil(t, result.Dmarc)

assert.NotNil(t, result.BlockLists)
assert.True(t, len(result.BlockLists) != 0)
for _, blockList := range result.BlockLists {
assert.NotNil(t, blockList)
assert.NotNil(t, blockList.Id)
assert.NotNil(t, blockList.Name)
}

assert.NotNil(t, result.Content)

assert.NotNil(t, result.DnsRecords)
assert.NotNil(t, result.DnsRecords.A)
assert.NotNil(t, result.DnsRecords.Mx)
assert.NotNil(t, result.DnsRecords.Ptr)

assert.NotNil(t, result.SpamAssassin)
for _, rule := range result.SpamAssassin.Rules {
assert.True(t, len(rule.Rule) != 0)
assert.True(t, len(rule.Description) != 0)
}
}

func TestDeleteMessage(t *testing.T) {
targetEmailId := emails[4].Id

Expand Down

0 comments on commit 657eb42

Please sign in to comment.