mailcap/README.md

1019 B

Mailcap

GoDoc

Golang port of the Python3 mailcap library.

Usage

An eaxmple showing how to launch a program based on its mime/media type:

import(
    tildegit.org/sloum/mailcap
)

func main() {
  // Build the mailcap database
  mc := mailcap.NewMailcap()

  // Find an avialable command with the required key and gui avialability
  command, err := mc.FindMatch("text/csv", "edit", false)
  if err != nil {
    panic(err)
  }

  // Run the command with the filepath provided
  err := command.Execute("/var/www/data/some_data.csv")
  if err != nil {
    panic(err)
  }

  // Now that the user has been presented the file to edit,
  // something can be done with the updated file...
}

In general usage a user will build the mailcap db, find a match, and execute the command they find with a certain filepath.

A few other helper methods are available for debugging or lower level mailcap work.