diff --git a/analysis.go b/analysis.go index c9cea52..5e24bc9 100644 --- a/analysis.go +++ b/analysis.go @@ -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 +} diff --git a/messages_test.go b/messages_test.go index 4843a11..6ac3ae4 100644 --- a/messages_test.go +++ b/messages_test.go @@ -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