From 5d1709f4391da0b35f8f3dcd601e15313eb87ea2 Mon Sep 17 00:00:00 2001
From: Pascal Bleser
Date: Thu, 23 Oct 2025 14:06:52 +0200
Subject: [PATCH] groupware: add threadCount to
/groupware/accounts/{accountId}/mailboxes/{mailboxId}/emails
---
pkg/jmap/jmap_api_email.go | 31 ++++++++++++++++---
.../pkg/groupware/groupware_api_emails.go | 2 +-
2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/pkg/jmap/jmap_api_email.go b/pkg/jmap/jmap_api_email.go
index 48a731dee..208c785e1 100644
--- a/pkg/jmap/jmap_api_email.go
+++ b/pkg/jmap/jmap_api_email.go
@@ -108,7 +108,7 @@ func (j *Client) GetEmailBlobId(accountId string, session *Session, ctx context.
}
// Retrieve all the Emails in a given Mailbox by its id.
-func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx context.Context, logger *log.Logger, acceptLanguage string, mailboxId string, offset uint, limit uint, collapseThreads bool, fetchBodies bool, maxBodyValueBytes uint) (Emails, SessionState, Language, Error) {
+func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx context.Context, logger *log.Logger, acceptLanguage string, mailboxId string, offset uint, limit uint, collapseThreads bool, fetchBodies bool, maxBodyValueBytes uint, withThreads bool) (Emails, SessionState, Language, Error) {
logger = j.loggerParams("GetAllEmailsInMailbox", session, logger, func(z zerolog.Context) zerolog.Context {
return z.Bool(logFetchBodies, fetchBodies).Uint(logOffset, offset).Uint(logLimit, limit)
})
@@ -117,7 +117,7 @@ func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx c
AccountId: accountId,
Filter: &EmailFilterCondition{InMailbox: mailboxId},
Sort: []EmailComparator{{Property: EmailPropertyReceivedAt, IsAscending: false}},
- CollapseThreads: collapseThreads,
+ CollapseThreads: false,
CalculateTotal: true,
}
if offset > 0 {
@@ -136,10 +136,24 @@ func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx c
get.MaxBodyValueBytes = maxBodyValueBytes
}
- cmd, err := j.request(session, logger,
+ invocations := []Invocation{
invocation(CommandEmailQuery, query, "0"),
invocation(CommandEmailGet, get, "1"),
- )
+ }
+
+ if withThreads {
+ threads := ThreadGetRefCommand{
+ AccountId: accountId,
+ IdsRef: &ResultReference{
+ ResultOf: "1",
+ Name: CommandEmailGet,
+ Path: "/list/*/" + EmailPropertyThreadId,
+ },
+ }
+ invocations = append(invocations, invocation(CommandThreadGet, threads, "2"))
+ }
+
+ cmd, err := j.request(session, logger, invocations...)
if err != nil {
return Emails{}, "", "", err
}
@@ -157,6 +171,15 @@ func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx c
return Emails{}, err
}
+ if withThreads {
+ var thread ThreadGetResponse
+ err = retrieveResponseMatchParameters(logger, body, CommandThreadGet, "2", &thread)
+ if err != nil {
+ return Emails{}, err
+ }
+ setThreadSize(&thread, getResponse.List)
+ }
+
return Emails{
Emails: getResponse.List,
Total: queryResponse.Total,
diff --git a/services/groupware/pkg/groupware/groupware_api_emails.go b/services/groupware/pkg/groupware/groupware_api_emails.go
index 312b3cce7..a1c776be0 100644
--- a/services/groupware/pkg/groupware/groupware_api_emails.go
+++ b/services/groupware/pkg/groupware/groupware_api_emails.go
@@ -116,7 +116,7 @@ func (g *Groupware) GetAllEmailsInMailbox(w http.ResponseWriter, r *http.Request
logger := log.From(l)
- emails, sessionState, lang, jerr := g.jmap.GetAllEmailsInMailbox(accountId, req.session, req.ctx, logger, req.language(), mailboxId, offset, limit, false, true, g.maxBodyValueBytes)
+ emails, sessionState, lang, jerr := g.jmap.GetAllEmailsInMailbox(accountId, req.session, req.ctx, logger, req.language(), mailboxId, offset, limit, false, true, g.maxBodyValueBytes, true)
if jerr != nil {
return req.errorResponseFromJmap(jerr)
}