### Install Anti Disposable Email Package Source: https://github.com/rocketlaunchr/anti-disposable-email/blob/master/README.md Installs the anti-disposable-email package using the go get command. This is the first step to include the package in your Go project. ```bash go get -u github.com/rocketlaunchr/anti-disposable-email ``` -------------------------------- ### Handle Invalid Email Addresses with ErrInvalidEmail (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Demonstrates how to check for invalid email formats using the `disposable.ErrInvalidEmail` error. Covers common invalid patterns like empty strings, missing '@', and invalid domain formats. Includes an example of rejecting registrations with invalid or disposable emails. ```go package main import ( "errors" "fmt" disposable "github.com/rocketlaunchr/anti-disposable-email" ) func main() { invalidEmails := []string{ "", // empty " ", // whitespace only "no-at-sign", // missing @ "multiple@@at.com", // multiple @ "spaces in@email.com", // contains spaces "user@.invalid", // domain starts with dot "user@invalid.", // domain ends with dot } for _, email := range invalidEmails { _, err := disposable.ParseEmail(email) if errors.Is(err, disposable.ErrInvalidEmail) { fmt.Printf("Invalid email: %q\n", email) } } // Proper error handling in registration flow userEmail := "new.user@gmail.com" parsed, err := disposable.ParseEmail(userEmail) if err != nil { fmt.Printf("Registration rejected: invalid email format\n") return } if parsed.Disposable { fmt.Printf("Registration rejected: disposable email not allowed\n") return } fmt.Printf("Registration accepted for: %s\n", parsed.Email) } ``` -------------------------------- ### Access and Check Disposable Email Domain List (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Provides direct access to a map containing all known disposable email domains. This list can be queried to check if a domain is disposable or to get the total count of blocked domains. The list is sourced from a community repository and can be updated at runtime. ```go package main import ( "fmt" disposable "github.com/rocketlaunchr/anti-disposable-email" ) func main() { // Check domain directly against the list domain := "mailinator.com" if _, exists := disposable.DisposableList[domain]; exists { fmt.Printf("%s is a disposable email domain\n", domain) } // Get total count of blocked domains fmt.Printf("Total disposable domains: %d\n", len(disposable.DisposableList)) // Check multiple domains domainsToCheck := []string{"gmail.com", "10minutemail.com", "yahoo.com", "guerrillamail.com"} for _, d := range domainsToCheck { _, isDisposable := disposable.DisposableList[d] fmt.Printf("%s: disposable=%v\n", d, isDisposable) } } ``` -------------------------------- ### Update Disposable Email List at Runtime (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Fetches the latest disposable email domain list from a GitHub repository. Supports optional mutex locking for thread-safe updates in concurrent applications. Requires context for timeouts and the disposable email list to update. ```go package main import ( "context" "fmt" "log" "sync" "time" disposable "github.com/rocketlaunchr/anti-disposable-email" "github.com/rocketlaunchr/anti-disposable-email/update" ) func main() { // Simple update without locking ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() fmt.Printf("Domains before update: %d\n", len(disposable.DisposableList)) err := update.Update(ctx, &disposable.DisposableList) if err != nil { log.Printf("Update failed: %v\n", err) } else { fmt.Printf("Domains after update: %d\n", len(disposable.DisposableList)) } // Thread-safe update with mutex for concurrent applications var mu sync.RWMutex // Background update goroutine go func() { updateCtx, updateCancel := context.WithTimeout(context.Background(), 120*time.Second) defer updateCancel() if err := update.Update(updateCtx, &disposable.DisposableList, &mu); err != nil { log.Printf("Background update failed: %v\n", err) } }() // Safe read while update may be in progress mu.RLock() _, isDisposable := disposable.DisposableList["tempmail.com"] mu.RUnlock() fmt.Printf("tempmail.com is disposable: %v\n", isDisposable) } ``` -------------------------------- ### Parse and Validate Email Addresses (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Parses and validates an email address, normalizing it and checking against a list of disposable domains. Handles Gmail quirks like dot removal and plus-addressing. Returns detailed email components and a boolean indicating if the domain is disposable. Supports an optional case-sensitive mode. ```go package main import ( "fmt" "log" disposable "github.com/rocketlaunchr/anti-disposable-email" ) func main() { // Parse a regular Gmail address with dots and plus addressing result, err := disposable.ParseEmail("John.Smith+newsletter@gmail.com") if err != nil { log.Fatal(err) } fmt.Printf("Email: %s\n", result.Email) // John.Smith+newsletter@gmail.com fmt.Printf("LocalPart: %s\n", result.LocalPart) // John.Smith+newsletter fmt.Printf("Preferred: %s\n", result.Preferred) // John.Smith fmt.Printf("Normalized: %s\n", result.Normalized) // johnsmith (dots removed, lowercased) fmt.Printf("Extra: %s\n", result.Extra) // newsletter (plus-addressed portion) fmt.Printf("Domain: %s\n", result.Domain) // gmail.com fmt.Printf("Disposable: %v\n", result.Disposable) // false // Check a disposable email address disposableResult, err := disposable.ParseEmail("user@10minutemail.com") if err != nil { log.Fatal(err) } fmt.Printf("\nDisposable check: %v\n", disposableResult.Disposable) // true // Case-sensitive mode (second parameter) caseSensitiveResult, err := disposable.ParseEmail("User@Example.com", true) if err != nil { log.Fatal(err) } fmt.Printf("\nCase-sensitive normalized: %s\n", caseSensitiveResult.Normalized) // User } ``` -------------------------------- ### Parse Email Address and Access Components (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Parses an email address into its constituent parts, including normalized forms for duplicate detection and a disposable status flag. The `ParsedEmail` struct holds all parsed components. Useful for API responses and database unique constraints. ```go package main import ( "encoding/json" "fmt" "log" disposable "github.com/rocketlaunchr/anti-disposable-email" ) func main() { // Parse email and access all struct fields parsed, err := disposable.ParseEmail("Test.User+promo@Gmail.Com") if err != nil { log.Fatal(err) } // ParsedEmail struct fields: // - Email: original input (trimmed) // - LocalPart: part before @ // - Preferred: local part with plus-suffix removed (user's preferred format) // - Normalized: fully normalized for duplicate detection // - Extra: content after + in local part (Gmail) // - Domain: lowercase domain // - Disposable: true if from disposable service // Serialize to JSON for API responses jsonData, _ := json.MarshalIndent(parsed, "", " ") fmt.Println(string(jsonData)) // Use Normalized for database unique constraint fmt.Printf("\nStore as unique key: %s@%s\n", parsed.Normalized, parsed.Domain) } ``` -------------------------------- ### Validate Email Domain Format (Go) Source: https://context7.com/rocketlaunchr/anti-disposable-email/llms.txt Validates the format and characters of an email domain. Ensures the domain is lowercase, trimmed, and adheres to standard domain naming conventions, including support for punycode-converted internationalized domain names. Returns true for valid domains and false otherwise. ```go package main import ( "fmt" disposable "github.com/rocketlaunchr/anti-disposable-email" ) func main() { // Valid domains fmt.Println(disposable.ValidateDomain("gmail.com")) // true fmt.Println(disposable.ValidateDomain("sub.domain.co.uk")) // true fmt.Println(disposable.ValidateDomain("my-company.io")) // true // Invalid domains fmt.Println(disposable.ValidateDomain("")) // false (empty) fmt.Println(disposable.ValidateDomain(".gmail.com")) // false (starts with dot) fmt.Println(disposable.ValidateDomain("gmail.com-")) // false (ends with dash) fmt.Println(disposable.ValidateDomain("domain.c")) // false (TLD too short) fmt.Println(disposable.ValidateDomain("invalid domain")) // false (contains space) } ``` -------------------------------- ### Import Anti Disposable Email Package Source: https://github.com/rocketlaunchr/anti-disposable-email/blob/master/README.md Imports the anti-disposable-email package into your Go program. This allows you to use its functionalities. ```go import "github.com/rocketlaunchr/anti-disposable-email" ``` -------------------------------- ### Update Disposable Domain List in Go Source: https://github.com/rocketlaunchr/anti-disposable-email/blob/master/README.md Updates the disposable domain list used by the package. This ensures the checker has the latest information on disposable email services. It requires a context and the disposable list to be updated. ```go import "github.com/rocketlaunchr/anti-disposable-email" import "github.com/rocketlaunchr/anti-disposable-email/update" update.Update(ctx, &disposable.DisposableList) ``` -------------------------------- ### Parse Email Address with Go Source: https://github.com/rocketlaunchr/anti-disposable-email/blob/master/README.md Parses an email address using the anti-disposable-email package. It returns a ParsedEmail struct containing details about the email, including whether it's from a disposable domain. ```go import "github.com/rocketlaunchr/anti-disposable-email" ParsedEmail, _ := disposable.ParseEmail("rocketlaunchr.cloud@gmail.com") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.