Kantoor.Invitations (Kantoor v1.0.0)

Calendar invitations found in mail (iTIP over email, RFC 6047): the card shown above a message, and the Accept / Tentative / Decline answer.

Hostile input

The text/calendar part comes from the sender. It is size-capped and parsed with the DAV library's structural parser; every value is plain data for HEEx to escape (nothing here builds HTML or links), long values are cut and control characters removed. A part that does not parse, has no valid event, or whose METHOD differs from its content type is shown as not actionable.

Several events in one message

RFC 5546 (section 3.2.2 for REQUEST, 3.2.3 for REPLY) lets one iTIP message hold several components only when they share a UID: a series and its overrides. A sender that packs different events into one message is not following it, but they exist (a "meeting pack"). Each UID is therefore treated as its own invitation: the card for the first, in card, has the others in card.others (at most 10, skipped_events counts the rest), each with its own answer buttons, its own copy in the calendar and, when answered, its own REPLY to the organiser (one UID per message, as the RFC asks). Answering one does not answer the others.

Trust

card.verdict is Kantoor.Dav.Itip.verdict/2 applied to the auth_results Karta recorded for this message and the message's From address, never to anything the message says about itself. Only a :pass is trusted (and only those are applied automatically at ingest, by Kantoor.Dav.Itip). With no or a failing verdict the card carries a "sender not verified" warning, and the user may still accept by hand.

Answering

An answer stores the invitation in the user's default calendar when it is not there yet (without alarms and attachments, transparent until answered), then changes the user's own PARTSTAT through Kantoor.Dav.Local, i.e. the same PUT a calendar app would do. The DAV scheduling hook then tells the organiser: inside this server by updating the organiser's copy, for anyone else by an iMIP REPLY (Kantoor.Dav.Itip.deliver/4). The reply goes to the ORGANIZER of the invitation and nowhere else; Reply-To and other headers are never read.

Summary

Functions

The invitation card for a message, :none when it has no (usable) iTIP part.

The answers a user can give.

Answers the invitation in message message_id for the signed-in user.

Types

card()

@type card() :: map()

Functions

for_message(scope, message)

@spec for_message(Kantoor.Accounts.Scope.t() | nil, Kantoor.Mailboxes.Message.t()) ::
  {:ok, card()} | :none

The invitation card for a message, :none when it has no (usable) iTIP part.

partstats()

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

The answers a user can give.

respond(scope, message_id, partstat, opts \\ [])

@spec respond(Kantoor.Accounts.Scope.t() | nil, term(), String.t(), keyword()) ::
  {:ok, card(),
   :organizer_updated | :reply_sent | :reply_failed | :calendar_only}
  | {:error,
     :not_found
     | :body_unavailable
     | :not_actionable
     | :conflict
     | :store_failed
     | :failed}

Answers the invitation in message message_id for the signed-in user.

Option :uid says which event of a message with several (see the moduledoc) is answered; it must be one the card lists, and defaults to the first. Option :rid says which occurrence of a repeating one. Returns the refreshed card (with the others' cards in others) and how the organiser was told: :organizer_updated (organiser on this server, their copy shows the answer), :reply_sent (an iMIP reply went out, or was handed to Karta), :reply_failed (it could not be sent: the answer is in the calendar and the page says so) or :calendar_only. Errors: :not_found, :not_actionable, :conflict, :store_failed, :failed.