1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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)
- }
|