package main import ( "log" "mime" "github.com/emersion/go-imap/v2/imapclient" "github.com/emersion/go-message/charset" ) type MailBox struct { Server string User string Password string Client *imapclient.Client } func (mb *MailBox) ListMessages() (string, error) { return "", nil } func (mb *MailBox) Connect() error { options := &imapclient.Options{ WordDecoder: &mime.WordDecoder{CharsetReader: charset.Reader}, } var err error mb.Client, err = imapclient.DialTLS(mb.Server, options) if err != nil { log.Println("Error connnecting to", mb.Server, ":", err) return err } log.Println("Connected") err = mb.Client.Login(mb.User, mb.Password).Wait() if err != nil { log.Fatal("failed to login:", err) } log.Println("Logged in") return nil } func (mb *MailBox) Close() { mb.Client.Close() }