mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-11 06:29:15 -06:00
feat(groupware): add fetching all mailboxes for all accounts
* add URL to retrieve all the mailboxes for all the accounts of a user, as a first use-case for an all-accounts operation, as /accounts/all/mailboxes * add URL to retrieve mailbox changes for all the mailboxes of all the accounts of a user, as a first use-case for an all-accounts operation, as /accounts/all/mailboxes/changes * change the defaultAccountId from '*' to '_', as '*' rather indicates "all" than "default", and we might want to use that for "all accounts" operations in the future * refactor(groupware): remove the accountId parameter from the logger() function, as it is not used anyways, but also confusing for operations that support multiple account ids
This commit is contained in:
@@ -32,7 +32,7 @@ type Emails struct {
|
||||
|
||||
// Retrieve specific Emails by their id.
|
||||
func (j *Client) GetEmails(accountId string, session *Session, ctx context.Context, logger *log.Logger, ids []string, fetchBodies bool, maxBodyValueBytes uint) (Emails, SessionState, Error) {
|
||||
logger = j.logger(accountId, "GetEmails", session, logger)
|
||||
logger = j.logger("GetEmails", session, logger)
|
||||
|
||||
get := EmailGetCommand{AccountId: accountId, Ids: ids, FetchAllBodyValues: fetchBodies}
|
||||
if maxBodyValueBytes > 0 {
|
||||
@@ -57,7 +57,7 @@ func (j *Client) GetEmails(accountId string, session *Session, ctx context.Conte
|
||||
|
||||
// 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, mailboxId string, offset uint, limit uint, fetchBodies bool, maxBodyValueBytes uint) (Emails, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "GetAllEmailsInMailbox", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("GetAllEmailsInMailbox", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies).Uint(logOffset, offset).Uint(logLimit, limit)
|
||||
})
|
||||
|
||||
@@ -119,7 +119,7 @@ func (j *Client) GetAllEmailsInMailbox(accountId string, session *Session, ctx c
|
||||
|
||||
// Get all the Emails that have been created, updated or deleted since a given state.
|
||||
func (j *Client) GetEmailsSince(accountId string, session *Session, ctx context.Context, logger *log.Logger, sinceState string, fetchBodies bool, maxBodyValueBytes uint, maxChanges uint) (MailboxChanges, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "GetEmailsSince", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("GetEmailsSince", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies).Str(logSinceState, sinceState)
|
||||
})
|
||||
|
||||
@@ -199,7 +199,7 @@ type EmailSnippetQueryResult struct {
|
||||
}
|
||||
|
||||
func (j *Client) QueryEmailSnippets(accountId string, filter EmailFilterElement, session *Session, ctx context.Context, logger *log.Logger, offset uint, limit uint) (EmailSnippetQueryResult, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "QueryEmails", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("QueryEmails", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Uint(logLimit, limit).Uint(logOffset, offset)
|
||||
})
|
||||
|
||||
@@ -272,7 +272,7 @@ type EmailQueryResult struct {
|
||||
}
|
||||
|
||||
func (j *Client) QueryEmails(accountId string, filter EmailFilterElement, session *Session, ctx context.Context, logger *log.Logger, offset uint, limit uint, fetchBodies bool, maxBodyValueBytes uint) (EmailQueryResult, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "QueryEmails", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("QueryEmails", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies)
|
||||
})
|
||||
|
||||
@@ -349,7 +349,7 @@ type EmailQueryWithSnippetsResult struct {
|
||||
}
|
||||
|
||||
func (j *Client) QueryEmailsWithSnippets(accountId string, filter EmailFilterElement, session *Session, ctx context.Context, logger *log.Logger, offset uint, limit uint, fetchBodies bool, maxBodyValueBytes uint) (EmailQueryWithSnippetsResult, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "QueryEmailsWithSnippets", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("QueryEmailsWithSnippets", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies)
|
||||
})
|
||||
|
||||
@@ -769,7 +769,7 @@ func (j *Client) SubmitEmail(accountId string, identityId string, emailId string
|
||||
}
|
||||
|
||||
func (j *Client) EmailsInThread(accountId string, threadId string, session *Session, ctx context.Context, logger *log.Logger, fetchBodies bool, maxBodyValueBytes uint) ([]Email, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "EmailsInThread", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("EmailsInThread", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies).Str("threadId", log.SafeString(threadId))
|
||||
})
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ type Identities struct {
|
||||
|
||||
// https://jmap.io/spec-mail.html#identityget
|
||||
func (j *Client) GetIdentity(accountId string, session *Session, ctx context.Context, logger *log.Logger) (Identities, SessionState, Error) {
|
||||
logger = j.logger(accountId, "GetIdentity", session, logger)
|
||||
logger = j.logger("GetIdentity", session, logger)
|
||||
cmd, err := request(invocation(CommandIdentityGet, IdentityGetCommand{AccountId: accountId}, "0"))
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
@@ -44,7 +44,7 @@ type IdentitiesGetResponse struct {
|
||||
func (j *Client) GetIdentities(accountIds []string, session *Session, ctx context.Context, logger *log.Logger) (IdentitiesGetResponse, SessionState, Error) {
|
||||
uniqueAccountIds := structs.Uniq(accountIds)
|
||||
|
||||
logger = j.logger("", "GetIdentities", session, logger)
|
||||
logger = j.logger("GetIdentities", session, logger)
|
||||
|
||||
calls := make([]Invocation, len(uniqueAccountIds))
|
||||
for i, accountId := range uniqueAccountIds {
|
||||
@@ -91,7 +91,7 @@ type IdentitiesAndMailboxesGetResponse struct {
|
||||
func (j *Client) GetIdentitiesAndMailboxes(mailboxAccountId string, accountIds []string, session *Session, ctx context.Context, logger *log.Logger) (IdentitiesAndMailboxesGetResponse, SessionState, Error) {
|
||||
uniqueAccountIds := structs.Uniq(accountIds)
|
||||
|
||||
logger = j.logger("", "GetIdentitiesAndMailboxes", session, logger)
|
||||
logger = j.logger("GetIdentitiesAndMailboxes", session, logger)
|
||||
|
||||
calls := make([]Invocation, len(uniqueAccountIds)+1)
|
||||
calls[0] = invocation(CommandMailboxGet, MailboxGetCommand{AccountId: mailboxAccountId}, "0")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/pkg/log"
|
||||
"github.com/opencloud-eu/opencloud/pkg/structs"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
@@ -14,27 +15,42 @@ type MailboxesResponse struct {
|
||||
}
|
||||
|
||||
// https://jmap.io/spec-mail.html#mailboxget
|
||||
func (j *Client) GetMailbox(accountId string, session *Session, ctx context.Context, logger *log.Logger, ids []string) (MailboxesResponse, SessionState, Error) {
|
||||
logger = j.logger(accountId, "GetMailbox", session, logger)
|
||||
cmd, err := request(invocation(CommandMailboxGet, MailboxGetCommand{AccountId: accountId, Ids: ids}, "0"))
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return MailboxesResponse{}, "", simpleError(err, JmapErrorInvalidJmapRequestPayload)
|
||||
func (j *Client) GetMailbox(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, ids []string) (map[string]MailboxesResponse, SessionState, Error) {
|
||||
logger = j.logger("GetMailbox", session, logger)
|
||||
|
||||
uniqueAccountIds := structs.Uniq(accountIds)
|
||||
if len(uniqueAccountIds) < 1 {
|
||||
return map[string]MailboxesResponse{}, "", nil
|
||||
}
|
||||
|
||||
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, func(body *Response) (MailboxesResponse, Error) {
|
||||
var response MailboxGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandMailboxGet, "0", &response)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return MailboxesResponse{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
invocations := make([]Invocation, len(uniqueAccountIds))
|
||||
for i, accountId := range uniqueAccountIds {
|
||||
invocations[i] = invocation(CommandMailboxGet, MailboxGetCommand{AccountId: accountId, Ids: ids}, accountId)
|
||||
}
|
||||
|
||||
return MailboxesResponse{
|
||||
Mailboxes: response.List,
|
||||
NotFound: response.NotFound,
|
||||
State: response.State,
|
||||
}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
cmd, err := request(invocations...)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxesResponse{}, "", simpleError(err, JmapErrorInvalidJmapRequestPayload)
|
||||
}
|
||||
|
||||
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, func(body *Response) (map[string]MailboxesResponse, Error) {
|
||||
resp := map[string]MailboxesResponse{}
|
||||
for _, accountId := range uniqueAccountIds {
|
||||
var response MailboxGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandMailboxGet, "0", &response)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxesResponse{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
|
||||
resp[accountId] = MailboxesResponse{
|
||||
Mailboxes: response.List,
|
||||
NotFound: response.NotFound,
|
||||
State: response.State,
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -43,15 +59,21 @@ type AllMailboxesResponse struct {
|
||||
State State `json:"state"`
|
||||
}
|
||||
|
||||
func (j *Client) GetAllMailboxes(accountId string, session *Session, ctx context.Context, logger *log.Logger) (AllMailboxesResponse, SessionState, Error) {
|
||||
resp, sessionState, err := j.GetMailbox(accountId, session, ctx, logger, nil)
|
||||
func (j *Client) GetAllMailboxes(accountIds []string, session *Session, ctx context.Context, logger *log.Logger) (map[string]AllMailboxesResponse, SessionState, Error) {
|
||||
resp, sessionState, err := j.GetMailbox(accountIds, session, ctx, logger, nil)
|
||||
if err != nil {
|
||||
return AllMailboxesResponse{}, sessionState, err
|
||||
return map[string]AllMailboxesResponse{}, sessionState, err
|
||||
}
|
||||
return AllMailboxesResponse{
|
||||
Mailboxes: resp.Mailboxes,
|
||||
State: resp.State,
|
||||
}, sessionState, nil
|
||||
|
||||
mapped := make(map[string]AllMailboxesResponse, len(resp))
|
||||
for accountId, mailboxesResponse := range resp {
|
||||
mapped[accountId] = AllMailboxesResponse{
|
||||
Mailboxes: mailboxesResponse.Mailboxes,
|
||||
State: mailboxesResponse.State,
|
||||
}
|
||||
}
|
||||
|
||||
return mapped, sessionState, nil
|
||||
}
|
||||
|
||||
type Mailboxes struct {
|
||||
@@ -61,29 +83,41 @@ type Mailboxes struct {
|
||||
State State `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
func (j *Client) SearchMailboxes(accountId string, session *Session, ctx context.Context, logger *log.Logger, filter MailboxFilterElement) (Mailboxes, SessionState, Error) {
|
||||
logger = j.logger(accountId, "SearchMailboxes", session, logger)
|
||||
func (j *Client) SearchMailboxes(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, filter MailboxFilterElement) (map[string]Mailboxes, SessionState, Error) {
|
||||
logger = j.logger("SearchMailboxes", session, logger)
|
||||
|
||||
cmd, err := request(
|
||||
invocation(CommandMailboxQuery, MailboxQueryCommand{AccountId: accountId, Filter: filter}, "0"),
|
||||
invocation(CommandMailboxGet, MailboxGetRefCommand{
|
||||
uniqueAccountIds := structs.Uniq(accountIds)
|
||||
|
||||
invocations := make([]Invocation, len(uniqueAccountIds)*2)
|
||||
for i, accountId := range uniqueAccountIds {
|
||||
baseId := accountId + ":"
|
||||
invocations[i*2+0] = invocation(CommandMailboxQuery, MailboxQueryCommand{AccountId: accountId, Filter: filter}, baseId+"0")
|
||||
invocations[i*2+1] = invocation(CommandMailboxGet, MailboxGetRefCommand{
|
||||
AccountId: accountId,
|
||||
IdRef: &ResultReference{Name: CommandMailboxQuery, Path: "/ids/*", ResultOf: "0"},
|
||||
}, "1"),
|
||||
)
|
||||
IdRef: &ResultReference{Name: CommandMailboxQuery, Path: "/ids/*", ResultOf: baseId + "0"},
|
||||
}, baseId+"1")
|
||||
}
|
||||
cmd, err := request(invocations...)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return Mailboxes{}, "", simpleError(err, JmapErrorInvalidJmapRequestPayload)
|
||||
return map[string]Mailboxes{}, "", simpleError(err, JmapErrorInvalidJmapRequestPayload)
|
||||
}
|
||||
|
||||
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, func(body *Response) (Mailboxes, Error) {
|
||||
var response MailboxGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandMailboxGet, "1", &response)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return Mailboxes{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, func(body *Response) (map[string]Mailboxes, Error) {
|
||||
resp := map[string]Mailboxes{}
|
||||
for _, accountId := range uniqueAccountIds {
|
||||
baseId := accountId + ":"
|
||||
|
||||
var response MailboxGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandMailboxGet, baseId+"1", &response)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]Mailboxes{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
|
||||
resp[accountId] = Mailboxes{Mailboxes: response.List, State: response.State}
|
||||
}
|
||||
return Mailboxes{Mailboxes: response.List, State: response.State}, nil
|
||||
return resp, nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,7 +132,7 @@ type MailboxChanges struct {
|
||||
|
||||
// Retrieve Email changes in a given Mailbox since a given state.
|
||||
func (j *Client) GetMailboxChanges(accountId string, session *Session, ctx context.Context, logger *log.Logger, mailboxId string, sinceState string, fetchBodies bool, maxBodyValueBytes uint, maxChanges uint) (MailboxChanges, SessionState, Error) {
|
||||
logger = j.loggerParams(accountId, "GetMailboxChanges", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
logger = j.loggerParams("GetMailboxChanges", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
return z.Bool(logFetchBodies, fetchBodies).Str(logSinceState, sinceState)
|
||||
})
|
||||
|
||||
@@ -169,3 +203,104 @@ func (j *Client) GetMailboxChanges(accountId string, session *Session, ctx conte
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
||||
// Retrieve Email changes in Mailboxes of multiple Accounts.
|
||||
func (j *Client) GetMailboxChangesForMultipleAccounts(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, sinceStateMap map[string]string, fetchBodies bool, maxBodyValueBytes uint, maxChanges uint) (map[string]MailboxChanges, SessionState, Error) {
|
||||
logger = j.loggerParams("GetMailboxChangesForMultipleAccounts", session, logger, func(z zerolog.Context) zerolog.Context {
|
||||
sinceStateLogDict := zerolog.Dict()
|
||||
for k, v := range sinceStateMap {
|
||||
sinceStateLogDict.Str(log.SafeString(k), log.SafeString(v))
|
||||
}
|
||||
return z.Bool(logFetchBodies, fetchBodies).Dict(logSinceState, sinceStateLogDict)
|
||||
})
|
||||
|
||||
uniqueAccountIds := structs.Uniq(accountIds)
|
||||
n := len(uniqueAccountIds)
|
||||
if n < 1 {
|
||||
return map[string]MailboxChanges{}, "", nil
|
||||
}
|
||||
|
||||
invocations := make([]Invocation, n*3)
|
||||
for i, accountId := range uniqueAccountIds {
|
||||
changes := MailboxChangesCommand{
|
||||
AccountId: accountId,
|
||||
}
|
||||
|
||||
sinceState, ok := sinceStateMap[accountId]
|
||||
if ok {
|
||||
changes.SinceState = sinceState
|
||||
}
|
||||
|
||||
if maxChanges > 0 {
|
||||
changes.MaxChanges = maxChanges
|
||||
}
|
||||
|
||||
baseId := accountId + ":"
|
||||
|
||||
getCreated := EmailGetRefCommand{
|
||||
AccountId: accountId,
|
||||
FetchAllBodyValues: fetchBodies,
|
||||
IdRef: &ResultReference{Name: CommandMailboxChanges, Path: "/created", ResultOf: baseId + "0"},
|
||||
}
|
||||
if maxBodyValueBytes > 0 {
|
||||
getCreated.MaxBodyValueBytes = maxBodyValueBytes
|
||||
}
|
||||
getUpdated := EmailGetRefCommand{
|
||||
AccountId: accountId,
|
||||
FetchAllBodyValues: fetchBodies,
|
||||
IdRef: &ResultReference{Name: CommandMailboxChanges, Path: "/updated", ResultOf: baseId + "0"},
|
||||
}
|
||||
if maxBodyValueBytes > 0 {
|
||||
getUpdated.MaxBodyValueBytes = maxBodyValueBytes
|
||||
}
|
||||
|
||||
invocations[i*3+0] = invocation(CommandMailboxChanges, changes, baseId+"0")
|
||||
invocations[i*3+1] = invocation(CommandEmailGet, getCreated, baseId+"1")
|
||||
invocations[i*3+2] = invocation(CommandEmailGet, getUpdated, baseId+"2")
|
||||
}
|
||||
|
||||
cmd, err := request(invocations...)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxChanges{}, "", simpleError(err, JmapErrorInvalidJmapRequestPayload)
|
||||
}
|
||||
|
||||
return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, func(body *Response) (map[string]MailboxChanges, Error) {
|
||||
resp := make(map[string]MailboxChanges, n)
|
||||
for _, accountId := range uniqueAccountIds {
|
||||
baseId := accountId + ":"
|
||||
|
||||
var mailboxResponse MailboxChangesResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandMailboxChanges, baseId+"0", &mailboxResponse)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxChanges{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
|
||||
var createdResponse EmailGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandEmailGet, baseId+"1", &createdResponse)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxChanges{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
|
||||
var updatedResponse EmailGetResponse
|
||||
err = retrieveResponseMatchParameters(body, CommandEmailGet, baseId+"2", &updatedResponse)
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
return map[string]MailboxChanges{}, simpleError(err, JmapErrorInvalidJmapResponsePayload)
|
||||
}
|
||||
|
||||
resp[accountId] = MailboxChanges{
|
||||
Destroyed: mailboxResponse.Destroyed,
|
||||
HasMoreChanges: mailboxResponse.HasMoreChanges,
|
||||
NewState: mailboxResponse.NewState,
|
||||
Created: createdResponse.List,
|
||||
Updated: createdResponse.List,
|
||||
State: createdResponse.State,
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ const (
|
||||
|
||||
// https://jmap.io/spec-mail.html#vacationresponseget
|
||||
func (j *Client) GetVacationResponse(accountId string, session *Session, ctx context.Context, logger *log.Logger) (VacationResponseGetResponse, SessionState, Error) {
|
||||
logger = j.logger(accountId, "GetVacationResponse", session, logger)
|
||||
logger = j.logger("GetVacationResponse", session, logger)
|
||||
cmd, err := request(invocation(CommandVacationResponseGet, VacationResponseGetCommand{AccountId: accountId}, "0"))
|
||||
if err != nil {
|
||||
logger.Error().Err(err)
|
||||
@@ -61,7 +61,7 @@ type VacationResponseChange struct {
|
||||
}
|
||||
|
||||
func (j *Client) SetVacationResponse(accountId string, vacation VacationResponsePayload, session *Session, ctx context.Context, logger *log.Logger) (VacationResponseChange, SessionState, Error) {
|
||||
logger = j.logger(accountId, "SetVacationResponse", session, logger)
|
||||
logger = j.logger("SetVacationResponse", session, logger)
|
||||
|
||||
cmd, err := request(
|
||||
invocation(CommandVacationResponseSet, VacationResponseSetCommand{
|
||||
|
||||
@@ -50,14 +50,12 @@ func (j *Client) FetchSession(sessionUrl *url.URL, username string, logger *log.
|
||||
return newSession(wk)
|
||||
}
|
||||
|
||||
func (j *Client) logger(accountId string, operation string, _ *Session, logger *log.Logger) *log.Logger {
|
||||
var _ string = accountId
|
||||
func (j *Client) logger(operation string, _ *Session, logger *log.Logger) *log.Logger {
|
||||
l := logger.With().Str(logOperation, operation)
|
||||
return log.From(l)
|
||||
}
|
||||
|
||||
func (j *Client) loggerParams(accountId string, operation string, _ *Session, logger *log.Logger, params func(zerolog.Context) zerolog.Context) *log.Logger {
|
||||
var _ string = accountId
|
||||
func (j *Client) loggerParams(operation string, _ *Session, logger *log.Logger, params func(zerolog.Context) zerolog.Context) *log.Logger {
|
||||
l := logger.With().Str(logOperation, operation)
|
||||
if params != nil {
|
||||
l = params(l)
|
||||
|
||||
@@ -354,9 +354,13 @@ func TestWithStalwart(t *testing.T) {
|
||||
var inboxFolder string
|
||||
var inboxId string
|
||||
{
|
||||
resp, sessionState, err := j.GetAllMailboxes(accountId, session, ctx, logger)
|
||||
respByAccountId, sessionState, err := j.GetAllMailboxes([]string{accountId}, session, ctx, logger)
|
||||
require.NoError(err)
|
||||
require.Equal(session.State, sessionState)
|
||||
require.Len(respByAccountId, 1)
|
||||
require.Contains(respByAccountId, accountId)
|
||||
resp := respByAccountId[accountId]
|
||||
|
||||
mailboxesNameByRole := map[string]string{}
|
||||
mailboxesUnreadByRole := map[string]int{}
|
||||
for _, m := range resp.Mailboxes {
|
||||
@@ -436,9 +440,12 @@ func TestWithStalwart(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
resp, sessionState, err := j.GetAllMailboxes(accountId, session, ctx, logger)
|
||||
respByAccountId, sessionState, err := j.GetAllMailboxes([]string{accountId}, session, ctx, logger)
|
||||
require.NoError(err)
|
||||
require.Equal(session.State, sessionState)
|
||||
require.Len(respByAccountId, 1)
|
||||
require.Contains(respByAccountId, accountId)
|
||||
resp := respByAccountId[accountId]
|
||||
mailboxesUnreadByRole := map[string]int{}
|
||||
for _, m := range resp.Mailboxes {
|
||||
if m.Role != "" {
|
||||
|
||||
@@ -151,8 +151,11 @@ func TestRequests(t *testing.T) {
|
||||
|
||||
session := Session{Username: "user123", JmapUrl: *jmapUrl}
|
||||
|
||||
folders, sessionState, err := client.GetAllMailboxes("a", &session, ctx, &logger)
|
||||
foldersByAccountId, sessionState, err := client.GetAllMailboxes([]string{"a"}, &session, ctx, &logger)
|
||||
require.NoError(err)
|
||||
require.Len(foldersByAccountId, 1)
|
||||
require.Contains(foldersByAccountId, "a")
|
||||
folders := foldersByAccountId["a"]
|
||||
require.Len(folders.Mailboxes, 5)
|
||||
require.NotEmpty(sessionState)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user