Sovite.Milter.Headers (sovite v0.6.0)

Copy Markdown View Source

Applies a milter's header modifications to the header fields of a message, with libmilter's index rules, and turns fields into the name and value that Sovite.Milter.header/3 sends.

Fields are Sovite.Message.Headers fields: {name, raw}, with the lower-cased name and the whole field, continuation lines and final CRLF included. Fields the milter does not touch keep every byte.

fields = Sovite.Message.Headers.parse(header)
fields = Sovite.Milter.Headers.apply(fields, modifications)

Modifications are applied one after the other, each to the result of the ones before it:

  • {:add_header, name, value} appends the field at the end.
  • {:insert_header, index, name, value} inserts it at position index among all fields: 0 is the top. Past the end, it is appended.
  • {:change_header, index, name, value} replaces the indexth field called name (case-insensitive, from 1; 0 counts as 1). When there are fewer, the field is appended, as Sendmail does.
  • {:delete_header, index, name} removes the indexth field called name, if there is one.

Other modifications are ignored.

Summary

Functions

Applies the header modifications in modifications to fields.

Splits a field into its name, as written, and its value: everything after the colon, without the final line break. Returns nil for a line that is not a field.

Functions

apply(fields, modifications)

Applies the header modifications in modifications to fields.

name_value(arg)

@spec name_value(Sovite.Message.Headers.field()) :: {String.t(), String.t()} | nil

Splits a field into its name, as written, and its value: everything after the colon, without the final line break. Returns nil for a line that is not a field.

iex> Sovite.Milter.Headers.name_value({"subject", "Subject: Hello\r\n world\r\n"})
{"Subject", " Hello\r\n world"}