From 40c3ea65ffc2f82246b258a4e615a63fe6ba3aa4 Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Thu, 30 Oct 2025 14:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E5=BA=8F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Common/EmailLogService.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs index 8f89bfa33..33b4c0984 100644 --- a/IRaCIS.Core.Application/Service/Common/EmailLogService.cs +++ b/IRaCIS.Core.Application/Service/Common/EmailLogService.cs @@ -16,6 +16,7 @@ using MailKit.Security; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using MimeKit; +using System.Linq; using System.Net.Mail; using System.Threading.Tasks; namespace IRaCIS.Core.Application.Service; @@ -73,15 +74,16 @@ public class EmailLogService(IRepository _emailLogRepository, //var uids = sentFolder.Sort(searchQuery, orderBy).Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToList(); - var uids = sentFolder.Search(searchQuery).Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToList(); + pageOutput.TotalCount = sentFolder.Search(searchQuery).Count(); + + // 在内存中分页倒序 + + var uids = sentFolder.Search(searchQuery).Skip(CalcReverseSkip(inQuery.PageIndex, inQuery.PageSize, (int)pageOutput.TotalCount)).Take(inQuery.PageSize).ToList(); + uids.Reverse(); // 获取邮件并排序(按时间倒序) var emailList = GetEmailsWithSorting(sentFolder, uids); - // 应用内存中的过滤条件(对于无法通过IMAP搜索的条件) - //var filteredEmails = ApplyMemoryFilters(emailList, inQuery); - - pageOutput.TotalCount = sentFolder.Search(searchQuery).Count(); pageOutput.PageIndex = inQuery.PageIndex; pageOutput.PageSize = inQuery.PageSize; @@ -115,10 +117,15 @@ public class EmailLogService(IRepository _emailLogRepository, return pageOutput; + } + // 取skip的值 + public int CalcReverseSkip(int pageIndex, int pageSize, int totalCount) + { - - + int lastPageFullSkip = totalCount / pageSize * pageSize; // 最后一页“整页”起点 + int skip = lastPageFullSkip - pageIndex * pageSize; // 倒着减 + return Math.Max(skip, 0); // 防止负值 } ///