Documentation
¶
Overview ¶
Package jmapc is a thin JMAP (RFC 8620/8621) client over github.com/mikluko/jmap types.
Index ¶
- Constants
- Variables
- func DiscoverSession(ctx context.Context, hc *http.Client, r Resolver, address string) (string, error)
- func Domain(address string) (string, error)
- func Result[T any](resp *jmap.Response, callID string) (T, error)
- func SetErrors(groups ...map[jmap.ID]*jmap.SetError) error
- type Account
- type Client
- func (c *Client) Do(ctx context.Context, req *jmap.Request) (*jmap.Response, error)
- func (c *Client) Download(ctx context.Context, accountID, blobID jmap.ID, name, contentType string) (io.ReadCloser, error)
- func (c *Client) HasCapability(ctx context.Context, uri jmap.URI) bool
- func (c *Client) Invalidate()
- func (c *Client) MailAccount(ctx context.Context) (jmap.ID, error)
- func (c *Client) Session(ctx context.Context) (*Session, error)
- func (c *Client) Upload(ctx context.Context, accountID jmap.ID, contentType string, data io.Reader) (*jmap.UploadResponse, error)
- type HTTPError
- type MethodError
- type Resolver
- type Session
Constants ¶
const ( CapCore jmap.URI = "urn:ietf:params:jmap:core" CapMail jmap.URI = "urn:ietf:params:jmap:mail" CapSubmission jmap.URI = "urn:ietf:params:jmap:submission" CapVacation jmap.URI = "urn:ietf:params:jmap:vacationresponse" CapSieve jmap.URI = "urn:ietf:params:jmap:sieve" )
Capability URIs used by this project.
Variables ¶
ErrUnauthorized means the mail server rejected the credentials.
Functions ¶
func DiscoverSession ¶
func DiscoverSession(ctx context.Context, hc *http.Client, r Resolver, address string) (string, error)
DiscoverSession finds the JMAP session URL for an email address (RFC 8620 §2.2).
Types ¶
type Account ¶
type Account struct {
Name string `json:"name"`
IsPersonal bool `json:"isPersonal"`
IsReadOnly bool `json:"isReadOnly"`
Capabilities map[jmap.URI]json.RawMessage `json:"accountCapabilities"`
}
Account is a JMAP account entry of the session.
type Client ¶
type Client struct {
HTTP *http.Client
SessionURL string
// contains filtered or unexported fields
}
Client talks to one JMAP server with an already authenticated HTTP client.
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, accountID, blobID jmap.ID, name, contentType string) (io.ReadCloser, error)
Download opens a blob. The caller must close the returned body.
func (*Client) HasCapability ¶
HasCapability reports whether the session advertises the capability.
func (*Client) Invalidate ¶
func (c *Client) Invalidate()
Invalidate drops the cached session so the next call refetches it.
func (*Client) MailAccount ¶
MailAccount returns the primary mail account id.
type HTTPError ¶
HTTPError is a request-level failure, decoded from an RFC 7807 problem when present.
type MethodError ¶
MethodError is a JMAP method-level error (RFC 8620 §3.6.2).
func (*MethodError) Error ¶
func (e *MethodError) Error() string
type Resolver ¶
type Resolver interface {
LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
}
Resolver looks up SRV records; *net.Resolver implements it.
type Session ¶
type Session struct {
Capabilities map[jmap.URI]json.RawMessage `json:"capabilities"`
Accounts map[jmap.ID]Account `json:"accounts"`
PrimaryAccounts map[jmap.URI]jmap.ID `json:"primaryAccounts"`
Username string `json:"username"`
APIURL string `json:"apiUrl"`
DownloadURL string `json:"downloadUrl"`
UploadURL string `json:"uploadUrl"`
State string `json:"state"`
}
Session is the subset of the JMAP session resource this project reads. Capabilities stay raw so that unknown server extensions never break decoding.