compose

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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 compose is the desktop app's compose window (docs/specs/compose-ui.md; plan 0015, Phase 5): the draft's HTML through MyGo's rich text editor, the recipients, the attachments, and sending.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedLink(href string) bool

AllowedLink reports whether the editor keeps a link.

func HTMLText

func HTMLText(src string) string

HTMLText is the text of HTML: blocks and line breaks end a line, then white space is squashed.

func HasAttachment

func HasAttachment(src string, attachments int) bool

HasAttachment reports a chip, or an image outside every quote.

func KeepPastedImages

func KeepPastedImages(t richtext.Text, html string) (lost int)

KeepPastedImages gives each picture in t that has only a bitmap the source it had in html, the clipboard's HTML it was pasted from: the editor drops that source, and a bitmap's bytes cannot be read back. A paste repeated in one frame brings the same pictures again. It returns how many have no usable source, or one that would take the draft's HTML past maxDraftHTML; those lose their bitmap, so that they show empty and are not asked about again.

func MentionsAttachment

func MentionsAttachment(text string) bool

MentionsAttachment reports whether text holds an attachment word as a whole word.

func NeedsReminder

func NeedsReminder(src, signatureHTML string, attachments int) bool

NeedsReminder reports whether the user's own text mentions an attachment and none is attached.

func OwnText

func OwnText(src, signatureHTML string) string

OwnText is the text the user wrote: no quotes, no attribution line, no signature (docs/specs/compose-ui.md, Attachment reminder).

func ParseAddresses

func ParseAddresses(text string) (addresses []api.Address, invalid []string)

ParseAddresses splits typed or pasted text into addresses, dropping repeats without regard to case; pieces that do not parse come back as invalid, trimmed.

func RecipientPrefix added in v0.10.0

func RecipientPrefix(text string) (string, string)

RecipientPrefix returns the completed part of a field, including its last separator, and the last unfinished address for completion.

func ToHTML

func ToHTML(t richtext.Text) string

ToHTML writes the editor's text as the draft's HTML: a quotation's depth as nested <blockquote type="cite">, lists as <ul> and <ol>, nested by their items' Indent. QuoteDepth is independent of the list nesting.

func ToText

func ToText(src string, load PartLoader) richtext.Text

ToText reads a draft's HTML as the editor's text. Headings read as body paragraphs, as TipTap's schema has none, and images that are neither data: nor mailpart: are dropped, since the app never loads remote content.

func Token

func Token(a api.Address) string

Token writes an address as a recipient field's token, which reads back as this one recipient whatever the mail it came from says: the text is untrusted. An address that cannot be written plainly becomes one quoted piece, which is invalid and holds the send back.

func TomorrowMorning

func TomorrowMorning(now time.Time) time.Time

TomorrowMorning is where the Send Later sheet starts.

func ValidAddress

func ValidAddress(text string) bool

ValidAddress reports whether text is a plausible email address.

Types

type Choice

type Choice struct {
	Label string
	At    time.Time
}

Choice is a Send Later choice and its time.

func SendChoices

func SendChoices(now time.Time) []Choice

SendChoices offers tonight at 9 PM while that is ahead, then tomorrow at 8 AM, in now's zone.

type Options

type Options struct {
	// Client is maild's client now, nil while there is none. It runs on
	// the UI thread: a worker uses the client read for it there.
	Client func() *api.Client
	Draft  int64
	// Fresh says the draft was just made for this window: closed
	// untouched, it is deleted.
	Fresh bool
	Post  func(func())
	Now   func() time.Time
	// Close closes the window, and may run on a worker; Hide hides it
	// while its last save ends, and Show shows it again when that save
	// failed; SetTitle names it.
	Close    func()
	Hide     func()
	Show     func()
	SetTitle func(string)
	// OpenFiles asks for files to attach; none when cancelled. It runs on
	// a worker.
	OpenFiles func() ([]string, error)
	// FilesAsBytes sends a file's bytes rather than its path: maild cannot
	// read this computer's paths behind lodge, or from the Flatpak. It says
	// so for the connection of the moment.
	FilesAsBytes func() bool
	// LoadPart reads a mailpart: image for the editor, through c, which is
	// nil while disconnected. It runs on a worker.
	LoadPart func(c *api.Client, src string) ([]byte, error)
	// Sent tells the main window a message went into the Outbox.
	Sent func(item *api.OutboxItem)
	// EditSnippets opens Settings on its Snippets pane.
	EditSnippets func()
	// Kept says a close ended with the window open again: its save on
	// closing failed, which the window shows. It runs on the UI thread.
	Kept func()
}

Options configure a compose window.

type PartLoader

type PartLoader func(src string) ([]byte, error)

PartLoader reads a mailpart: image's bytes; nil, or an error, leaves the image without a picture but keeps it in the draft.

type TimeSheet

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

TimeSheet asks for a future date and time, for Send Later and Remind Me. Keep one in the window's state, Show it, and call View every frame.

func (*TimeSheet) Show

func (s *TimeSheet) Show(title string, at time.Time, choose func(time.Time))

Show opens the sheet at the time given; choose gets the time on OK.

func (*TimeSheet) View

func (s *TimeSheet) View(c *ui.Context, now time.Time)

View draws the sheet while it is open; now decides what is in the future.

type Window

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

Window is one draft's window. Its state belongs to the UI thread.

func New

func New(o Options) *Window

New returns a window that has not loaded its draft; Start loads it.

func (*Window) RequestClose

func (w *Window) RequestClose() bool

RequestClose says whether the window may go now. Asked first, it says no: it hides the window and starts the save on closing, whose end closes the window again through Options.Close, and only then does it say yes. So the app, which quits with its last window, outlives the save. A snippet still being read goes in first, and the save starts after it. A save that fails shows the window again (keep).

func (*Window) SaveNow

func (w *Window) SaveNow(limit time.Duration) error

SaveNow writes what is left of the draft before it returns, waiting at most limit: the OS ends the session (logout, shutdown), and the process can end once the quit's listeners return. It never deletes an untouched draft. Call it on the UI thread.

func (*Window) Start

func (w *Window) Start(ctx context.Context)

Start loads the draft and what its fields offer.

func (*Window) View

func (w *Window) View(c *ui.Context)

View draws the window.

Jump to

Keyboard shortcuts

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