listMessages() only ever fetched everything then kept the newest
limit (default 50) messages, with no offset parameter and no way for
the client to know how many messages existed beyond what it was
shown - older mail was completely unreachable through the webmail UI.
__imap::listMessages() now takes an offset (counted back from the
newest message) and returns {"total":N,"messages":[...]} instead of
a bare array, so the client can page backward/forward and know when
it has reached either end. __imaplist tag and /email/list both pass
offset through; /email/search is unchanged (search results are not
paginated). email.js tracks currentOffset (reset alongside
currentFolder/currentUid at every existing reset site), and renders
Prev/Next controls next to the unread count showing the current
1-based range and total.
32 lines
1.0 KiB
C++
32 lines
1.0 KiB
C++
#include "__imaplist.h"
|
|
#include "Exception.h"
|
|
#include "__imap.h"
|
|
#include <cstdlib>
|
|
|
|
namespace jet {
|
|
|
|
__imaplist::__imaplist(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
|
|
|
coreutils::MString sessionId = resolveKeyword("sessionid");
|
|
if (!global.imapSessionExists(sessionId))
|
|
throw coreutils::Exception("imap sessionid does not exist.", __FILE__, __LINE__, 502);
|
|
|
|
std::string folder = resolveKeyword("folder").str();
|
|
if (folder.empty())
|
|
folder = "INBOX";
|
|
|
|
std::string limitStr = resolveKeyword("limit").str();
|
|
int limit = limitStr.empty() ? 50 : atoi(limitStr.c_str());
|
|
if (limit <= 0)
|
|
limit = 50;
|
|
|
|
std::string offsetStr = resolveKeyword("offset").str();
|
|
int offset = offsetStr.empty() ? 0 : atoi(offsetStr.c_str());
|
|
if (offset < 0)
|
|
offset = 0;
|
|
|
|
out = global.getImapSession(sessionId)->listMessages(folder, limit, offset);
|
|
}
|
|
|
|
}
|