Skip to content

Commit

Permalink
Add a customizable limit to senders
Browse files Browse the repository at this point in the history
  • Loading branch information
wheelercj committed Feb 10, 2024
1 parent 06f35b2 commit 5075cdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/find_spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func appendIfDisposable(disposableAddresses []string, emailDataList []any) []str

// printAddresses prints all the disposable email addresses and the addresses they
// received emails from. The "from" addresses are sorted alphabetically and
// deduplicated.
// deduplicated. If JSON is not being printed and there are more than a certain number
// of unique senders to one address, the number of senders is printed instead of their
// addresses.
func printAddresses(disposableAddresses []string, toAndFrom map[string][]string) {
if len(disposableAddresses) == 0 {
fmt.Fprint(os.Stderr, "No disposable addresses found in your inbox")
Expand Down Expand Up @@ -173,8 +175,17 @@ func printAddresses(disposableAddresses []string, toAndFrom map[string][]string)
}
for to := range toAndFrom {
fmt.Println(to)
for _, from := range toAndFrom[to] {
fmt.Printf("\t%s\n", from)
froms := toAndFrom[to]
if len(froms) > MaxFrom {
fmt.Printf(
"\tReceived emails from %d unique addresses. Use `-f %d` if you want to see them.\n",
len(froms),
len(froms),
)
} else {
for _, from := range froms {
fmt.Printf("\t%s\n", from)
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var Verbose bool
var ApiSessionUrl string
var Domains string
var MaxFrom int
var PrintJson bool

func runFunc(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -81,6 +82,13 @@ func init() {
"duck.com mozmail.com icloud.com",
"email protection service domains to search for",
)
rootCmd.Flags().IntVarP(
&MaxFrom,
"maxFrom",
"f",
5,
"max unique senders to a disposable email address",
)
rootCmd.Flags().BoolVarP(
&PrintJson,
"json",
Expand Down

0 comments on commit 5075cdc

Please sign in to comment.