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

Copy Markdown View Source

Reads Postfix's main.cf and expands parameter values the way Postfix does, for Sovite.Core.Postfix.Migration.

The file has one name = value per logical line. Lines whose first non-whitespace character is # are comments, and a line that starts with whitespace continues the one before it. Values can refer to other parameters as $name, ${name}, or $(name), and use the conditional forms ${name?value} (value when $name is not empty), ${name:value} (when it is empty), and ${name?{value1}:{value2}}. $$ is a literal $. Parameters not in the file get Postfix's defaults, for the ones the migration needs.

The file is untrusted input: names stay strings.

Summary

Functions

Expands the parameter references in text.

The expanded value of name, split into a list. See split/1.

Splits Postfix configuration text into logical lines: comments and blank lines are dropped, and lines starting with whitespace are joined to the one before. Returns {line_number, text} pairs.

The names the file sets, in file order.

Parses contents. defaults override Postfix's built-in defaults, such as "myhostname" (the system's host name) and "config_directory".

The value of name as written in the file, or nil.

Whether the file sets name.

Splits a list value on whitespace and commas, keeping { ... } groups (and type:{ ... } tables) together.

Strips the braces of a { ... } group and the whitespace inside. Other text is returned trimmed.

The expanded value of name: from the file, or the default. Unknown parameters are empty, as in Postfix.

Types

t()

@type t() :: %Sovite.Core.Postfix.MainCf{
  defaults: %{required(String.t()) => String.t()},
  names: [String.t()],
  params: %{required(String.t()) => String.t()}
}

Functions

expand(main, text)

@spec expand(t(), String.t()) :: String.t()

Expands the parameter references in text.

list(main, name)

@spec list(t(), String.t()) :: [String.t()]

The expanded value of name, split into a list. See split/1.

logical_lines(contents)

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

Splits Postfix configuration text into logical lines: comments and blank lines are dropped, and lines starting with whitespace are joined to the one before. Returns {line_number, text} pairs.

iex> Sovite.Core.Postfix.MainCf.logical_lines("a = 1\n  2\n# c\nb = 3\n")
[{1, "a = 1 2"}, {4, "b = 3"}]

names(main_cf)

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

The names the file sets, in file order.

parse(contents, defaults \\ %{})

@spec parse(String.t(), %{required(String.t()) => String.t()}) :: t()

Parses contents. defaults override Postfix's built-in defaults, such as "myhostname" (the system's host name) and "config_directory".

raw(main_cf, name)

@spec raw(t(), String.t()) :: String.t() | nil

The value of name as written in the file, or nil.

set?(main_cf, name)

@spec set?(t(), String.t()) :: boolean()

Whether the file sets name.

split(value)

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

Splits a list value on whitespace and commas, keeping { ... } groups (and type:{ ... } tables) together.

iex> Sovite.Core.Postfix.MainCf.split("a, b  c,{ d, e }, inline:{ x=1, y=2 }")
["a", "b", "c", "{ d, e }", "inline:{ x=1, y=2 }"]

ungroup(text)

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

Strips the braces of a { ... } group and the whitespace inside. Other text is returned trimmed.

iex> Sovite.Core.Postfix.MainCf.ungroup("{ a = b }")
"a = b"

value(main, name)

@spec value(t(), String.t()) :: String.t()

The expanded value of name: from the file, or the default. Unknown parameters are empty, as in Postfix.