~migadu/alps-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH] plugins/base/imap: use slices package

Silvan Jegen <s.jegen@gmail.com>
Details
Message ID
<20241207095810.15968-1-s.jegen@gmail.com>
DKIM signature
pass
Download raw message
Patch: +9 -13
This saves a few lines of code.

Signed-off-by: Silvan Jegen <s.jegen@gmail.com>
---
 plugins/base/imap.go | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index ec4947d..55ea5cb 100644
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -6,10 +6,9 @@ import (
	"fmt"
	"io"
	"net/url"
	"sort"
	"slices"
	"strconv"
	"strings"
	//"time"

	"github.com/dustin/go-humanize"
	"github.com/emersion/go-imap/v2"
@@ -73,14 +72,15 @@ func listMailboxes(conn *imapclient.Client) ([]MailboxInfo, error) {
		return nil, fmt.Errorf("failed to list mailboxes: %v", err)
	}

	sort.Slice(mailboxes, func(i, j int) bool {
		if mailboxes[i].Mailbox == "INBOX" {
			return true
	slices.SortFunc(mailboxes, func(i, j MailboxInfo) int {
		if i.Mailbox == "INBOX" {
			return 1
		}
		if mailboxes[j].Mailbox == "INBOX" {
			return false
		if j.Mailbox == "INBOX" {
			return -1
		}
		return mailboxes[i].Mailbox < mailboxes[j].Mailbox

		return strings.Compare(i.Mailbox, j.Mailbox)
	})
	return mailboxes, nil
}
@@ -465,11 +465,7 @@ func listMessages(conn *imapclient.Client, mboxName string, page, messagesPerPag
		msgs = append(msgs, IMAPMessage{msg, mboxName})
	}

	// Reverse list of messages
	for i := len(msgs)/2 - 1; i >= 0; i-- {
		opp := len(msgs) - 1 - i
		msgs[i], msgs[opp] = msgs[opp], msgs[i]
	}
	slices.Reverse(msgs)

	return msgs, total, nil
}
-- 
2.47.1
Details
Message ID
<D67CYGM07ELO.SV9UZ7DQLBIM@petersanchez.com>
In-Reply-To
<20241207095810.15968-1-s.jegen@gmail.com> (view parent)
DKIM signature
pass
Download raw message
The slices package was introduced in Go 1.21. If we're going to use this 
package then go.mod needs to be updated as it's currently coded to 1.18.

Peter
Silvan Jegen <s.jegen@gmail.com>
Details
Message ID
<31C3HZZN8WFYO.2SBC52QPH7TWO@homearch.localdomain>
In-Reply-To
<D67CYGM07ELO.SV9UZ7DQLBIM@petersanchez.com> (view parent)
DKIM signature
pass
Download raw message
"Peter Sanchez" <pjs@petersanchez.com> wrote:
> The slices package was introduced in Go 1.21. If we're going to use this 
> package then go.mod needs to be updated as it's currently coded to 1.18.

Yes, that makes sense. I was testing this locally and I assumed that the
compiler would complain if the package is not supported, which it did not.

I didn't realise that I was running go v1.22 or so and that in that case
it wouldn't complain (since go.mod specifies the minimal version).

I will send a new version that updates the minimal golang version
accordingly.
Reply to thread Export thread (mbox)