diff --git a/pkg/jmap/jmap_api_bootstrap.go b/pkg/jmap/jmap_api_bootstrap.go index 405506ac8..70bb7987f 100644 --- a/pkg/jmap/jmap_api_bootstrap.go +++ b/pkg/jmap/jmap_api_bootstrap.go @@ -15,7 +15,7 @@ type AccountBootstrapResult struct { func (j *Client) GetBootstrap(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, acceptLanguage string) (map[string]AccountBootstrapResult, SessionState, Language, Error) { uniqueAccountIds := structs.Uniq(accountIds) - logger = j.logger("GetIdentities", session, logger) + logger = j.logger("GetBootstrap", session, logger) calls := make([]Invocation, len(uniqueAccountIds)*2) for i, accountId := range uniqueAccountIds { diff --git a/pkg/jmap/jmap_api_email.go b/pkg/jmap/jmap_api_email.go index 6f9006fe6..ee255bc41 100644 --- a/pkg/jmap/jmap_api_email.go +++ b/pkg/jmap/jmap_api_email.go @@ -253,7 +253,6 @@ func (j *Client) QueryEmailSnippets(accountId string, filter EmailFilterElement, QueryState: queryResponse.QueryState, }, nil }) - } type EmailQueryResult struct { @@ -323,7 +322,6 @@ func (j *Client) QueryEmails(accountId string, filter EmailFilterElement, sessio QueryState: queryResponse.QueryState, }, nil }) - } type EmailWithSnippets struct { @@ -438,7 +436,6 @@ func (j *Client) QueryEmailsWithSnippets(accountId string, filter EmailFilterEle QueryState: queryResponse.QueryState, }, nil }) - } type UploadedEmail struct { diff --git a/pkg/jmap/jmap_api_mailbox.go b/pkg/jmap/jmap_api_mailbox.go index ed0ba62af..0d2635b59 100644 --- a/pkg/jmap/jmap_api_mailbox.go +++ b/pkg/jmap/jmap_api_mailbox.go @@ -352,3 +352,49 @@ func (j *Client) GetMailboxRolesForMultipleAccounts(accountIds []string, session return resp, nil }) } + +func (j *Client) GetInboxNameForMultipleAccounts(accountIds []string, session *Session, ctx context.Context, logger *log.Logger, acceptLanguage string) (map[string]string, SessionState, Language, Error) { + logger = j.logger("GetInboxNameForMultipleAccounts", session, logger) + + uniqueAccountIds := structs.Uniq(accountIds) + n := len(uniqueAccountIds) + if n < 1 { + return nil, "", "", nil + } + + invocations := make([]Invocation, n*2) + for i, accountId := range uniqueAccountIds { + invocations[i*2+0] = invocation(CommandMailboxQuery, MailboxQueryCommand{ + AccountId: accountId, + Filter: MailboxFilterCondition{ + Role: JmapMailboxRoleInbox, + }, + }, mcid(accountId, "0")) + } + + cmd, err := j.request(session, logger, invocations...) + if err != nil { + return nil, "", "", err + } + + return command(j.api, logger, ctx, session, j.onSessionOutdated, cmd, acceptLanguage, func(body *Response) (map[string]string, Error) { + resp := make(map[string]string, n) + for _, accountId := range uniqueAccountIds { + var r MailboxQueryResponse + err = retrieveResponseMatchParameters(logger, body, CommandMailboxGet, mcid(accountId, "0"), &r) + if err != nil { + return nil, err + } + switch len(r.Ids) { + case 0: + // skip: account has no inbox? + case 1: + resp[accountId] = r.Ids[0] + default: + logger.Warn().Msgf("multiple ids for mailbox role='%v' for accountId='%v'", JmapMailboxRoleInbox, accountId) + resp[accountId] = r.Ids[0] + } + } + return resp, nil + }) +}