ability to connect to indepentant mail servers

Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
Michael 2021-08-29 23:11:59 +01:00
parent c5a2892136
commit 172b18f962
2 changed files with 7 additions and 6 deletions

View File

@ -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"`
}

12
main.go
View File

@ -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")