This repository has been archived on 2023-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
Files
2022-12-16 19:45:01 -08:00

49 lines
926 B
Go

package commands
import (
"errors"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/utf7"
)
// A MOVE command.
// See RFC 6851 section 3.1.
type Move struct {
SeqSet *imap.SeqSet
Mailbox string
}
func (cmd *Move) Command() *imap.Command {
mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox)
return &imap.Command{
Name: "MOVE",
Arguments: []interface{}{cmd.SeqSet, mailbox},
}
}
func (cmd *Move) Parse(fields []interface{}) (err error) {
if len(fields) < 2 {
return errors.New("No enough arguments")
}
seqset, ok := fields[0].(string)
if !ok {
return errors.New("Invalid sequence set")
}
if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil {
return err
}
mailbox, ok := fields[1].(string)
if !ok {
return errors.New("Mailbox name must be a string")
}
if cmd.Mailbox, err = utf7.Encoding.NewDecoder().String(mailbox); err != nil {
return err
}
return
}