Documentation
¶
Overview ¶
Package mailfold is the official Go client SDK for Mailfold (https://github.com/isi1988/Mailfold), a self-hosted webmail/admin backend. It wraps Mailfold's per-mailbox REST API using only the standard library (net/http, encoding/json) — no third-party dependencies.
Index ¶
- type APIError
- type Address
- type Attachment
- type AttachmentData
- type Client
- func (c *Client) Attachment(folder string, uid int, index int) (*AttachmentData, error)
- func (c *Client) DeleteMessage(folder string, uid int) error
- func (c *Client) Folders() ([]Folder, error)
- func (c *Client) Message(folder string, uid int) (*Message, error)
- func (c *Client) Messages(opts MessagesOptions) ([]MessageHeader, error)
- func (c *Client) Search(folder, q string) ([]MessageHeader, error)
- func (c *Client) Send(req SendRequest) (*SendResponse, error)
- func (c *Client) SetFlag(req SetFlagRequest) error
- func (c *Client) WithHTTPClient(hc *http.Client) *Client
- type Flag
- type Folder
- type Message
- type MessageHeader
- type MessagesOptions
- type SendRequest
- type SendResponse
- type SetFlagRequest
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is returned whenever the Mailfold server responds with a non-2xx status code. It exposes the HTTP status, the server's error message, and (when the server set the header, typically on 429) the Retry-After value in seconds.
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
ContentType string `json:"content_type"`
Size int `json:"size"`
}
Attachment describes metadata about a message attachment (not its bytes; use Client.Attachment to fetch the bytes).
type AttachmentData ¶
AttachmentData is the raw bytes of an attachment plus whatever metadata the server exposed via response headers.
The attachment endpoint returns the file's raw bytes directly (not JSON), so this is a plain struct assembled from the HTTP response rather than an unmarshaled body.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Mailfold API client bound to a single base URL and API key. Construct one with New and reuse it; it is safe for concurrent use.
func New ¶
New creates a Client for the given Mailfold instance base URL (e.g. "https://real.mailfold.site" or a self-hosted URL) and API key (a "mf_live_..." bearer token). The token is sent verbatim and is never parsed or validated client-side.
func (*Client) Attachment ¶
Attachment downloads a single attachment's raw bytes by folder, message UID, and attachment index. Requires the mail:read scope.
Unlike every other endpoint, this one returns raw binary bytes rather than a JSON envelope, so it is handled outside of Client.do.
func (*Client) DeleteMessage ¶
DeleteMessage deletes (or marks \Deleted, per server semantics) the message at folder/uid. Requires the mail:write scope.
func (*Client) Message ¶
Message fetches a single full message (body + attachment metadata) by folder and UID. Requires the mail:read scope.
func (*Client) Messages ¶
func (c *Client) Messages(opts MessagesOptions) ([]MessageHeader, error)
Messages lists message headers in a folder, newest first. Requires the mail:read scope.
func (*Client) Search ¶
func (c *Client) Search(folder, q string) ([]MessageHeader, error)
Search searches a folder for messages matching q. Requires the mail:read scope.
func (*Client) Send ¶
func (c *Client) Send(req SendRequest) (*SendResponse, error)
Send sends an email from the mailbox the API key is bound to. Requires the mail:send scope.
func (*Client) SetFlag ¶
func (c *Client) SetFlag(req SetFlagRequest) error
SetFlag sets or clears a single IMAP flag on a message. Requires the mail:write scope.
type Message ¶
type Message struct {
MessageHeader
Text string `json:"text"`
HTML string `json:"html"`
Attachments []Attachment `json:"attachments"`
}
Message is the full message body, as returned by GET .../mail/message.
type MessageHeader ¶
type MessageHeader struct {
UID uint32 `json:"uid"`
Subject string `json:"subject"`
From []Address `json:"from"`
To []Address `json:"to"`
Date string `json:"date"`
Flags []string `json:"flags"`
Seen bool `json:"seen"`
Size uint32 `json:"size"`
Preview string `json:"preview"`
}
MessageHeader is a summary of a message, as returned by the listing and search endpoints.
type MessagesOptions ¶
MessagesOptions configures Client.Messages. Zero values mean "use the server default" (folder defaults to INBOX, limit defaults to 50).
type SendRequest ¶
type SendRequest struct {
To []string `json:"to,omitempty"`
Cc []string `json:"cc,omitempty"`
Bcc []string `json:"bcc,omitempty"`
Subject string `json:"subject,omitempty"`
Text string `json:"text,omitempty"`
HTML string `json:"html,omitempty"`
}
SendRequest is the payload for Client.Send. From is not included: the server always forces the From address to the mailbox the API key is bound to.
type SendResponse ¶
type SendResponse struct {
Status string `json:"status"`
}
SendResponse is returned by POST /api/v1/mail/send.
type SetFlagRequest ¶
type SetFlagRequest struct {
Folder string `json:"folder"`
UID int `json:"uid"`
Flag Flag `json:"flag"`
Set bool `json:"set"`
}
SetFlagRequest is the payload for Client.SetFlag.
type StatusResponse ¶
type StatusResponse struct {
Status string `json:"status"`
}
StatusResponse is the generic {"status": "..."} response body returned by the delete and flag endpoints.