aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/emersion/go-imap/commands/fetch.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/emersion/go-imap/commands/fetch.go')
-rw-r--r--vendor/github.com/emersion/go-imap/commands/fetch.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/github.com/emersion/go-imap/commands/fetch.go b/vendor/github.com/emersion/go-imap/commands/fetch.go
new file mode 100644
index 0000000..4eb3ab9
--- /dev/null
+++ b/vendor/github.com/emersion/go-imap/commands/fetch.go
@@ -0,0 +1,63 @@
+package commands
+
+import (
+ "errors"
+ "strings"
+
+ "github.com/emersion/go-imap"
+)
+
+// Fetch is a FETCH command, as defined in RFC 3501 section 6.4.5.
+type Fetch struct {
+ SeqSet *imap.SeqSet
+ Items []imap.FetchItem
+}
+
+func (cmd *Fetch) Command() *imap.Command {
+ // Handle FETCH macros separately as they should not be serialized within parentheses
+ if len(cmd.Items) == 1 && (cmd.Items[0] == imap.FetchAll || cmd.Items[0] == imap.FetchFast || cmd.Items[0] == imap.FetchFull) {
+ return &imap.Command{
+ Name: "FETCH",
+ Arguments: []interface{}{cmd.SeqSet, imap.RawString(cmd.Items[0])},
+ }
+ } else {
+ items := make([]interface{}, len(cmd.Items))
+ for i, item := range cmd.Items {
+ items[i] = imap.RawString(item)
+ }
+
+ return &imap.Command{
+ Name: "FETCH",
+ Arguments: []interface{}{cmd.SeqSet, items},
+ }
+ }
+}
+
+func (cmd *Fetch) Parse(fields []interface{}) error {
+ if len(fields) < 2 {
+ return errors.New("No enough arguments")
+ }
+
+ var err error
+ if seqset, ok := fields[0].(string); !ok {
+ return errors.New("Sequence set must be an atom")
+ } else if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil {
+ return err
+ }
+
+ switch items := fields[1].(type) {
+ case string: // A macro or a single item
+ cmd.Items = imap.FetchItem(strings.ToUpper(items)).Expand()
+ case []interface{}: // A list of items
+ cmd.Items = make([]imap.FetchItem, 0, len(items))
+ for _, v := range items {
+ itemStr, _ := v.(string)
+ item := imap.FetchItem(strings.ToUpper(itemStr))
+ cmd.Items = append(cmd.Items, item.Expand()...)
+ }
+ default:
+ return errors.New("Items must be either a string or a list")
+ }
+
+ return nil
+}