mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-11 14:39:09 -06:00
* refactor the jmap package to split it into several files as the
jmap.api.go file was becoming too unwieldy
* refactor the Groupware handler function response to be a Response
object, to be more future-proof and avoid adding more and more
return parameters while handling "no content" response as well
* more godoc for the JMAP model
* add Email creation, updating, deleting (Email/set,
EmailSubmission/set)
* add endpoints
- POST /accounts/{accountid}/messages
- PATCH|PUT /accounts/{accountid}/messages/{messageid}
- DELETE /accounts/{accountid}/messages/{messageid}
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package jmap
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/opencloud-eu/opencloud/pkg/log"
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type Client struct {
|
|
wellKnown SessionClient
|
|
api ApiClient
|
|
blob BlobClient
|
|
sessionEventListeners *eventListeners[SessionEventListener]
|
|
io.Closer
|
|
}
|
|
|
|
func (j *Client) Close() error {
|
|
return j.api.Close()
|
|
}
|
|
|
|
func NewClient(wellKnown SessionClient, api ApiClient, blob BlobClient) Client {
|
|
return Client{
|
|
wellKnown: wellKnown,
|
|
api: api,
|
|
blob: blob,
|
|
sessionEventListeners: newEventListeners[SessionEventListener](),
|
|
}
|
|
}
|
|
|
|
func (j *Client) AddSessionEventListener(listener SessionEventListener) {
|
|
j.sessionEventListeners.add(listener)
|
|
}
|
|
|
|
func (j *Client) onSessionOutdated(session *Session) {
|
|
j.sessionEventListeners.signal(func(listener SessionEventListener) {
|
|
listener.OnSessionOutdated(session)
|
|
})
|
|
}
|
|
|
|
// Retrieve JMAP well-known data from the Stalwart server and create a Session from that.
|
|
func (j *Client) FetchSession(username string, logger *log.Logger) (Session, Error) {
|
|
wk, err := j.wellKnown.GetSession(username, logger)
|
|
if err != nil {
|
|
return Session{}, err
|
|
}
|
|
return newSession(wk)
|
|
}
|
|
|
|
func (j *Client) logger(accountId string, operation string, session *Session, logger *log.Logger) *log.Logger {
|
|
zc := logger.With().Str(logOperation, operation).Str(logUsername, session.Username)
|
|
if accountId != "" {
|
|
zc = zc.Str(logAccountId, accountId)
|
|
}
|
|
return &log.Logger{Logger: zc.Logger()}
|
|
}
|
|
|
|
func (j *Client) loggerParams(accountId string, operation string, session *Session, logger *log.Logger, params func(zerolog.Context) zerolog.Context) *log.Logger {
|
|
zc := logger.With().Str(logOperation, operation).Str(logUsername, session.Username)
|
|
if accountId != "" {
|
|
zc = zc.Str(logAccountId, accountId)
|
|
}
|
|
return &log.Logger{Logger: params(zc).Logger()}
|
|
}
|