Sovite.Core.Postfix.Table (sovite v0.6.0)

Copy Markdown View Source

Reads Postfix lookup tables, for Sovite.Core.Postfix.Migration.

A table is named type:name:

  • hash:, btree:, lmdb:, cdb:, dbm:, sdbm: - indexed files built with postmap from a text file. The text file is read (hash:/etc/postfix/virtual reads /etc/postfix/virtual, not virtual.db). texthash: is the text file itself.
  • proxy:TYPE:name - one of the above through proxymap(8); the file is read as without proxy:.
  • inline:{ key=value, { key = text } } and static:value - the entries are in the name.

Other types (mysql:, pgsql:, ldap:, regexp:, pcre:, cidr:, sqlite:, memcache:, socketmap:, tcp:, unionmap:, ...) cannot be read: they are reported as unsupported.

Text files have one key value entry per logical line (see Sovite.Core.Postfix.MainCf.logical_lines/1). Keys are lower-cased, as postmap does. Alias files (aliases(5)) are name: dest, dest.

Summary

Types

Why a table could not be read.

Reads a file: File.read/1, or a function that maps paths first.

Where a table's entries come from.

Functions

Describes a read error for the report.

Splits a list of destinations on commas, keeping quoted ones (such as "|command with args") whole and removing the quotes.

Parses a postmap source file.

Parses an aliases(5) file: name: destination, destination. Names may be quoted.

Reads the entries of table name as {key, value} pairs, in file order. read reads a file.

Reads alias table name as {name, destinations} pairs. See read/2.

Parses a table name.

Types

error()

@type error() :: {:unsupported, String.t()} | {:unreadable, String.t(), term()}

Why a table could not be read.

reader()

@type reader() :: (String.t() -> {:ok, binary()} | {:error, term()})

Reads a file: File.read/1, or a function that maps paths first.

source()

@type source() ::
  {:file, type :: String.t(), path :: String.t()}
  | {:inline, [{String.t(), String.t()}]}
  | {:static, String.t()}
  | {:unsupported, type :: String.t()}

Where a table's entries come from.

Functions

describe_error(arg)

@spec describe_error(error()) :: String.t()

Describes a read error for the report.

destinations(value)

@spec destinations(String.t()) :: [String.t()]

Splits a list of destinations on commas, keeping quoted ones (such as "|command with args") whole and removing the quotes.

parse(contents)

@spec parse(String.t()) :: [{String.t(), String.t()}]

Parses a postmap source file.

iex> Sovite.Core.Postfix.Table.parse("# comment\nAlice@Example.com  alice@example.org,\n  bob@example.org\n")
[{"alice@example.com", "alice@example.org, bob@example.org"}]

parse_aliases(contents)

@spec parse_aliases(String.t()) :: [{String.t(), [String.t()]}]

Parses an aliases(5) file: name: destination, destination. Names may be quoted.

iex> Sovite.Core.Postfix.Table.parse_aliases(~s(postmaster: root\n"x y": a@example.com, "|/bin/prog arg"\n))
[{"postmaster", ["root"]}, {"x y", ["a@example.com", "|/bin/prog arg"]}]

read(name, read)

@spec read(String.t(), reader()) ::
  {:ok, [{String.t(), String.t()}]} | {:error, error()}

Reads the entries of table name as {key, value} pairs, in file order. read reads a file.

read_aliases(name, read)

@spec read_aliases(String.t(), reader()) ::
  {:ok, [{String.t(), [String.t()]}]} | {:error, error()}

Reads alias table name as {name, destinations} pairs. See read/2.

source(name)

@spec source(String.t()) :: source()

Parses a table name.

iex> Sovite.Core.Postfix.Table.source("hash:/etc/postfix/virtual")
{:file, "hash", "/etc/postfix/virtual"}
iex> Sovite.Core.Postfix.Table.source("mysql:/etc/postfix/mysql.cf")
{:unsupported, "mysql"}