<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-arslan-mimi-outer-00"
submissionType="IETF" category="info" xml:lang="en"
xmlns:xi="http://www.w3.org/2001/XInclude" indexInclude="true"
consensus="true">
  <front>
    <title abbrev="MIMI Outer">More Instant Messaging Interoperability (MIMI)
    Outer Layer</title>
    <seriesInfo value="draft-arslan-mimi-outer-00" stream="IETF"
    status="informational" name="Internet-Draft"></seriesInfo>
    <author initials="B." surname="Arslan" fullname="Burak Arslan">
      <organization>Soba Yazılım A.Ş.</organization>
      <address>
        <postal>
          <street></street>
          <country>Turkey</country>
        </postal>
        <email>burak@soba.email</email>
      </address>
    </author>
    <date />
    <area>Internet</area>
    <workgroup>MIMI</workgroup>
    <keyword>Internet-Draft</keyword>
    <keyword>mimi</keyword>
    <keyword>json</keyword>
    <keyword>xml</keyword>
    <keyword>mime</keyword>
    <keyword>msgpack</keyword>
    <keyword>jmap</keyword>
    <abstract>
      <t>This document describes a general purpose messaging format that is
      flexible enough to capture the semantics of incumbent messaging formats
      like MIME or XMPP or non-standard protocols like those of apps like
      WhatsApp, Signal, etc. It can be used as the payload format inside an MLS
      session.</t>
    </abstract>
  </front>
  <middle>
    <section anchor="conventions-and-definitions">
      <name>Conventions and Definitions</name>
      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
      "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
      "OPTIONAL" in this document are to be interpreted as described in BCP 14 
      <xref target="RFC2119"></xref>
      <xref target="RFC8174"></xref>when, and only when, they appear in all
      capitals, as shown here.</t>
      <t>The reader may wish to note that one of the two RFC references in the
      preceding paragraph was normative; the other was informative. These will
      be correctly identified as such in the References section below.</t>
    </section>
    <section anchor="introduction">
      <name>Introduction</name>
      <t>Compatibility with existing email systems is a nice property to have.
      The email infrastructure is distributed, tries to deal with the spam
      problem using its own means and most email clients are robust and
      feature-rich, built with long-term archival in mind.</t>
      <t>MIME is still the standard format in email exchange. It definitely
      shows its age (it's rather complex to implement, text-only,
      self-contained, etc) but otherwise stood the test of time so could very
      well form the basis of a next generation messaging format.</t>
      <t>The JMAP Email object 
      <xref target="RFC8621"></xref>(§.4) is one such attempt -- it simplifies
      MIME processing by shedding obsolete features like support for
      non-unicode character encodings but keeps defining features like being
      text-only and recursive structure. The JMAP protocol also adds blob
      support which adds an alternate transport for binary data, which not only
      dramatically lowers the impact of using a text-only format, but also
      makes it possible to bundle arbitrary size or amount of attachments
      together.</t>
      <t>However, email lacks structure, except in very niche applications like
      meeting requests, which renders it non-suitable for most of instant
      messaging applications.</t>
      <t>The history of instant messaging so far makes it obvious that it's not
      possible to foresee all actions a client may implement. For example, at
      the height of its popularity, the MSN client famously let its users shake
      the windows of their peers. WhatsApp is very good at sending plain-text
      messages, but Snapchat came up with stickers and expiring messages, which
      other clients eventually had to implement.</t>
      <t>Any system that seeks to unify message exchange must be flexible
      enough to capture and encode any current and future needs of messaging
      applications.</t>
    </section>
    <section anchor="mimi-ink-format">
      <name>MIMI-INK format</name>
      <t>We propose the MIMI-INK format, message/mimi-ink, to be renamed to
      message/mimi if it gets standardized, which is made of the following
      primitives:</t>
      <ol spacing="compact">
        <li>A dict of headers. It "MUST" contain the defining entry named
        "Root-Content-Id", among other ones.</li>
        <li>An optional message body in any number of formats. It's supposed to
        describe the purpose of the message for clients that don't support the
        attached structure, though of course it can be anything.</li>
        <li>At least one blob that contains the main data structure with 
        <tt>Content-Id: [Root-Content-Id-Value]</tt>defined in the message
        headers. This is called the "root content".</li>
        <li>Zero or more additional blobs that may be referenced from inside
        the main structure for any reason.</li>
      </ol>
      <t>In MIME terms;</t>
      <ul spacing="compact">
        <li>headers with at least Root-Content-Id: XYZ and Content-Type:
        message/mimi-ink</li>
        <li>
          <t>multipart/mixed</t>
          <ul spacing="compact">
            <li>
              <t>multipart/alternative</t>
              <ul spacing="compact">
                <li>text/html</li>
                <li>text/plain</li>
                <li>etc.</li>
              </ul>
            </li>
            <li>
              <t>multipart/mixed</t>
              <ul spacing="compact">
                <li>one of application/{xml,json,msgpack,etc} with
                content-id="XYZ"</li>
                <li>one or more binary objects</li>
              </ul>
            </li>
          </ul>
        </li>
      </ul>
      <t>The root content must at least denote a namespace, name and actual
      content. An optional errorcode could also be included, if the content
      designates an error message. The client "MUST" validate the content
      according to the information given in namespace/name values and refuse to
      process the message by resorting to interpret it a regular email message
      with attachments.</t>
      <t>Some examples:</t>
      <ul spacing="compact">
        <li>
          <eref target="https://github.com/plq/mimi/blob/main/reaction.eml">
          https://github.com/plq/mimi/blob/main/reaction.eml</eref>
        </li>
        <li>
          <eref target="https://github.com/plq/mimi/blob/main/vibrate.eml">
          https://github.com/plq/mimi/blob/main/vibrate.eml</eref>
        </li>
      </ul>
      <t>We omitted non-essential JMAP properties for sake of simplicity.</t>
      <t>The mimi-ink repository contains software that converts the MIME
      structure to the suggested jmap structure. It is assumed that there is a
      1-to-1 releation between the MIME representation and the JMAP
      representation of a message, even though that's not correct -- whatever
      gets lost in translations is not of interest.</t>
      <t>The following key differences exist with the JMAP Email object:</t>
      <ol spacing="compact">
        <li>Uses msgpack for the outermost layer instead of JSON.</li>
        <li>The "content" property was added to represent inline data where
        appropriate.</li>
        <li>The root content needs to represent an abstract structure,
        serialized as any popular format (json, xml, msgpack, etc.).</li>
        <li>Add an XML-like namespacing structure so that both
        standards-compliant and proprietary objects can coexist. Or force the
        inner layer to be XML?</li>
        <li>Not technically a difference, but: Using a message body with a
        well-defined structure makes the recursivity of the outer layer
        (JMAP/MIME) redundant. This kind of structure can be realized inside
        the payload.</li>
      </ol>
    </section>
    <section anchor="rationale">
      <name>Rationale</name>
      <section anchor="msgpack">
        <name>Msgpack</name>
        <t>msgpack is;</t>
        <ol spacing="compact">
          <li>Binary</li>
          <li>Simple to implement: Here's an implementation in ~400 lines of
          python: 
          <eref target="https://github.com/plq/msgpack-python-pure/blob/master/msgpack_pure/_core.py">
          https://github.com/plq/msgpack-python-pure/blob/master/msgpack_pure/_core.py</eref></li>
          <li>Supports enough primitives to be useful: null, true, false,
          int64, uint64, float32, float64, string, bytearray, list, map</li>
          <li>Doesn't overstep its boundaries by defining complex types like
          Date</li>
        </ol>
        <t>However, there is stuff that needs to be further/better
        specified:</t>
        <ol spacing="compact">
          <li>msgpack doesn't have a standard way of defining a schema. We
          could just imitate the relevant bits of XSD.</li>
          <li>As said above, there is no standard way of serializing complex
          objects like dates.</li>
          <li>It's very easy to prepend headers to MIME, which eg. makes it
          very easy to trace its origins via 
          <tt>Received</tt>headers. "Patching" msgpack like this doesn't seem
          practical. However, it's quite easy to tell concatenated msgpack
          objects apart. So it may be desirable to specify MIMI as a bunch of
          concatenated msgpack objects instead of just one object containing
          everything.</li>
        </ol>
        <t>If there is a simpler binary format that provides equivalent
        functionality, it could be adopted instead. msgpack is not a hard
        requirement here but does have interesting properties that make it a
        strong contender.</t>
      </section>
      <section anchor="doing-away-with-recursivity">
        <name>Doing away with recursivity</name>
        <ul spacing="compact">
          <li>Recursive formats like MIME/JMAP add a great deal of flexibility
          to the wrong layer.</li>
          <li>MIMI outer shell needs to be as simple as possible. If a complex
          message bundle is needed, it can be easily expressed by the inner
          structure(s).</li>
          <li>MIMI objects can be nested as attachments and the clients could
          choose to interpret it further down anyway.</li>
        </ul>
      </section>
    </section>
    <section anchor="content">
      <name>Content</name>
      <section anchor="object-definitions">
        <name>Object definitions</name>
        <t>When specified in onion-like layers like this, the object
        definitions become the subject of another standard. It's off-topic
        here.</t>
      </section>
      <section anchor="validation">
        <name>Validation</name>
        <t>To standardize how clients could validate incoming content, we need
        to specify or choose a schema language first. XML is the clear winner
        as the inner format here as it already has everything, including
        widespread software support.</t>
      </section>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>The inner format may require IANA to maintain a supported MIMI object
      types registry.</t>
    </section>
  </middle>
  <back>
    <references>
      <name>Normative References</name>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml" />
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8621.xml" />
    </references>
    <references>
      <name>Informative References</name>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml" />
    </references>
  </back>
</rfc>
