render

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 28 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 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

View Source
const (
	MaxImageBytes    = 5 << 20
	MaxImagesPerMail = 32
)

Limits on fetching remote images (docs/design/rendering.md).

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

View Source
const MaxEmbeddedBytes = 16 << 20

MaxEmbeddedBytes bounds the image bytes one rendering embeds as data: URLs; images past it keep their mailpart URL.

View Source
const PartURL = "mailpart://localhost/"

PartURL is the prefix of every URL the app resolves through the parts cache.

Variables

View Source
var ErrNoPart = errors.New("render: no such part")

ErrNoPart means a message has no part with the requested path.

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

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

func Page(html string) []byte

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

func PublicAddr(a netip.Addr) bool

PublicAddr reports whether a is a public unicast address, the only kind the fetcher connects to.

func SafeFilename

func SafeFilename(name, partPath, contentType string) string

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.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, rawURL string) (string, error)

Fetch downloads an image URL into the cache, or finds it there, and returns its relative path.

type PartFile

type PartFile struct {
	Path        string
	ContentType string
	Filename    string
	Size        int64
}

PartFile is a part decoded into the parts cache (api.PartFile).

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.

func (*PartsCache) Write

func (c *PartsCache) Write(rel string, data []byte) error

Write stores data at rel atomically: a temp file in the same directory, then a rename.

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.

func (*Renderer) Part

func (r *Renderer) Part(messageID int64, raw []byte, path string) (PartFile, error)

Part decodes the part at path (an IMAP part specifier) into m/<messageID>/<path>/<safe file name>.

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, messageID int64, raw []byte, remote bool) (Rendering, error)

Render prepares a raw message. With remote, remote images (not trackers) are fetched into the cache; otherwise they are left out and counted.

type Rendering

type Rendering struct {
	HTML     string
	Text     string
	Remote   int // remote resources left out
	Trackers int // tracking images removed
}

Rendering is a message prepared for the reader (api.Rendering).

Jump to

Keyboard shortcuts

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