diff options
author | 2024-01-10 19:28:56 +0100 | |
---|---|---|
committer | 2024-01-10 19:28:56 +0100 | |
commit | 9104af1fcbdde1c3527e6b6e22a49236e1eda653 (patch) | |
tree | fd0cecfa1ed18916b94698936c0520d094139e9f /plugins | |
parent | ae1d0a873b7dc8bee3669c7639c36f5743335636 (diff) | |
download | alps-9104af1fcbdde1c3527e6b6e22a49236e1eda653.tar.gz alps-9104af1fcbdde1c3527e6b6e22a49236e1eda653.tar.bz2 alps-9104af1fcbdde1c3527e6b6e22a49236e1eda653.zip |
Upgrade go-imap
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/imap.go | 21 | ||||
-rw-r--r-- | plugins/base/routes.go | 15 | ||||
-rw-r--r-- | plugins/base/smtp.go | 3 | ||||
-rw-r--r-- | plugins/base/strconv.go | 12 |
4 files changed, 24 insertions, 27 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go index e9636e3..ec4947d 100644 --- a/plugins/base/imap.go +++ b/plugins/base/imap.go @@ -448,7 +448,8 @@ func listMessages(conn *imapclient.Client, mboxName string, page, messagesPerPag return nil, total, nil } - seqSet := imap.SeqSetRange(uint32(from), uint32(to)) + var seqSet imap.SeqSet + seqSet.AddRange(uint32(from), uint32(to)) options := imap.FetchOptions{ Flags: true, Envelope: true, @@ -486,7 +487,7 @@ func searchMessages(conn *imapclient.Client, mboxName, query string, page, messa if err != nil { return nil, 0, fmt.Errorf("SEARCH failed: %v", err) } - nums = data.AllNums() + nums = data.AllSeqNums() } else { sortOptions := &imapclient.SortOptions{ SearchCriteria: searchCriteria, @@ -541,13 +542,11 @@ func searchMessages(conn *imapclient.Client, mboxName, query string, page, messa return msgs, total, nil } -func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPath []int) (*IMAPMessage, *message.Entity, error) { +func getMessagePart(conn *imapclient.Client, mboxName string, uid imap.UID, partPath []int) (*IMAPMessage, *message.Entity, error) { if err := ensureMailboxSelected(conn, mboxName); err != nil { return nil, nil, err } - seqSet := imap.SeqSetNum(uid) - headerItem := &imap.FetchItemBodySection{ Peek: true, Part: partPath, @@ -577,7 +576,7 @@ func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPa } // TODO: stream attachments - msgs, err := conn.UIDFetch(seqSet, &options).Collect() + msgs, err := conn.Fetch(imap.UIDSetNum(uid), &options).Collect() if err != nil { return nil, nil, fmt.Errorf("failed to fetch message: %v", err) } else if len(msgs) == 0 { @@ -610,13 +609,12 @@ func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPa return &IMAPMessage{msg, mboxName}, part, nil } -func markMessageAnswered(conn *imapclient.Client, mboxName string, uid uint32) error { +func markMessageAnswered(conn *imapclient.Client, mboxName string, uid imap.UID) error { if err := ensureMailboxSelected(conn, mboxName); err != nil { return err } - seqSet := imap.SeqSetNum(uid) - return conn.UIDStore(seqSet, &imap.StoreFlags{ + return conn.Store(imap.UIDSetNum(uid), &imap.StoreFlags{ Op: imap.StoreFlagsAdd, Silent: true, Flags: []imap.Flag{imap.FlagAnswered}, @@ -655,13 +653,12 @@ func appendMessage(c *imapclient.Client, msg *OutgoingMessage, mboxType mailboxT return mbox, nil } -func deleteMessage(conn *imapclient.Client, mboxName string, uid uint32) error { +func deleteMessage(conn *imapclient.Client, mboxName string, uid imap.UID) error { if err := ensureMailboxSelected(conn, mboxName); err != nil { return err } - seqSet := imap.SeqSetNum(uid) - err := conn.UIDStore(seqSet, &imap.StoreFlags{ + err := conn.Store(imap.UIDSetNum(uid), &imap.StoreFlags{ Op: imap.StoreFlagsAdd, Silent: true, Flags: []imap.Flag{imap.FlagDeleted}, diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 8b346a2..482b368 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -514,7 +514,7 @@ type ComposeRenderData struct { type messagePath struct { Mailbox string - Uid uint32 + Uid imap.UID } type composeOptions struct { @@ -674,7 +674,7 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti if saveAsDraft { var ( drafts *MailboxInfo - uid uint32 + uid imap.UID ) err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { drafts, err = appendMessage(c, msg, mailboxDrafts) @@ -700,7 +700,7 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti } if data, err := c.UIDSearch(&criteria, nil).Wait(); err != nil { return err - } else if uids := data.AllNums(); len(uids) != 1 { + } else if uids := data.AllUIDs(); len(uids) != 1 { panic(fmt.Errorf("Duplicate message ID")) } else { uid = uids[0] @@ -1049,8 +1049,7 @@ func handleMove(ctx *alps.Context) error { return err } - seqSet := imap.SeqSetNum(uids...) - if _, err := c.UIDMove(seqSet, to).Wait(); err != nil { + if _, err := c.Move(imap.UIDSetNum(uids...), to).Wait(); err != nil { return fmt.Errorf("failed to move message: %v", err) } @@ -1093,8 +1092,7 @@ func handleDelete(ctx *alps.Context) error { return err } - seqSet := imap.SeqSetNum(uids...) - err := c.UIDStore(seqSet, &imap.StoreFlags{ + err := c.Store(imap.UIDSetNum(uids...), &imap.StoreFlags{ Op: imap.StoreFlagsAdd, Silent: true, Flags: []imap.Flag{imap.FlagDeleted}, @@ -1172,8 +1170,7 @@ func handleSetFlags(ctx *alps.Context) error { return err } - seqSet := imap.SeqSetNum(uids...) - err := c.UIDStore(seqSet, &imap.StoreFlags{ + err := c.Store(imap.UIDSetNum(uids...), &imap.StoreFlags{ Op: op, Silent: true, Flags: l, diff --git a/plugins/base/smtp.go b/plugins/base/smtp.go index 8892cae..bf91c24 100644 --- a/plugins/base/smtp.go +++ b/plugins/base/smtp.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/emersion/go-imap/v2" "github.com/emersion/go-message/mail" "github.com/emersion/go-smtp" ) @@ -56,7 +57,7 @@ func (att *formAttachment) Filename() string { type imapAttachment struct { Mailbox string - Uid uint32 + Uid imap.UID Node *IMAPPartNode Body []byte diff --git a/plugins/base/strconv.go b/plugins/base/strconv.go index b423f13..4266e00 100644 --- a/plugins/base/strconv.go +++ b/plugins/base/strconv.go @@ -5,9 +5,11 @@ import ( "net/url" "strconv" "strings" + + "github.com/emersion/go-imap/v2" ) -func parseUid(s string) (uint32, error) { +func parseUid(s string) (imap.UID, error) { uid, err := strconv.ParseUint(s, 10, 32) if err != nil { return 0, fmt.Errorf("invalid UID: %v", err) @@ -15,10 +17,10 @@ func parseUid(s string) (uint32, error) { if uid == 0 { return 0, fmt.Errorf("UID must be non-zero") } - return uint32(uid), nil + return imap.UID(uid), nil } -func parseMboxAndUid(mboxString, uidString string) (string, uint32, error) { +func parseMboxAndUid(mboxString, uidString string) (string, imap.UID, error) { mboxName, err := url.PathUnescape(mboxString) if err != nil { return "", 0, fmt.Errorf("invalid mailbox name: %v", err) @@ -27,8 +29,8 @@ func parseMboxAndUid(mboxString, uidString string) (string, uint32, error) { return mboxName, uid, err } -func parseUidList(values []string) ([]uint32, error) { - var uids []uint32 +func parseUidList(values []string) ([]imap.UID, error) { + var uids []imap.UID for _, v := range values { uid, err := parseUid(v) if err != nil { |