commit 861fc513c8968adc6aac3ab85377d3e6b9054705 from: Oliver Lowe date: Tue Apr 12 06:54:55 2022 UTC wip commit - 8d82f4f7bef520ae81a9e5f9265e9a65cc060b29 commit + 861fc513c8968adc6aac3ab85377d3e6b9054705 blob - db77054712eef39bc2a689bd2b78b6c4f884d921 blob + cf7c3b7002ca03c91b23889a340c6b387bd92778 --- cmd/mailmux/mailmux.go +++ cmd/mailmux/mailmux.go @@ -177,6 +177,7 @@ func main() { os.Exit(1) } + rand.Seed(time.Now().UnixNano()) srv.seedfile = "/usr/share/dict/words" http.HandleFunc("/register", srv.registerHandler) blob - ac0acf3fb67527493f9e8fcd29421a54ca208098 (mode 644) blob + /dev/null --- main.go +++ /dev/null @@ -1,35 +0,0 @@ -package mailmux - -import ( - "fmt" - "math/rand" - "os" - "time" - - "mailmux.net/aliases" -) - -func init() { - rand.Seed(time.Now().UnixNano()) -} - -const usage string = "usage: randomalias destination" - -func main() { - if len(os.Args) < 2 { - fmt.Println(usage) - os.Exit(1) - } - dest := os.Args[1] - username, err := RandomUsername("/usr/share/dict/words") - if err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } - m := make(aliases.Aliases) - m[username] = dest - if err := aliases.NewEncoder(os.Stdout).Encode(m); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} blob - 267fb4c56be888c434d071a18e64935683b16f2d blob + 7a3c4393c7ed79653bd98da9527be675ab1e44d5 --- random.go +++ random.go @@ -46,6 +46,9 @@ func randomLine(f *os.File) (string, error) { return line, nil } +// RandomUsername generates a random username from the dictionary file at dictpath. +// The dictionary file should be a newline delimited text file, one word per line. +// On Unix systems, the file /usr/share/dic/words is a suitable file. func RandomUsername(dictpath string) (string, error) { f, err := os.Open(dictpath) if err != nil {