修正网页邮件按投递时间排序并补录草稿发送验收
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-10-04 05:09:08 +08:00
1 parent 157da8eadd
commit 61b361a6af
4 files changed
+79 -1

No files matched your search

+6 -1
View File
@@ -105,7 +105,12 @@ func genSQL(ctx *context.Context, count bool, tagInfo dto.SearchTag, keyword str
return sql, sqlParams
}
sql += " order by e.id desc"
if pop3List {
sql += " order by e.id desc"
} else {
// 网页按实际展示的投递时间排序,同一时间用邮件编号稳定分页。
sql += " order by e.send_date desc, e.id desc"
}
if limit < 10000 {
sql += fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, offset)
+55
View File
@@ -2,10 +2,14 @@ package list
import (
"path/filepath"
"strings"
"testing"
"time"
"git.pcux.cn/xuans/Smail/config"
"git.pcux.cn/xuans/Smail/consts"
"git.pcux.cn/xuans/Smail/db"
"git.pcux.cn/xuans/Smail/dto"
"git.pcux.cn/xuans/Smail/models"
"git.pcux.cn/xuans/Smail/utils/context"
)
@@ -23,6 +27,57 @@ func initListTestDB(t *testing.T) {
})
}
func TestWebListOrdersByDisplayedDateAcrossPages(t *testing.T) {
initListTestDB(t)
base := time.Date(2026, 10, 4, 0, 0, 0, 0, time.UTC)
// 旧草稿后发;相同投递时间的邮件必须有稳定次序。
for _, item := range []struct {
id int
hour int
}{
{101, 4},
{102, 2},
{103, 3},
{104, 3},
} {
message := models.Email{
Id: item.id, Type: consts.EmailTypeSend,
SendDate: base.Add(time.Duration(item.hour) * time.Hour),
}
if _, err := db.Instance.Insert(&message); err != nil {
t.Fatal(err)
}
relation := models.UserEmail{UserID: 1, EmailID: item.id, GroupId: models.Sent}
if _, err := db.Instance.Insert(&relation); err != nil {
t.Fatal(err)
}
}
tag := dto.SearchTag{Type: consts.EmailTypeSend, Status: -1, GroupId: models.Sent}
ctx := &context.Context{UserID: 1}
for page, want := range [][]int{{101, 104}, {103, 102}} {
messages, total, err := GetEmailList(ctx, tag, "", false, page*2, 2)
if err != nil {
t.Fatal(err)
}
if total != 4 || len(messages) != len(want) {
t.Fatalf("page %d: total=%d, length=%d", page, total, len(messages))
}
for i, id := range want {
if messages[i].Id != id {
t.Fatalf("page %d item %d: got %d, want %d", page, i, messages[i].Id, id)
}
}
}
query, _ := genSQL(ctx, false, tag, "", true, 0, 2)
if !strings.Contains(query, " order by e.id desc") || strings.Contains(query, "order by e.send_date") {
t.Fatalf("POP3 ordering changed: %s", query)
}
query, _ = genSQL(ctx, true, tag, "", false, 0, 2)
if strings.Contains(query, "order by") {
t.Fatalf("count query should not sort: %s", query)
}
}
func TestGetUEListByUIDUsesFullPath(t *testing.T) {
initListTestDB(t)
first := models.Group{Name: "leaf", UserId: 1, FullPath: "first/leaf"}