diff --git a/config.go b/config.go index 2681a79..91f7061 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,7 @@ type Config struct { Addr string `yaml:"addr"` Path string `yaml:"path"` Account []struct { + Addr string `yaml:"addr"` Username string `yaml:"username"` Password string `yaml:"password"` } diff --git a/main.go b/main.go index 23c43e7..92e4db4 100644 --- a/main.go +++ b/main.go @@ -17,11 +17,11 @@ func main() { logger := logger.New(cfg.Logger.Path, cfg.Logger.Mode, cfg.Logger.Level) chErr, chDone := make(chan error), make(chan bool) for _, account := range cfg.Account { - go func(username, password string, chErr chan<- error, chDone chan<- bool) { + go func(addr, username, password string, chErr chan<- error, chDone chan<- bool) { defer func() { chDone <- true }() - conn, err := mail.Login(cfg.Addr, username, password) + conn, err := mail.Login(addr, username, password) if err != nil { chErr <- err } @@ -39,7 +39,7 @@ func main() { if err := mail.WriteMessages(path, messages); err != nil { chErr <- err } - }(account.Username, account.Password, chErr, chDone) + }(account.Addr, account.Username, account.Password, chErr, chDone) } for c := 0; c < len(cfg.Account); { select { @@ -56,9 +56,9 @@ func ui() (cfgFile, mailbox *string, msgs *int) { fmt.Printf("Usage of %s:\n", os.Args[0]) flag.PrintDefaults() } - home, ok := os.LookupEnv("HOME") - if !ok { - log.Fatal("Unable to find home directory") + home, err := os.UserHomeDir() + if err != nil { + log.Fatal(err) } cfgFile = flag.String("cfgFile", home+"/.config/gomail/config.yaml", "path to config file") mailbox = flag.String("mailbox", "inbox", "mailbox to scan messages")