fastmail

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// APIEndpoint is the Fastmail API endpoint.
	APIEndpoint = "https://api.fastmail.com/jmap/api/"
	// APIAuthEndpoint is the Fastmail authentication endpoint.
	APIAuthEndpoint = "https://www.fastmail.com/jmap/authenticate/"
)
View Source
var (
	ErrAccessTokenNotFound = errors.New("access token not found")
	ErrUnauthorized        = errors.New("unauthorized")
	ErrNoItemsReturned     = errors.New("no items returned")
	ErrMFARequired         = errors.New("mfa required for login")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code   int
	Status string
	Msg    string
	Detail string
}

func (APIError) Error

func (a APIError) Error() string

type AuthFlowMessage

type AuthFlowMessage struct {
	LoginID        string       `json:"loginId,omitempty"`
	MayTrustDevice bool         `json:"mayTrustDevice,omitempty"`
	Remember       bool         `json:"remember"`
	Type           string       `json:"type,omitempty"`
	Methods        []AuthMethod `json:"methods,omitempty"`
	Value          string       `json:"value,omitempty"`
}

func (*AuthFlowMessage) TOTPRequired

func (a *AuthFlowMessage) TOTPRequired() bool

type AuthMethod

type AuthMethod struct {
	Type         string `json:"type"`
	PhoneNumbers []struct {
		Number     string `json:"number"`
		ID         string `json:"id"`
		IsCodeSent bool   `json:"isCodeSent"`
	} `json:"phoneNumbers,omitempty"`
}

type AuthResponse

type AuthResponse struct {
	AccountType      string                 `json:"accountType,omitempty"`
	UserID           string                 `json:"userId,omitempty"`
	SigningID        string                 `json:"signingId,omitempty"`
	SigningKey       string                 `json:"signingKey,omitempty"`
	IsAdmin          bool                   `json:"isAdmin,omitempty"`
	SessionKey       string                 `json:"sessionKey,omitempty"`
	PrimaryAccounts  map[string]string      `json:"primaryAccounts,omitempty"`
	AccessToken      string                 `json:"accessToken,omitempty"`
	DisplayName      string                 `json:"displayName"`
	APIURL           string                 `json:"apiUrl,omitempty"`
	DownloadURL      string                 `json:"downloadUrl,omitempty"`
	UploadURL        string                 `json:"uploadUrl"`
	IsLoginBlocked   bool                   `json:"isLoginBlocked"`
	State            string                 `json:"state"`
	IsReseller       bool                   `json:"isReseller"`
	IsAppStore       bool                   `json:"isAppStore"`
	IsVerified       bool                   `json:"isVerified"`
	MayMailSync      bool                   `json:"mayMailSync"`
	MayContactSync   bool                   `json:"mayContactSync"`
	FeatureLevel     int                    `json:"featureLevel"`
	IsReceiveBlocked bool                   `json:"isReceiveBlocked"`
	ProxyURL         string                 `json:"proxyUrl,omitempty"`
	IsSendBlocked    bool                   `json:"isSendBlocked,omitempty"`
	NewCalAlerts     bool                   `json:"newCalAlerts,omitempty"`
	Language         string                 `json:"language"`
	Capabilities     map[string]interface{} `json:"capabilities,omitempty"`
}

func (*AuthResponse) GetAccessToken

func (a *AuthResponse) GetAccessToken() string

func (*AuthResponse) GetMailAccountID

func (a *AuthResponse) GetMailAccountID() (accountID string, ok bool)

type AuthenticateUsernameRequest

