mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-06 04:11:21 -05:00
jmap: add GetInboxNameForMultipleAccounts
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user