mailcap: Index | Files

package mailcap

import ""

Package mailcap is a port of the python3 mailcap library to golang and provides developers with the ability to query mimetypes and keys against the various mailcap files on a system to acquire an appropriate command to run in order to view, edit, etc a given file of a given mimetype.


Package Files


type Entry Uses

type Entry map[string]string

Entry is a map of strings keyed with strings that represents a single mailcap entry. It represents one prgram for one mimetype. An entry can contain options for various keys (test, view, edit, etc).

func (Entry) Actions Uses

func (e Entry) Actions() []string

Get the available actions/attributes for an entry as a string slice

func (Entry) Command Uses

func (e Entry) Command(path string) (*exec.Cmd, error)

Called on an Entry type that has an action set (either by calling SetAction on the Entry or by it being returned by FindMatch. Returns a pointer to type exec.Command and an error (or nil). The caller needs to remember to set Std in/out/err on the returned Cmd as is needed by their use case.

func (Entry) CommandString Uses

func (e Entry) CommandString(action string) (string, error)

Retrieve the command string for a particular action. The string will not have a path inserted into it and will have %s to represent the place that the path will go. Returns a string and error (or nil).

func (Entry) SetAction Uses

func (e Entry) SetAction(action string) error

Sets the action (key) for the entry calling it. This action is used when calling execute. The action is generally set by the Mailcap receiver FindMatch and SetAction is provided in order to easily manipulate an Entry found in the db directly. This is not recommended, but is provided as a lower level way of using the lib.

type Mailcap Uses

type Mailcap struct {
    DB map[string][]Entry

Mailcap is the main struct to interact with. It contains a Cap, as caps, that represents the full mailcap db for the system. It has a number of receivers to facilitate retrieving a command from a mimetype.

func NewMailcap Uses

func NewMailcap() *Mailcap

Creates and initializes the mailcap struct/db and returns a pointer to Mailcap struct

func (*Mailcap) FindMatch Uses

func (m *Mailcap) FindMatch(mime, key string, needsTerm bool) (Entry, error)

Retrieves an Entry for a given mimetype and key. Key is required to make sure the returned Entry has the capability that is desired. Common keys: "view", "edit". Also takes a bool, needsTerm, that can be set to true if the command must be executable in a terminal only environment.

Returns and Entry and an error

func (*Mailcap) GetAllMime Uses

func (m *Mailcap) GetAllMime(mime string) ([]Entry, error)

Returns []Entry for a given mimetype and an error or nil.

Package mailcap imports 7 packages (graph). Updated 2019-10-01. Refresh now. Tools for package owners.