type AuthenticateUsernameRequest struct {
	Username string `json:"username,omitempty"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(appName string) *Client

Returns NewClient with the given values. 'accountID' is the Fastmail account ID, this is not the same as the email address.

func (*Client) CreateMaskedEmail

func (c *Client) CreateMaskedEmail(ctx context.Context, maskedEmail *MaskedEmail, enabled bool) (*MaskedEmail, error)

CreateMaskedEmail creates a new masked email for the given forDomain domain. If `enabled` is set to false, will only create a pending email and needs to be confirmed before it's usable.

func (*Client) DeleteMaskedEmails

func (c *Client) DeleteMaskedEmails(ctx context.Context, ids ...string) error

DeleteMaskedEmails deletes the given masked emails by ID.

func (*Client) LoginUsernamePasswordMFA

func (c *Client) LoginUsernamePasswordMFA(ctx context.Context, username, password, mfaCode string) (*AuthResponse, error)

LoginUsernamePasswordMFA authenticates with the given username and password, mfaCode is optional based on account settings.

func (*Client) SetTokenAuthCredentials

func (c *Client) SetTokenAuthCredentials(accountID, accessToken string) *Client

type ClientConfig

type ClientConfig struct {
	AppName    string
	APIBaseURL string
}

type Credentials

type Credentials struct {
	// contains filtered or unexported fields
}

type JMAPRequest

type JMAPRequest struct {
	Using       []string     `json:"using,omitempty"`
	MethodCalls []MethodCall `json:"methodCalls,omitempty"`
}

type JMAPResponse

type JMAPResponse struct {
	LatestClientVersion string           `json:"latestClientVersion,omitempty"`
	MethodResponses     []MethodResponse `json:"methodResponses,omitempty"`
	SessionState        string           `json:"sessionState,omitempty"`
}

type MaskedEmail

type MaskedEmail struct {
	ID            string `json:"id,omitempty" mapstructure:"id"`
	State         string `json:"state,omitempty" mapstructure:"state"`
	Email         string `json:"email,omitempty" mapstructure:"email"`
	Description   string `json:"description,omitempty" mapstructure:"description"`
	ForDomain     string `json:"forDomain,omitempty" mapstructure:"forDomain"`
	URL           string `json:"url,omitempty" mapstructure:"url"`
	CreatedBy     string `json:"createdBy,omitempty" mapstructure:"createdBy"`
	CreatedAt     string `json:"createdAt,omitempty" mapstructure:"createdAt"`
	LastMessageAt string `json:"lastMessageAt,omitempty" mapstructure:"lastMessageAt"`
}

MaskedEmail represents a Fastmail masked email.

type MaskedEmailPayload

type MaskedEmailPayload struct {
	AccountID string                  `json:"accountId,omitempty"`
	Create    map[string]*MaskedEmail `json:"create,omitempty"`
	Set       map[string]*MaskedEmail `json:"set,omitempty"`
	Update    map[string]*MaskedEmail `json:"update,omitempty"`
	Destroy   []string                `json:"destroy,omitempty"`
}

MaskedEmailPayload is the payload for the MaskedEmail/{set,update} method.

type MethodCall

type MethodCall struct {
	Name    string
	Payload interface{}
	ID      string
}

func (*MethodCall) MarshalJSON

func (m *MethodCall) MarshalJSON() ([]byte, error)

MarshalJSON marshals a MethodCall into the format needed by the Fastmail API eg. ["MaskedEmail/set", {...}, "0"].

func (*MethodCall) UnmarshalJSON

func (m *MethodCall) UnmarshalJSON(b []byte) error

type MethodResponse

type MethodResponse [3]interface{}

type MethodResponseError

type MethodResponseError struct {
	Actual   int
	Expected int
}

func (MethodResponseError) Error

func (m MethodResponseError) Error() string

type MethodResponseMaskedEmailSet

type MethodResponseMaskedEmailSet struct {
	AccountID string                 `mapstructure:"accountId" json:"accountId,omitempty"`
	Created   map[string]MaskedEmail `mapstructure:"created" json:"created,omitempty"`
	Updated   map[string]interface{} `mapstructure:"updated" json:"updated,omitempty"`
	Destroyed []interface{}          `mapstructure:"destroyed" json:"destroyed,omitempty"`
	NewState  interface{}            `mapstructure:"newState" json:"newState,omitempty"`
	OldState  interface{}            `mapstructure:"oldState" json:"oldState,omitempty"`
}

func (*MethodResponseMaskedEmailSet) GetCreatedItem

func (m *MethodResponseMaskedEmailSet) GetCreatedItem() (MaskedEmail, error)

Jump to

Keyboard shortcuts

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