diff options
Diffstat (limited to 'internal/formatter/email.go')
| -rw-r--r-- | internal/formatter/email.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/internal/formatter/email.go b/internal/formatter/email.go new file mode 100644 index 0000000..80f590c --- /dev/null +++ b/internal/formatter/email.go @@ -0,0 +1,103 @@ +package formatter + +import ( + "fmt" + "git.db.org.ai/dborg/internal/models" + "git.db.org.ai/dborg/internal/utils" +) + +func FormatEmailResults(response *models.EmailVerifyResponse, asJSON bool) error { + if asJSON { + return utils.PrintJSON(response) + } + + PrintSection(fmt.Sprintf("📧 Email Verification: %s", Bold(response.Email))) + + statusColor := ColorGreen + switch response.Status { + case "valid": + statusColor = ColorGreen + case "invalid": + statusColor = ColorRed + case "risky", "accept_all": + statusColor = ColorYellow + default: + statusColor = ColorGray + } + + fmt.Printf("%s: %s", Cyan("Status"), Colorize(response.Status, statusColor)) + if response.Score > 0 { + scoreColor := ColorGreen + if response.Score < 50 { + scoreColor = ColorRed + } else if response.Score < 75 { + scoreColor = ColorYellow + } + fmt.Printf(" (Score: %s)", Colorize(fmt.Sprintf("%d/100", response.Score), scoreColor)) + } + fmt.Println() + + fmt.Println() + fmt.Printf("%s\n", Bold("Validation Checks")) + + checks := []struct { + name string + passed bool + }{ + {"Format Valid", response.Regexp}, + {"MX Records Found", response.MXRecords}, + {"SMTP Server Reachable", response.SMTPServer}, + {"Mailbox Verified", response.SMTPCheck}, + } + + for _, check := range checks { + status := StatusError + if check.passed { + status = StatusSuccess + } + fmt.Printf(" %s %s\n", status.String(), check.name) + } + + if response.MXServer != "" { + fmt.Printf("\n%s: %s\n", Cyan("MX Server"), response.MXServer) + } + + fmt.Println() + fmt.Printf("%s\n", Bold("Risk Indicators")) + + risks := []struct { + name string + present bool + }{ + {"Disposable Email", response.Disposable}, + {"Webmail Service", response.Webmail}, + {"Blocked Domain", response.Block}, + {"Gibberish Detected", response.Gibberish}, + } + + hasRisks := false + for _, risk := range risks { + if risk.present { + hasRisks = true + fmt.Printf(" %s %s\n", StatusWarning.String(), risk.name) + } + } + + if !hasRisks { + fmt.Printf(" %s %s\n", StatusSuccess.String(), "No risk indicators found") + } + + if response.ResponseTimeMs > 0 { + fmt.Printf("\n%s: %dms\n", Dim("Response Time"), response.ResponseTimeMs) + } + + if response.ErrorMessage != "" { + fmt.Printf("\n%s: %s\n", Red("Error"), response.ErrorMessage) + } + + if response.VerifiedAt != "" { + fmt.Printf("%s: %s\n", Dim("Verified At"), response.VerifiedAt) + } + + return nil +} |
