Skip to content

Commit

Permalink
Simulate cooldown in dry-run
Browse files Browse the repository at this point in the history
Signed-off-by: Olaf Lessenich <[email protected]>
  • Loading branch information
xai committed Mar 21, 2022
1 parent 22a298b commit 5239b5f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const Name = "xmailgun"
const Version = "1.0.5"
const Version = "1.0.6"
const UserAgent string = Name + "/" + Version

type Config struct {
Expand Down Expand Up @@ -584,24 +584,28 @@ func main() {

sendMail(config, mails[i], outputFile, dryRun)
if dryRun {
fmt.Printf("> %d of %d mails NOT sent (dry-run)", i+1, len(mails))
fmt.Printf("> mail %d of %d NOT sent (dry-run)", i+1, len(mails))
} else {
fmt.Printf("> %d of %d mails sent", i+1, len(mails))
fmt.Printf("> mail %d of %d sent", i+1, len(mails))
}
if len(mails[i].To) == 1 {
fmt.Printf(" to %s", mails[i].To[0])
}
fmt.Print("\n")

// recovery phase to prevent triggering spam detection of smtp server
if !dryRun && (i+1)%cooldown == 0 {
if (i+1) < len(mails) && (i+1)%cooldown == 0 {
fmt.Printf(
"\nAutomatic cooldown for %d minutes to let smtp server recover.\n\n",
cooldown,
)
for i := cooldown; i >= 0; i-- {
fmt.Printf("\033[2K\rRemaining in recovery phase for %d minutes", i)
time.Sleep(1 * time.Minute)
if !dryRun {
for i := cooldown; i >= 0; i-- {
fmt.Printf("\033[2K\rRemaining in recovery phase for %d minutes", i)
time.Sleep(1 * time.Minute)
}
} else {
fmt.Printf("dry-run: cooldown skipped")
}

fmt.Print("\n\n")
Expand Down

0 comments on commit 5239b5f

Please sign in to comment.