# `Letterbox.Routing`
[🔗](https://github.com/hattoriai/letterbox/blob/v0.1.0-rc.0/lib/letterbox/routing.ex#L1)

Which mailbox takes which message: the app's routes, in one module.

    defmodule MyApp.Mailboxes do
      use Letterbox.Routing

      route "support@example.com", to: MyApp.SupportMailbox
      route "billing@", to: MyApp.BillingMailbox
      route ~r/\Areply\+/, to: MyApp.RepliesMailbox
      route "@in.example.com", to: MyApp.SitesMailbox
      route &MyApp.Tickets.forwarded?/1, to: MyApp.ForwardsMailbox
      route :all, to: MyApp.UnknownMailbox
    end

    config :letterbox, routing: MyApp.Mailboxes

A route matches a message's recipients (`Letterbox.Message`'s
`:recipients`), each in its order, and the first route that matches one
takes the message; the address it matched is the message's `:recipient`.
A route is:

  * an address, `"support@example.com"`: that address in any case, with
    or without a sub-address (`support+urgent@example.com`);
  * a local part, `"billing@"`: at any domain, with or without a
    sub-address;
  * a domain, `"@in.example.com"`: any address there;
  * a regex, matched with the address in lowercase;
  * a function of the message, true for the messages it takes (its
    `:recipient` is then the first of its recipients);
  * `:all`, every message.

A message no route takes is `"unrouted"`.

# `match`

```elixir
@spec match(module(), Letterbox.Message.t()) ::
  {:ok, module(), Letterbox.Address.t() | nil} | :none
```

The mailbox of a message and the recipient its route matched:
`{:ok, mailbox, recipient}`, or `:none`.

# `route`
*macro* 

A route: what it matches, and the mailbox (`to:`) that takes the messages.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
