Indy 9 | Content | Index | Reference

IdMessageCoderMIME.pas
See Also, Classes, Constants
Unit: IdMessageCoderMIME.pas

IdMessageCoderMIME.pas contains types, classes, procedures, functions, and constant variables used to implement coders and decoders for RFC-822 compliant MIME message parts. IdMessageCoderMIME.pas extends the coder framework established in IdCoder.pas.

MIME encoding allows data to be represented in a 7-bit textual representation, called Base64, as described in the Internet Standards document:

- RFC 2045 - Multipurpose Internet Mail Extensions (MIME), Part One: Format of Internet Message Bodies, Section 6.8 Base64 Content-Transfer-Encoding (http://www.rfc-editor.org/rfc/rfc2045.txt)

The MIME, or Base64, encoding mechanism is designed to represent arbitrary sequences of byte data in a form that need not be humanly readable. Base64 encoding is almost identical to the mechanism used in Privacy Enhanced Mail (PEM) applications, as defined in:

- RFC 1421 - Privacy Enhancement for Internet Electronic Mail, Part I: Message Encryption and Authentication Procedures (http://www.rfc-editor.org/rfc/rfc1421.txt)

Base64 encoding uses a 64-character subset of US-ASCII, enabling 6 bits to be represented per printable character. An extra character ("=") has special significance in Base64 encoding. Base64 encoding can represent all version of ISO 646, including US-ASCII, and all characters in the subset are also represented identically in EBCDIC.

Base64 encoding represents 24-bit groups of input as output strings of 4 encoded characters. Proceeding from left to right, a 24-bit input group is formed by concatenating 3 8-bit input groups. These 24 bits are then treated as 4 concatenated 6-bit groups, each of which is translated into a single digit in the base64 alphabet.

Each 6-bit group is used as an index into an array of 64 printable characters. The character referenced by the index is placed in the output string. These characters are selected to be universally representable, and the set excludes characters with particular significance to SMTP (".", CR, LF) and to the multipart boundary delimiters ("-") defined in:

- RFC 2046 - Multipurpose Internet Mail Extensions (MIME), Part Two: Media Types (http://www.rfc-editor.org/rfc/rfc2046.txt)

The following table identifies characters and encodings for the Base64 Alphabet:

          Value Encoding  Value Encoding
          0     A         34    i
          1     B         35    j
          2     C         36    k
          3     D         37    l
          4     E         38    m
          5     F         39    n
          6     G         40    o
          7     H         41    p
          8     I         42    q
          9     J         43    r
          10    K         44    s
          11    L         45    t
          12    M         46    u
          13    N         47    v
          14    O         48    w
          15    P         49    x
          16    Q         50    y
          17    R         51    z
          18    S         52    0
          19    T         53    1
          20    U         54    2
          21    V         55    3
          22    W         56    4
          23    X         57    5
          24    Y         58    6
          25    Z         59    7
          26    a         60    8
          27    b         61    9
          28    c         62    +
          29    d         63    /
          30    e         (pad) =
          31    f
          32    g
          33    h

Base64-encoded output must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in the Base64 alphabet must be ignored by decoding software.

Special processing is performed if fewer than 24 bits are available at the end of the data being encoded. A full encoding quantum is always completed at the end of a body. When fewer than 24 input bits are available in an input group, zero bits are added (on the right) to form an integral number of 6-bit groups. Padding at the end of the data is performed using the "=" character.

Because it is used only for padding at the end of the data, the occurrence of any "=" characters may be taken as evidence that the end of the data has been reached (without truncation in transit). No such assurance is possible, however, when the number of octets transmitted was a multiple of three and no "=" characters are present.

Any characters outside of the Base64 alphabet are to be ignored when present in Base64-encoded data.

Base64 encoding is commonly used in E-Mail and Usenet messages.

Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.