jmapc

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jmapc is a thin JMAP (RFC 8620/8621) client over github.com/mikluko/jmap types.

Index

Constants

View Source
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

View Source
var ErrUnauthorized = errors.New("the mail server rejected the authorization; reconnect the account")

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).

func Domain

func Domain(address string) (string, error)

Domain returns the lower-cased domain of an email address.

func Result

func Result[T any](resp *jmap.Response, callID string) (T, error)

Result extracts the response of callID from resp.

func SetErrors

func SetErrors(groups ...map[jmap.ID]*jmap.SetError) error

SetErrors flattens the per-record failures of a /set response, or returns nil.

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) Do

func (c *Client) Do(ctx context.Context, req *jmap.Request) (*jmap.Response, error)

Do sends a request and returns the decoded response.

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

func (c *Client) HasCapability(ctx context.Context, uri jmap.URI) bool

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

func (c *Client) MailAccount(ctx context.Context) (jmap.ID, error)

MailAccount returns the primary mail account id.

func (*Client) Session

func (c *Client) Session(ctx context.Context) (*Session, error)

Session returns the cached JMAP session, fetching it on first use.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, accountID jmap.ID, contentType string, data io.Reader) (*jmap.UploadResponse, error)

Upload stores a blob and returns its id.

type HTTPError

type HTTPError struct {
	Status int
	Type   string
	Detail string
}

HTTPError is a request-level failure, decoded from an RFC 7807 problem when present.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type MethodError

type MethodError struct {
	Type        string
	Description string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL