Mime Module

# Introduction to the Mime Module

The Mime module provides definitions and functions related to MIME processing. MIME concepts are used in HTTP and SMTP communications, among others.

To use this module, use `"%requires Mime"` in your code. See the SmtpClient and the HttpServer modules for examples of Qore code using this module.

All the public symbols in the module are defined in the Mime namespace

The main definitions and functions are:

- MimeTypeDefinitions: constant for common MIME types
- MimeTypes: a map of common file name extensions to the default MIME type
- MimeEncodingFunctions: functions for encoding MIME data
- MimeDecodingFunctions: functions for decoding MIME data
- MultiPartConstants: constants for the MultiPartMessage classes
- MultiPartMessage: the base class for MultiPartMessage classes
  - MultiPartMessage::parseBody(): use this static function to parse multipart message bodies (including parts that themselves have parts if the decode argument is True); this static method can be used for both HTTP multipart messages or text multipart messages (for example as sent in an email/SMTP message)
- MultiPartRelatedMessage: a class for handling multipart/related messages

based on:

- http://tools.ietf.org/html/rfc1521: quoted printable & base 64 transfer encodings
- http://tools.ietf.org/html/rfc2045: mime headers, content types, etc
- http://tools.ietf.org/html/rfc2047: "Q" and "B" encoded words (implemented by the Mime module)

Example:
  #!/usr/bin/env qore
  %requires Mime
  string str = "This is a test: æéìœü";
  printf("%y: quoted printable: %y\n", mime_decode_quoted_printable(mime_encode_quoted_printable(str)), mime_encode_quoted_printable(str));
  printf("%y: base64: %y\n", mime_decode_base64_to_string(mime_encode_base64(str)), mime_encode_base64(str));
  printf("%y: header word q: %y\n", mime_decode_header(mime_encode_header_word_q(str)), mime_encode_header_word_q(str));
  printf("%y: header word b: %y\n", mime_decode_header(mime_encode_header_word_b(str)), mime_encode_header_word_b(str));
  The output of the above example looks like:

      "This is a test: æéìœü": quoted printable: "This is a test: =C3=A6=C3=A9=C3=AC=C5=93=C3=BC"
      "This is a test: æéìœü": base64: "VGhpcyBpcyBhIHRlc3Q6IMOmw6nDrMWTw7w="
      "This is a test: æéìœü": header word q: "=?UTF-8?Q?This_is_a_test:_=C3=A6=C3=A9=C3=AC=C5=93=C3=BC?="
      "This is a test: æéìœü": header word b: "=?UTF-8?B?VGhpcyBpcyBhIHRlc3Q6IMOmw6nDrMWTw7w=?="

# Release Notes

## v1.3.4

- added dependency on the Util module
- replaced Mime::MultiPartMessage::getRandomString() with Util::get_random_string()
- converted to new-style

## v1.3.3

- added Mime::MimeTypeOctetStream constant

## v1.3.2

- added mime type for WSDL files (`"application/wsdl+xml"`)
- added mappings for xls and xlst extensions to Mime::MimeTypes

## v1.3.1

- added Mime::get_mime_type_from_ext()
- minor corrections
- added constants for css and js files + more extension -> mime type mappings

## v1.3

- made get Mime::MultiPartMessage::getMsgAndHeaders() abstract as originally intended
- added Mime::MultiPartMessage::parseBody() static method

## v1.2.1

- fixed q-encoding mail headers (always encode '_' chars otherwise they will be decoded as spaces)

## v1.2

- added MIME decoding functions

## v1.1

- added initial Mime::MultiPartMessage classes

## v1.0

- pulled MIME implementation out of other code and made a user module to aggregate MIME definitions and functions