Karta.Messages.Search (Karta v1.0.0)

What the messages of a server are searched for, cast from the query string of the messages page (cast/1), and the query it makes (query/2):

  • q - text found, without regard to case, in the envelope sender, an envelope recipient, the From address, the subject or the Message-ID (at most 200 characters);
  • status - messages with at least one recipient in this state (queued, deferred, delivered, bounced, suppressed, cancelled);
  • delivery - received messages with at least one inbound delivery in this state (pending, delivered, failed, accepted, held);
  • tag - messages with this tag, exactly;
  • from, to - dates (YYYY-MM-DD, UTC): messages accepted on or after the first, on or before the second.

cast/2 takes the fields a page offers; the ones it leaves out are not read from the parameters, so a page cannot be searched by a field it does not show.

A value that does not cast or validate is reported in the changeset and ignored in the search; the other values still count.

Summary

Functions

Casts query parameters (string keys; others are ignored). Returns the search made of the valid values, and the changeset with the errors of the others (for the form).

As cast/1, for a page that offers only fields (a subset of :q, :status, :delivery, :tag, :from, :to).

The delivery states of received messages that can be searched for.

query (of messages, named :message) narrowed to what the search asks for.

The recipient states that can be searched for.

The search as query parameters (only the values set), for links.

Types

t()

@type t() :: %Karta.Messages.Search{
  delivery: term(),
  from: term(),
  q: term(),
  status: term(),
  tag: term(),
  to: term()
}

Functions

cast(params)

@spec cast(map()) :: {t(), Ecto.Changeset.t()}

Casts query parameters (string keys; others are ignored). Returns the search made of the valid values, and the changeset with the errors of the others (for the form).

cast(params, fields)

@spec cast(map(), [atom()]) :: {t(), Ecto.Changeset.t()}

As cast/1, for a page that offers only fields (a subset of :q, :status, :delivery, :tag, :from, :to).

delivery_statuses()

@spec delivery_statuses() :: [atom()]

The delivery states of received messages that can be searched for.

query(search, query)

@spec query(t(), Ecto.Query.t()) :: Ecto.Query.t()

query (of messages, named :message) narrowed to what the search asks for.

statuses()

@spec statuses() :: [atom()]

The recipient states that can be searched for.

to_params(search)

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

The search as query parameters (only the values set), for links.