Files
go-imap/commands/store.go
T
fox.cppandSimon Ser 5511b755bd Explicit separation for quoted strings and atoms (#261)
* Rename imap.Atom to imap.RawString

See
https://github.com/emersion/go-imap/issues/242#issuecomment-498757425.

* Don't write string as atom

* all: Use imap.RawString where needed

* Drop imap.Quoted

* Format INBOX name as atom

* server: Don't quote INBOX in LIST and STATUS responses

* Revert StatusRespCode change
2019-06-06 10:44:50 +03:00

51 lines
976 B
Go

package commands
import (
"errors"
"strings"
"github.com/emersion/go-imap"
)
// Store is a STORE command, as defined in RFC 3501 section 6.4.6.
type Store struct {
SeqSet *imap.SeqSet
Item imap.StoreItem
Value interface{}
}
func (cmd *Store) Command() *imap.Command {
return &imap.Command{
Name: "STORE",
Arguments: []interface{}{cmd.SeqSet, imap.RawString(cmd.Item), cmd.Value},
}
}
func (cmd *Store) Parse(fields []interface{}) error {
if len(fields) < 3 {
return errors.New("No enough arguments")
}
seqset, ok := fields[0].(string)
if !ok {
return errors.New("Invalid sequence set")
}
var err error
if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil {
return err
}
if item, ok := fields[1].(string); !ok {
return errors.New("Item name must be a string")
} else {
cmd.Item = imap.StoreItem(strings.ToUpper(item))
}
if len(fields[2:]) == 1 {
cmd.Value = fields[2]
} else {
cmd.Value = fields[2:]
}
return nil
}