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

A message that came to the app, as its mailbox gets it.

Its fields are a message's, whatever brought it: who sent it, to whom,
its subject, its text and HTML, its files, when it was sent. Email is
the one channel there is (`channel: :email`); the email's own are kept
beside them: its headers, `Message-ID` and references, its structure
and the raw email.

  * `:id` - the message's row (`Letterbox.Inbound`).
  * `:from` - the sender (`Letterbox.Address`), as the email says it.
    Anyone can write any `From`.
  * `:verified_from` - the sender, when a mail server the app trusts
    checked it: the `From` whose domain passed DMARC, or DKIM or SPF
    for that domain, in that server's `Authentication-Results` (see
    `Letterbox.Email.parse/2`'s `:trusted_servers`). nil otherwise. Act
    on this one, not on `:from`, for what only a known sender may do.
  * `:to`, `:cc`, `:bcc`, `:reply_to` - its addresses, as the email says.
  * `:recipient` - the recipient its route matched (`Letterbox.Routing`):
    the address it came in by, `site+abc123@in.example.com`, whose
    sub-address (`Letterbox.Address.tag/1`) can say whose it is.
  * `:recipients` - where it was delivered: the addresses the mail
    server took it for (an ingress's envelope, Resend's
    `received_for`), else those of `To`, `Cc`, `Delivered-To` and
    `X-Original-To`. An address in `Bcc` is only here.
  * `:subject`, `:text`, `:html` - in UTF-8. `:text` is the plain text
    the email has, or text from its HTML when it has none. `:lossy` is
    true when some of it could not be read (a charset no one knows).
  * `:attachments` - its files (`Letterbox.Attachment`), those its HTML
    shows (`inline?: true`) included.
  * `:file_links` - links in its text to files sent another way, too
    large for an email: Apple's Mail Drop, Google Drive, OneDrive,
    Dropbox, WeTransfer. `%{url: …, service: :mail_drop | …}`.
  * `:sent_at` - its `Date`, in UTC, or nil.
  * `:message_id`, `:in_reply_to`, `:references` - the email's ids,
    without their angle brackets: what threads it to what was sent.
  * `:headers` - all the email's headers (`Letterbox.MIME.Header`),
    undecoded; `header/2` gives one decoded.
  * `:mime` - its structure (`Letterbox.MIME`), and `:raw`, the email as
    it came.

# `t`

```elixir
@type t() :: %Letterbox.Message{
  attachments: [Letterbox.Attachment.t()],
  bcc: [Letterbox.Address.t()],
  cc: [Letterbox.Address.t()],
  channel: :email,
  file_links: [%{url: String.t(), service: atom()}],
  from: Letterbox.Address.t() | nil,
  headers: [Letterbox.MIME.Header.t()],
  html: String.t() | nil,
  id: term(),
  in_reply_to: [String.t()],
  lossy: boolean(),
  message_id: String.t() | nil,
  mime: Letterbox.MIME.t() | nil,
  raw: binary() | nil,
  recipient: Letterbox.Address.t() | nil,
  recipients: [Letterbox.Address.t()],
  references: [String.t()],
  reply_to: [Letterbox.Address.t()],
  sent_at: DateTime.t() | nil,
  subject: String.t() | nil,
  text: String.t() | nil,
  to: [Letterbox.Address.t()],
  verified_from: Letterbox.Address.t() | nil
}
```

# `delivered_to?`

```elixir
@spec delivered_to?(t(), String.t()) :: boolean()
```

Whether it was delivered to `address` (a string, any case, with or
without its sub-address).

# `files`

```elixir
@spec files(t()) :: [Letterbox.Attachment.t()]
```

Its attachments the HTML does not show in its text.

# `header`

```elixir
@spec header(t(), String.t()) :: String.t() | nil
```

The first value of a header (any case), decoded to UTF-8, or nil.

# `headers`

```elixir
@spec headers(t(), String.t()) :: [String.t()]
```

Every value of a header (any case), decoded.

---

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