Skip to content

Instantly share code, notes, and snippets.

@u1aryz
Last active November 23, 2019 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1aryz/f7fb7d28a994c2d2db228d61fddf51dd to your computer and use it in GitHub Desktop.
Save u1aryz/f7fb7d28a994c2d2db228d61fddf51dd to your computer and use it in GitHub Desktop.
Print dot alias all pattern of gmail(G Suite).
package main
import (
"flag"
"fmt"
"math"
"os"
"strings"
)
var (
email = flag.String("email", "", "Set email")
)
func main() {
flag.Parse()
if len(*email) == 0 {
// Require --email option
fmt.Println("Error: args <email> is required.")
os.Exit(1)
}
// Split into username and domain
split := strings.Split(*email, "@")
user := split[0]
user = strings.Replace(user, ".", "", -1)
domain := ""
if len(split) > 1 {
// Domain exists
domain = split[1]
}
n := len(user) - 1
// Number of patterns
patternCnt := int(math.Pow(2, float64(n)))
for i := 0; i < patternCnt; i++ {
alias := ""
for j, v := range user {
alias += string(v)
if (i >> j & 1) == 1 {
alias += "."
}
}
if len(domain) > 0 {
// Put domain if exists
alias += "@" + domain
}
fmt.Println(alias)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment