home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / rfc / 1500s / rfc1563.txt < prev    next >
Text File  |  1994-01-06  |  33KB  |  899 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                      N. Borenstein
  8. Request for Comments: 1563                                      Bellcore
  9. Obsoletes: 1523                                             January 1994
  10. Category: Informational
  11.  
  12.  
  13.                   The text/enriched MIME Content-type
  14.  
  15. Status of this Memo
  16.  
  17.    This memo provides information for the Internet community.  This memo
  18.    does not specify an Internet standard of any kind.  Distribution of
  19.    this memo is unlimited.
  20.  
  21. Abstract
  22.  
  23.    MIME [RFC-1341, RFC-1521] defines a format and general framework for
  24.    the representation of a wide variety of data types in Internet mail.
  25.    This document defines one particular type of MIME data, the
  26.    text/enriched type, a refinement of the "text/richtext" type defined
  27.    in RFC 1341.  The text/enriched MIME type is intended to facilitate
  28.    the wider interoperation of simple enriched text across a wide
  29.    variety of hardware and software platforms.
  30.  
  31. Table of Contents
  32.  
  33.    The Text/enriched MIME type..............................  2
  34.    Formatting Commands......................................  4
  35.          Font-Alteration Commands...........................  4
  36.          Fill/Justification Commands........................  5
  37.          Indentation Commands...............................  6
  38.          Miscellaneous Commands.............................  6
  39.          Balancing and Nesting of Formatting Commands.......  7
  40.          Unrecognized formatting commands...................  8
  41.    White Space in Text/enriched Data........................  8
  42.    Initial State of a text/enriched interpreter.............  8
  43.    Non-ASCII character sets.................................  8
  44.    Minimal text/enriched conformance........................  9
  45.    Notes for Implementors...................................  9
  46.    Extensions to text/enriched.............................. 10
  47.    An Example............................................... 11
  48.    Security Considerations.................................. 12
  49.    Author's Address......................................... 12
  50.    Acknowledgements......................................... 12
  51.    References............................................... 12
  52.    Appendix A -- A Simple enriched-to-plain Translator in C. 13
  53.    Appendix B -- Differences from RFC 1341 text/richtext.... 15
  54.  
  55.  
  56.  
  57.  
  58. Borenstein                                                      [Page 1]
  59.  
  60. RFC 1563             A text/enriched type for MIME          January 1994
  61.  
  62.  
  63. The Text/enriched MIME type
  64.  
  65.    In order to promote the wider interoperability of simple formatted
  66.    text, this document defines an extremely simple subtype of the MIME
  67.    content-type "text", the "text/enriched" subtype.  This subtype was
  68.    designed to meet the following criteria:
  69.  
  70.       1.  The syntax must be extremely simple to parse,
  71.           so that even teletype-oriented mail systems can
  72.           easily strip away the formatting information and
  73.           leave only the readable text.
  74.  
  75.       2.  The syntax must be extensible to allow for new
  76.           formatting commands that are deemed essential for
  77.           some application.
  78.  
  79.       3.  If the character set in use is ASCII or an 8-
  80.           bit ASCII superset, then the raw form of the data
  81.           must be readable enough to be largely
  82.           unobjectionable in the event that it is displayed
  83.           on the screen of the user of a non-MIME-conformant
  84.           mail reader.
  85.  
  86.       4.  The capabilities must be extremely limited, to
  87.           ensure that it can represent no more than is
  88.           likely to be representable by the user's primary
  89.           word processor.  While this limits what can be
  90.           sent, it increases the likelihood that what is
  91.           sent can be properly displayed.
  92.  
  93.    This document defines a new MIME content-type, "text/enriched".  The
  94.    content-type line for this type may have one optional parameter, the
  95.    "charset" parameter, with the same values permitted for the
  96.    "text/plain" MIME content-type.
  97.  
  98.    The syntax of "text/enriched" is very simple.  It represents text in
  99.    a single character set -- US-ASCII by default, although a different
  100.    character set can be specified by the use of the "charset" parameter.
  101.    (The semantics of text/enriched in non-ASCII character sets are
  102.    discussed later in this document.)  All characters represent
  103.    themselves, with the exception of the "<" character (ASCII 60), which
  104.    is used to mark the beginning of a formatting command.  Formatting
  105.    instructions consist of formatting commands surrounded by angle
  106.    brackets ("<>", ASCII 60 and 62).  Each formatting command may be no
  107.    more than 60 characters in length, all in US-ASCII, restricted to the
  108.    alphanumeric and hyphen ("-") characters.  Formatting commands may be
  109.    preceded by a solidus ("/", ASCII 47), making them negations, and
  110.    such negations must always exist to balance the initial opening
  111.  
  112.  
  113.  
  114. Borenstein                                                      [Page 2]
  115.  
  116. RFC 1563             A text/enriched type for MIME          January 1994
  117.  
  118.  
  119.    commands.  Thus, if the formatting command "<bold>" appears at some
  120.    point, there must later be a "</bold>" to balance it.  (NOTE: The 60
  121.    character limit on formatting commands does NOT include the "<", ">",
  122.    or "/" characters that might be attached to such commands.)
  123.  
  124.    Formatting commands are always case-insensitive.  That is, "bold" and
  125.    "BoLd" are equivalent in effect, if not in good taste.
  126.  
  127.    Beyond tokens delimited by "<" and ">", there are two other special
  128.    processing rules.  First, a literal less-than sign ("<") can be
  129.    represented by a sequence of two such characters, "<<".  Second, line
  130.    breaks (CRLF pairs in standard network representation) are handled
  131.    specially.  In particular, isolated CRLF pairs are translated into a
  132.    single SPACE character.  Sequences of N consecutive CRLF pairs,
  133.    however, are translated into N-1 actual line breaks.  This permits
  134.    long lines of data to be represented in a natural- looking manner
  135.    despite the frequency of line-wrapping in Internet mailers.  When
  136.    preparing the data for mail transport, isolated line breaks should be
  137.    inserted wherever necessary to keep each line shorter than 80
  138.    characters.  When preparing such data for presentation to the user,
  139.    isolated line breaks should be replaced by a single SPACE character,
  140.    and N consecutive CRLF pairs should be presented to the user as N-1
  141.    line breaks.
  142.  
  143.    Thus text/enriched data that looks like this:
  144.  
  145.                  This is
  146.                  a single
  147.                  line
  148.  
  149.                  This is the
  150.                  next line.
  151.  
  152.  
  153.                  This is the
  154.                  next paragraph.
  155.  
  156.    should be displayed by a text/enriched interpreter as follows:
  157.  
  158.  
  159.                  This is a single line
  160.                  This is the next line.
  161.  
  162.                  This is the next paragraph.
  163.  
  164.    The formatting commands, not all of which will be implemented by all
  165.    implementations, are described in the following sections.
  166.  
  167.  
  168.  
  169.  
  170. Borenstein                                                      [Page 3]
  171.  
  172. RFC 1563             A text/enriched type for MIME          January 1994
  173.  
  174.  
  175. Formatting Commands
  176.  
  177.    The text/enriched formatting commands all begin with <commandname>
  178.    and end with </commandname>, affecting the formatting of the text
  179.    between those two tokens.  The commands are described here, grouped
  180.    according to type.
  181.  
  182. Font-Alteration Commands
  183.  
  184.    The following formatting commands are intended to alter the font in
  185.    which text is displayed, but not to alter the indentation or
  186.    justification state of the text:
  187.  
  188.          Bold -- causes the affected text to be in a bold font.  Nested
  189.               bold commands have the same effect as a single bold
  190.               command.
  191.  
  192.          Italic -- causes the affected text to be in an italic font.
  193.               Nested italic commands have the same effect as a single
  194.               italic command.
  195.  
  196.          Fixed -- causes the affected text to be in a fixed width font.
  197.               Nested fixed commands have the same effect as a single
  198.               fixed command.
  199.  
  200.          Smaller -- causes the affected text to be in a smaller font.
  201.               It is recommended that the font size be changed by two
  202.               points, but other amounts may be more appropriate in some
  203.               environments.  Nested smaller commands produce ever-
  204.               smaller fonts, to the limits of the implementation's
  205.               capacity to reasonably display them, after which further
  206.               smaller commands have no incremental effect.
  207.  
  208.          Bigger -- causes the affected text to be in a bigger font.  It
  209.               is recommended that the font size be changed by two
  210.               points, but other amounts may be more appropriate in some
  211.               environments.  Nested bigger commands produce ever-bigger
  212.               fonts, to the limits of the implementation's capacity to
  213.               reasonably display them, after which further bigger
  214.               commands have no incremental effect.
  215.  
  216.          Underline -- causes the affected text to be underlined.  Nested
  217.               underline commands have the same effect as a single
  218.               underline command.
  219.  
  220.    While the "bigger" and "smaller" operators are effectively inverses,
  221.    it is not recommended, for example, that "<smaller>" be used to end
  222.    the effect of "<bigger>".  This is properly done with "</bigger>".
  223.  
  224.  
  225.  
  226. Borenstein                                                      [Page 4]
  227.  
  228. RFC 1563             A text/enriched type for MIME          January 1994
  229.  
  230.  
  231. Fill/Justification Commands
  232.  
  233.    Initially, text/enriched text is intended to be displayed fully
  234.    filled with appropriate kerning and letter-tracking as suits the
  235.    capabilities of the receiving user agent software.  Actual line width
  236.    is left to the discretion of the receiver, which is expected to fold
  237.    lines intelligently (preferring soft line breaks) to the best of its
  238.    ability.
  239.  
  240.    The following commands alter that state.  Each of these commands
  241.    force a line break before and after the formatting environment if
  242.    there is not otherwise a line break.  For example, if one of these
  243.    commands occurs anywhere other than the beginning of a line of text
  244.    as presented, a new line is begun.
  245.  
  246.       Center -- causes the affected text to be centered.
  247.  
  248.       FlushLeft -- causes the affected text to be left-justified with a
  249.            ragged right margin.
  250.  
  251.       FlushRight -- causes the affected text to be right-justified with a
  252.            ragged left margin.
  253.  
  254.       FlushBoth -- causes the affected text to be filled and padded so
  255.            as to create smooth left and right margins, i.e., to be
  256.            fully justified.
  257.  
  258.       Nofill -- causes the affected text to be displayed without filling
  259.            or justification.
  260.  
  261.    The center, flushleft, flushright, and flushboth commands are
  262.    mutually exclusive, and, when nested, the inner command takes
  263.    precedence.
  264.  
  265.    Whether or not text is justified by default (that is, whether the
  266.    default environment is flushleft, flushright, or flushboth) is
  267.    unspecified, and depends on the preferences of the user, the
  268.    capabilities of the local software and hardware, and the nature of
  269.    the character set in use.  On systems where justification is
  270.    considered undesirable, the flushboth environment may be identical to
  271.    the default environment.  Note that justification should never be
  272.    performed inside of center, flushleft, flushright, or nofill
  273.    environments.  Note also that for some non-ASCII character sets, full
  274.    justification may be fundamentally inappropriate.
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. Borenstein                                                      [Page 5]
  283.  
  284. RFC 1563             A text/enriched type for MIME          January 1994
  285.  
  286.  
  287. Indentation Commands
  288.  
  289.    Initially, text/enriched text is displayed using the maximum
  290.    available margins.  Two formatting commands may be used to affect the
  291.    margins.
  292.  
  293.          Indent -- causes the running left margin to be moved to the
  294.               right.  The recommended indentation change is the width of
  295.               four characters, but this may differ among
  296.               implementations.
  297.  
  298.          IndentRight -- causes the running right margin to be moved to
  299.               the left.  The recommended indentation change is the width
  300.               of four characters, but this may differ among
  301.               implementations.
  302.  
  303.    A line break is NOT forced by a change of the margin, to permit the
  304.    description of "hanging" text.  Thus for example the following text:
  305.  
  306.    Now <indent> is the time for all good horses to come to the aid of
  307.    their stable, assuming that </indent> any stable is really stable.
  308.  
  309.    would be displayed in a 40-character-wide window as follows:
  310.  
  311.                Now is the time for all good horses to
  312.                    come to the aid of their stable,
  313.                    assuming that any stable is
  314.                really stable.
  315.  
  316. Miscellaneous Commands
  317.  
  318.          Excerpt -- causes the affected text to be interpreted as a
  319.               textual excerpt from another source, probably a message
  320.               being responded to.  Typically this will be displayed
  321.               using indentation and an alternate font, or by indenting
  322.               lines and preceding them with "> ", but such decisions are
  323.               up to the implementation.  (Note that this is the only
  324.               truly declarative markup construct in text/enriched, and
  325.               as such doesn't fit very well with the other facilities,
  326.               but it describes a type of markup that is very commonly
  327.               used in email and has no procedural analogue.)  Note that
  328.               as with the justification commands, the excerpt command
  329.               implicitly begins and ends with a line break if one is not
  330.               already there.
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338. Borenstein                                                      [Page 6]
  339.  
  340. RFC 1563             A text/enriched type for MIME          January 1994
  341.  
  342.  
  343.          Param -- Marks the affected text as command parameters, to be
  344.               interpreted or ignored by the text/enriched interpreter,
  345.               but NOT to be shown to the reader.  The syntax of the
  346.               parameter data (whatever appears between the initial
  347.               "<param>" and the terminating "</param>") is left
  348.               undefined by this memo, to be defined by text/enriched
  349.               extensions in the future.  However, the format of such
  350.               data must NOT contain nested <param> commands, and either
  351.               must NOT use the "<" character or must use it in a way
  352.               that is compatible with text/enriched parsing.  That is,
  353.               the end of the parameter data should be recognizable with
  354.               EITHER of two algorithms: simply searching for the first
  355.               occurence of "</param>" or parsing until a balanced
  356.               "</param>" command is found.  In either case, however, the
  357.               parameter data should NOT be shown to the human reader.
  358.  
  359. Balancing and Nesting of Formatting Commands
  360.  
  361.    Pairs of formatting commands must be properly balanced and nested.
  362.    Thus, a proper way to describe text in bold italics is:
  363.  
  364.                       <bold><italic>the-text</italic></bold>
  365.  
  366.                  or, alternately,
  367.  
  368.                       <italic><bold>the-text</bold></italic>
  369.  
  370.                  but, in particular, the following is illegal
  371.                  text/enriched:
  372.  
  373.                       <bold><italic>the-text</bold></italic>
  374.  
  375.    The nesting requirement for formatting commands imposes a slightly
  376.    higher burden upon the composers of text/enriched bodies, but
  377.    potentially simplifies text/enriched displayers by allowing them to
  378.    be stack-based.  The main goal of text/enriched is to be simple
  379.    enough to make multifont, formatted email widely readable, so that
  380.    those with the capability of sending it will be able to do so with
  381.    confidence.  Thus slightly increased complexity in the composing
  382.    software was deemed a reasonable tradeoff for simplified reading
  383.    software.  Nonetheless, implementors of text/enriched readers are
  384.    encouraged to follow the general Internet guidelines of being
  385.    conservative in what you send and liberal in what you accept.  Those
  386.    implementations that can do so are encouraged to deal reasonably with
  387.    improperly nested text/enriched data.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Borenstein                                                      [Page 7]
  395.  
  396. RFC 1563             A text/enriched type for MIME          January 1994
  397.  
  398.  
  399. Unrecognized formatting commands
  400.  
  401.    Implementations must regard any unrecognized formatting command as
  402.    "no-op" commands, that is, as commands having no effect, thus
  403.    facilitating future extensions to "text/enriched".  Private
  404.    extensions may be defined using formatting commands that begin with
  405.    "X-", by analogy to Internet mail header field names.
  406.  
  407.    In order to formally define extended commands, a new Internet
  408.    document should be published.
  409.  
  410. White Space in Text/enriched Data
  411.  
  412.    No special behavior is required for the SPACE or TAB (HT) character.
  413.    It is recommended, however, that, at least when fixed-width fonts are
  414.    in use, the common semantics of the TAB (HT) character should be
  415.    observed, namely that it moves to the next column position that is a
  416.    multiple of 8.  (In other words, if a TAB (HT) occurs in column n,
  417.    where the leftmost column is column 0, then that TAB (HT) should be
  418.    replaced by 8-(n mod 8) SPACE characters.)  It should also be noted
  419.    that some mail gateways are notorious for losing (or, less commonly,
  420.    adding) white space at the end of lines, so reliance on SPACE or TAB
  421.    characters at the end of a line is not recommended.
  422.  
  423. Initial State of a text/enriched interpreter
  424.  
  425.    Text/enriched is assumed to begin with filled text in a variable-
  426.    width font in a normal typeface and a size that is average for the
  427.    current display and user.  The left and right margins are assumed to
  428.    be maximal, that is, at the leftmost and rightmost acceptable
  429.    positions.
  430.  
  431. Non-ASCII character sets
  432.  
  433.    If the character set specified by the charset parameter on the
  434.    Content-type line is anything other than "US-ASCII", this means that
  435.    the text being described by text/enriched formatting commands is in a
  436.    non-ASCII character set.  However, the commands themselves are still
  437.    the same ASCII commands that are defined in this document.  This
  438.    creates an ambiguity only with reference to the "<" character, the
  439.    octet with numeric value 60.  In single byte character sets, such as
  440.    the ISO-8859 family, this is not a problem; the octet 60 can be
  441.    quoted by including it twice, just as for ASCII.  The problem is more
  442.    complicated, however, in the case of multi-byte character sets, where
  443.    the octet 60 might appear at any point in the byte sequence for any
  444.    of several characters.
  445.  
  446.  
  447.  
  448.  
  449.  
  450. Borenstein                                                      [Page 8]
  451.  
  452. RFC 1563             A text/enriched type for MIME          January 1994
  453.  
  454.  
  455.    In practice, however, most multibyte character sets address this
  456.    problem internally.  For example, the ISO-2022 family of character
  457.    sets can switch back into ASCII at any moment.  Therefore it is
  458.    specified that, before text/enriched formatting commands, the
  459.    prevailing character set should be "switched back" into ASCII, and
  460.    that only those characters which would be interpreted as "<" in plain
  461.    text should be interpreted as token delimiters in text/enriched.
  462.  
  463.    The question of what to do for hypothetical future character sets
  464.    that do NOT subsume ASCII is not addressed in this memo.
  465.  
  466. Minimal text/enriched conformance
  467.  
  468.    A minimal text/enriched implementation is one that converts "<<" to
  469.    "<", removes everything between a <param> command and the next
  470.    balancing </param> command, removes all other formatting commands
  471.    (all text enclosed in angle brackets), and, outside of <nofill>
  472.    environments, converts any series of n CRLFs to n-1 CRLFs, and
  473.    converts any lone CRLF pairs to SPACE.
  474.  
  475. Notes for Implementors
  476.  
  477.    It is recognized that implementors of future mail systems will want
  478.    rich text functionality far beyond that currently defined for
  479.    text/enriched.  The intent of text/enriched is to provide a common
  480.    format for expressing that functionality in a form in which much of
  481.    it, at least, will be understood by interoperating software.  Thus,
  482.    in particular, software with a richer notion of formatted text than
  483.    text/enriched can still use text/enriched as its basic
  484.    representation, but can extend it with new formatting commands and by
  485.    hiding information specific to that software system in text/enriched
  486.    <param> constructs.  As such systems evolve, it is expected that the
  487.    definition of text/enriched will be further refined by future
  488.    published specifications, but text/enriched as defined here provides
  489.    a platform on which evolutionary refinements can be based.
  490.  
  491.    An expected common way that sophisticated mail programs will generate
  492.    text/enriched data is as part of a multipart/alternative construct.
  493.    For example, a mail agent that can generate enriched mail in ODA
  494.    format can generate that mail in a more widely interoperable form by
  495.    generating both text/enriched and ODA versions of the same data,
  496.    e.g.:
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506. Borenstein                                                      [Page 9]
  507.  
  508. RFC 1563             A text/enriched type for MIME          January 1994
  509.  
  510.  
  511.                  Content-type: multipart/alternative; boundary=foo
  512.  
  513.                  --foo
  514.                  Content-type: text/enriched
  515.  
  516.                  [text/enriched version of data]
  517.                  --foo
  518.                  Content-type: application/oda
  519.  
  520.                  [ODA version of data]
  521.                  --foo--
  522.  
  523.    If such a message is read using a MIME-conformant mail reader that
  524.    understands ODA, the ODA version will be displayed; otherwise, the
  525.    text/enriched version will be shown.
  526.  
  527.    In some environments, it might be impossible to combine certain
  528.    text/enriched formatting commands, whereas in others they might be
  529.    combined easily.  For example, the combination of <bold> and <italic>
  530.    might produce bold italics on systems that support such fonts, but
  531.    there exist systems that can make text bold or italicized, but not
  532.    both.  In such cases, the most recently issued (innermost) recognized
  533.    formatting command should be preferred.
  534.  
  535.    One of the major goals in the design of text/enriched was to make it
  536.    so simple that even text-only mailers will implement enriched-to-
  537.    plain-text translators, thus increasing the likelihood that enriched
  538.    text will become "safe" to use very widely.  To demonstrate this
  539.    simplicity, an extremely simple C program that converts text/enriched
  540.    input into plain text output is included in Appendix A.
  541.  
  542. Extensions to text/enriched
  543.  
  544.    It is expected that various mail system authors will desire
  545.    extensions to text/enriched.  The simple syntax of text/enriched, and
  546.    the specification that unrecognized formatting commands should simply
  547.    be ignored, are intend to promote such extensions.
  548.  
  549.    Beyond simply defining new formatting commands, however, it may
  550.    sometimes be necessary to define formatting commands that can take
  551.    arguments.  This is the intended use of the <param> construct.  In
  552.    particular, software that wished to extend text/enriched to include
  553.    colored text might define an "x-color" environment which always began
  554.    with a color name parameter, to indicate the desired color for the
  555.    affected text.
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562. Borenstein                                                     [Page 10]
  563.  
  564. RFC 1563             A text/enriched type for MIME          January 1994
  565.  
  566.  
  567. An Example
  568.  
  569.    Putting all this together, the following "text/enriched" body
  570.    fragment:
  571.  
  572.                       From: Nathaniel Borenstein <nsb@bellcore.com>
  573.                       To: Ned Freed <ned@innosoft.com>
  574.                       Content-type: text/enriched
  575.  
  576.                       <bold>Now</bold> is the time for
  577.                       <italic>all</italic> good men
  578.                        <smaller>(and <<women>)</smaller> to
  579.                       <ignoreme>come</ignoreme>
  580.  
  581.                       to the aid of their
  582.  
  583.  
  584.                       <x-color><param>red</param>beloved</x-color>
  585.                       country.
  586.  
  587.                       By the way, I think that <<smaller>
  588.  
  589.                       should
  590.  
  591.                       REALLY be called
  592.  
  593.                       <<tinier>
  594.                       and that I am always right.
  595.  
  596.                       -- the end
  597.  
  598.    represents the following formatted text (which will, no doubt, look
  599.    somewhat cryptic in the text-only version of this document):
  600.  
  601.                  Now is the time for all good men (and <women>)  to
  602.                  come
  603.                  to the aid of their
  604.  
  605.                  beloved country.
  606.                  By the way, I think that <smaller>
  607.                  should
  608.                  REALLY be called
  609.                  <tinier>
  610.                  and that I am always right.
  611.                  -- the end
  612.  
  613.    where the word "beloved" would be in red on a color display if the
  614.    receiving software implemented the "x-color" extension.
  615.  
  616.  
  617.  
  618. Borenstein                                                     [Page 11]
  619.  
  620. RFC 1563             A text/enriched type for MIME          January 1994
  621.  
  622.  
  623. Security Considerations
  624.  
  625.    Security issues are not discussed in this memo, as the mechanism
  626.    raises no security issues.
  627.  
  628. Author's Address
  629.  
  630.    For more information, the author of this document may be contacted
  631.    via Internet mail:
  632.  
  633.    Nathaniel S. Borenstein
  634.    MRE 2D-296, Bellcore
  635.    445 South St.
  636.    Morristown, NJ 07962-1910
  637.  
  638.    Phone: +1 201 829 4270
  639.    Fax:  +1 201 829 5963
  640.    EMail: nsb@bellcore.com
  641.  
  642. Acknowledgements
  643.  
  644.    This document reflects the input of many contributors, readers, and
  645.    implementors of the original MIME specification, RFC 1341.  It also
  646.    reflects particular contributions and comments from Terry Crowley,
  647.    Rhys Weatherley, and John LoVerso.
  648.  
  649. References
  650.  
  651.    [RFC-1341] Borenstein, N., and N.  Freed, "MIME (Multipurpose
  652.               Internet Mail Extensions): Mechanisms for Specifying
  653.               and Describing the Format of Internet Message Bodies",
  654.               RFC 1341, Bellcore, Innosoft, June 1992.
  655.  
  656.    [RFC-1521] Borenstein, N., and N.  Freed, "MIME (Multipurpose
  657.               Internet Mail Extensions) Part One: Mechanisms for
  658.               Specifying and Describing the Format of Internet
  659.               Message Bodies", RFC 1521, Bellcore, Innosoft,
  660.               September 1993.
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Borenstein                                                     [Page 12]
  675.  
  676. RFC 1563             A text/enriched type for MIME          January 1994
  677.  
  678.  
  679. Appendix A -- A Simple enriched-to-plain Translator in C
  680.  
  681.    One of the major goals in the design of the text/enriched subtype of
  682.    the text Content-Type is to make formatted text so simple that even
  683.    text-only mailers will implement enriched-to-plain-text translators,
  684.    thus increasing the likelihood that multifont text will become "safe"
  685.    to use very widely.  To demonstrate this simplicity, what follows is
  686.    a simple C program that converts text/enriched input into plain text
  687.    output.  Note that the local newline convention (the single character
  688.    represented by "\n") is assumed by this program, but that special
  689.    CRLF handling might be necessary on some systems.
  690.  
  691. #include <stdio.h>
  692. #include <ctype.h>
  693.  
  694. main() {
  695.     int c, i, paramct=0, newlinect=0, nofill=0;
  696.     char token[62], *p;
  697.  
  698.     while ((c=getc(stdin)) != EOF) {
  699.         if (c == '<') {
  700.             if (newlinect == 1) putc(' ', stdout);
  701.             newlinect = 0;
  702.             c = getc(stdin);
  703.             if (c == '<') {
  704.                 if (paramct <= 0) putc(c, stdout);
  705.             } else {
  706.                   ungetc(c, stdin);
  707.                   for (i=0, p=token; (c=getc(stdin)) != EOF && c != '>';
  708.                   i++)
  709.                   { if (i < sizeof(token)-1)
  710.                     *p++ = isupper(c) ? tolower(c) : c;
  711.                   }
  712.                   *p = '\0';
  713.                   if (c == EOF) break;
  714.                   if (strcmp(token, "param") == 0)
  715.                       paramct++;
  716.                   else if (strcmp(token, "nofill") == 0)
  717.                       nofill++;
  718.                   else if (strcmp(token, "/param") == 0)
  719.                       paramct--;
  720.                   else if (strcmp(token, "/nofill") == 0)
  721.                       nofill--;
  722.               }
  723.         } else {
  724.             if (paramct > 0)
  725.                 ; /* ignore params */
  726.             else if (c == '\n' && nofill <= 0) {
  727.  
  728.  
  729.  
  730. Borenstein                                                     [Page 13]
  731.  
  732. RFC 1563             A text/enriched type for MIME          January 1994
  733.  
  734.  
  735.                 if (++newlinect > 1) putc(c, stdout);
  736.             } else {
  737.                 if (newlinect == 1) putc(' ', stdout);
  738.                 newlinect = 0;
  739.                 putc(c, stdout);
  740.             }
  741.         }
  742.      }
  743.      /* The following line is only needed with line-buffering */
  744.      putc('\n', stdout);
  745.      exit(0);
  746. }
  747.  
  748.    It should be noted that one can do considerably better than this in
  749.    displaying text/enriched data on a dumb terminal.  In particular, one
  750.    can replace font information such as "bold" with textual emphasis
  751.    (like *this* or _T_H_I_S_).  One can also properly handle the
  752.    text/enriched formatting commands regarding indentation,
  753.    justification, and others.  However, the above program is all that is
  754.    necessary in order to present text/enriched on a dumb terminal
  755.    without showing the user any formatting artifacts.
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786. Borenstein                                                     [Page 14]
  787.  
  788. RFC 1563             A text/enriched type for MIME          January 1994
  789.  
  790.  
  791. Appendix B -- Differences from RFC 1341 text/richtext
  792.  
  793.    Text/enriched is a clarification, simplification, and refinement of
  794.    the type defined as text/richtext in RFC 1341.  For the benefit of
  795.    those who are already familiar with text/richtext, or for those who
  796.    want to exploit the similarities to be able to display text/richtext
  797.    data with their text/enriched software, the differences between the
  798.    two are summarized here. Note, however, that text/enriched is
  799.    intended to make text/richtext obsolete, so it is not recommended
  800.    that new software generate text/richtext.
  801.  
  802.    0.  The name "richtext" was changed to "enriched", both to
  803.        differentiate the two versions and because "richtext"
  804.        created widespread confusion with Microsoft's Rich Text
  805.        Format (RTF).
  806.  
  807.    1.  Clarifications.  Many things were ambiguous or
  808.        unspecified in the text/richtext definition, particularly
  809.        the initial state and the semantics of richtext with
  810.        multibyte character sets.  However, such differences are
  811.        OPERATIONALLY irrelevant, since the clarifications offered
  812.        in this document are at least reasonable interpretations of
  813.        the text/richtext specification.
  814.  
  815.    2.  Newline semantics have changed.  In text/richtext, all
  816.        CRLFs were mapped to spaces, and line breaks were indicated
  817.        by "<nl>".  This has been replaced by the "n-1" rule for
  818.        CRLFs.
  819.  
  820.    3.  The representation of a literal "<" character was "<lt>"
  821.        in text/richtext, but is "<<" in text/enriched.
  822.  
  823.    4.  The "nofill" command did not exist in text/richtext.
  824.  
  825.    5.  The "param" command did not exist in text/richtext.
  826.  
  827.    6.  The following commands from text/richtext have been
  828.        REMOVED from text/enriched: <COMMENT>, <OUTDENT>,
  829.        <OUTDENTRIGHT>, <SAMEPAGE>, <SUBSCRIPT>, <SUPERSCRIPT>,
  830.        <HEADING>, <FOOTING>, <ISO-8859-[1-9]>, <US-ASCII>,
  831.        <PARAGRAPH>, <SIGNATURE>, <NO-OP>, <LT>, <NL>, and <NP>.
  832.  
  833.    7.  All claims of SGML compatibility have been dropped.
  834.        However, with the possible exceptions of the new semantics
  835.        for CRLF and "<<" can be implemented, text/enriched should
  836.        be no less SGML-friendly than text/richtext was.
  837.  
  838.  
  839.  
  840.  
  841.  
  842. Borenstein                                                     [Page 15]
  843.  
  844. RFC 1563             A text/enriched type for MIME          January 1994
  845.  
  846.  
  847.    8.  In text/richtext, there were three commands (<NL>, <NP>,
  848.        and <LT>) that did not use balanced closing delimiters.
  849.        Since all of these have been eliminated, there are NO
  850.        exceptions to the nesting/balancing rules in text/enriched.
  851.  
  852.    9.  The limit on the size of formatting tokens has been
  853.        increased from 40 to 60 characters.
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898. Borenstein                                                     [Page 16]
  899.