gomail/main.go
Michael b14b816097 minor changes and fixes
Signed-off-by: Michael <michael.lindman@gmail.com>
2021-07-03 01:08:46 +01:00

45 lines
994 B
Go

package main
import (
"flag"
"fmt"
"os"
"git.0cd.xyz/michael/gomail/mail"
"git.0cd.xyz/michael/gtools/logger"
)
func main() {
cfgFile, mailbox, msgs := ui()
cfg := NewConfig(*cfgFile)
logger := logger.New(cfg.Logger.Path, cfg.Logger.Mode, cfg.Logger.Level)
conn, err := mail.Login(cfg.Addr, cfg.Username, cfg.Password)
if err != nil {
logger.Error.Fatal(err)
}
defer conn.Client.Logout()
messages, err := conn.GetMessages(*mailbox, int32(*msgs))
if err != nil {
logger.Error.Fatal(err)
}
if err := mail.WriteMessages(messages); err != nil {
logger.Error.Fatal(err)
}
}
func ui() (cfgFile, mailbox *string, msgs *int) {
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
cfgFile = flag.String("cfgFile", "./config.yaml", "path to config file")
mailbox = flag.String("mailbox", "inbox", "mailbox to scan messages")
msgs = flag.Int("msgs", 100, "Number of messages to pull")
flag.Parse()
return cfgFile, mailbox, msgs
}