package imaputils import ( "bytes" "time" "git.sr.ht/~blallo/papero/config" ) var zeroTime = time.Time{} type PutMessageOpts struct { Debug bool Mailbox string Body *bytes.Buffer Flags []string Time time.Time } func PutMessage(conf *config.AccountData, opts *PutMessageOpts) error { conn := NewConnection(conf) err := conn.Start(opts.Debug) if err != nil { return err } defer conn.Close() return PutMessageInSession(conn, opts) } func PutMessageInSession(conn *IMAPConnection, opts *PutMessageOpts) error { var err error var msgTime time.Time _, err = conn.client.Select(opts.Mailbox, false) if err != nil { return err } if opts.Time == zeroTime { msgTime = time.Now() } else { msgTime = opts.Time } return conn.client.Append(opts.Mailbox, opts.Flags, msgTime, opts.Body) }