groupware: add threadCount to /groupware/accounts/{accountId}/mailboxes/{mailboxId}/emails

This commit is contained in:
Pascal Bleser
2025-10-23 14:06:52 +02:00
parent 81cec702f3
commit 5d1709f439
2 changed files with 28 additions and 5 deletions

View File

@@ -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,

View File

@@ -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)
}