Documentation
¶
Overview ¶
Package render prepares stored messages for the reader: sanitized HTML whose images are embedded as data: URLs (WebKitGTK does not load the app's mailpart:// scheme inside the reader's frame), inline parts decoded into the parts cache, and remote images fetched only on request (docs/design/rendering.md, ADR-0005).
Index ¶
Constants ¶
const ( MaxImageBytes = 5 << 20 MaxImagesPerMail = 32 )
Limits on fetching remote images (docs/design/rendering.md).
const CodeParseFailed = "mime.parse_failed"
CodeParseFailed is the problem code of a stored message that mimex cannot parse for display (mimex.ErrParse). The record's MESSAGE is the error's text; the code names no mail.
const MaxEmbeddedBytes = 16 << 20
MaxEmbeddedBytes bounds the image bytes one rendering embeds as data: URLs; images past it keep their mailpart URL.
const PartURL = "mailpart://localhost/"
PartURL is the prefix of every URL the app resolves through the parts cache.
Variables ¶
var ErrNoPart = errors.New("render: no such part")
ErrNoPart means a message has no part with the requested path.
var ErrOmitted = errors.New("render: the part's content was left out")
ErrOmitted means the message is a display copy (ADR-0037) that left the part's content out: render the part from the whole message.
var ErrRefusedAddress = errors.New("render: refused non-public address")
ErrRefusedAddress means a remote image resolved to an address that is not on the public internet.
Functions ¶
func Page ¶
Page wraps a rendering's sanitized HTML in the reader's whole page, for lodge's content route (docs/specs/lodge-app.md). Every link targets a new tab: the sanitizer drops base and target from messages (ADR-0036).
func PublicAddr ¶
PublicAddr reports whether a is a public unicast address, the only kind the fetcher connects to.
func SafeFilename ¶
SafeFilename makes a part's file name safe to create: no path separators, control characters or leading dots, at most 200 bytes. An empty result becomes part-<path>.<ext>.
Types ¶
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher downloads remote images into the parts cache for a message whose remote content the user allowed. It sends no cookies or Referer, and its dialer refuses every address allow rejects, so a message cannot reach the local network, also through DNS or redirects.
func NewFetcher ¶
func NewFetcher(cache *PartsCache, allow func(netip.Addr) bool) *Fetcher
NewFetcher returns a Fetcher; allow nil means PublicAddr.
type PartsCache ¶
type PartsCache struct {
Root string
}
PartsCache is the directory the app reads as mailpart://localhost/ (<cache>/parts). Paths are relative and use forward slashes.
func (*PartsCache) File ¶
func (c *PartsCache) File(rel string) (*os.File, error)
File opens the cached file at rel, for serving it with its size and modification time.
func (*PartsCache) Has ¶
func (c *PartsCache) Has(rel string) bool
Has reports whether rel exists in the cache.
func (*PartsCache) Open ¶
func (c *PartsCache) Open(rel string) (io.ReadCloser, error)
Open opens the cached file at rel.
type Renderer ¶
type Renderer struct {
Parts *PartsCache
Fetcher *Fetcher
// Problems, when set, records CodeParseFailed in the local journal each
// time a stored message cannot be parsed for display (ADR-0049). nil
// records nothing.
Problems *problems.Recorder
}
Renderer renders messages into its parts cache. Fetcher may be nil, which leaves every remote image out.