Mime Namespace Reference

public Mime namespace defines constants and functions relevant to MIME More...

## Classes

struct | FormDataMessageInfo
| parsed form-data message part info More...
struct | MessageInfo
| message and part info hash More...
struct | MessagePartInfo
| message part hash More...
class | MultiPartFormDataMessage
| implements the MultiPartFormDataMessage class, a specialization of MultiPartMessage More...
class | MultiPartMessage
| MultiPartMessage class implementation. More...
class | MultiPartMixedMessage
| implements the MultiPartMixedMessage class, a specialization of MultiPartMessage More...
class | MultiPartRelatedMessage
| implements the MultiPartRelatedMessage class, a specialization of MultiPartMessage More...

## Functions

string | get_mime_type_from_ext (string path, string def_type=MimeTypeUnknown)
| returns the mime type for the given filename from the extension or the default type if the extension is not present or unknown
binary | mime_decode_base64 (data str)
| returns a binary value from a string in "BASE64" encoding according to RFC 2045 More...
string | mime_decode_base64_to_string (data str, *string encoding)
| returns a string value from a string in "BASE64" encoding according to RFC 2045 More...
string | mime_decode_header (string hdr)
| decodes a header string; if any part of the string is encoded with "B" ("BASE64") or "Q" ("quoted-printable") encodings according to RFC 2045 section 6.7, then those parts are decoded and the decoded string is returned More...
string | mime_decode_quoted_printable (string str, *string encoding)
| returns a string parsed from "quoted-printable" (or "QP") encoding according to RFC 2045 section 6.7 More...
data | mime_decode_transfer_data (data mime_data, string enc, *string ct)
| decodes data according to the given encoding More...
string | mime_decode_urlencoded_string (string str)
| decodes the given string from URL encoded format More...
string | mime_encode_base64 (data str, int len=MimeBase64LineLen)
| returns a string in "BASE64" encoding according to RFC 2045 More...
string | mime_encode_header_word_b (string str)
| returns a string in "B" ("BASE64") encoding for MIME header string words according to RFC 2047
string | mime_encode_header_word_q (string str)
| returns a string in "Q" ("quoted-printable") encoding for MIME header string words according to RFC 2047
string | mime_encode_quoted_printable (string str, bool hdr=False)
| returns a string in "quoted-printable" (or "QP") encoding according to RFC 2045 section 6.7 More...
data | mime_encode_transfer_data (data mime_data, string enc)
| encodes data according to the given encoding More...
string | mime_get_form_urlencoded_string (hash h)
| returns a string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data) More...
string | mime_get_urlencoded_string (auto val)
| returns a single string in MIME URL encoded format More...
hash< auto > | mime_parse_form_urlencoded_string (string str)
| returns a hash corresponding to the string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data) More...

## Variables

const | ContentTransEnc7Bit = "7bit"
| default Content-Transfer-Encoding if none is present; implies lines < 1000 chars (= no encoding)
const | ContentTransEnc8Bit = "8bit"
| implies lines < 1000 chars (= no encoding)
const | ContentTransEncBase64 = "base64"
| base-64 Content-Transfer-Encoding
const | ContentTransEncBinary = "binary"
| binary transfer encoding; implies no maximum line length (= no encoding)
const | ContentTransEncQuotedPrintable = "quoted-printable"
| quoted-printable Content-Transfer-Encoding
const | MimeBase64LineLen = 76
| maximum line length for base64 encoding More...
const | MimeQuotedPrintableLineLen = 76
| maximum line length for quoted-printable encoding More...
const | MimeTypeCss = "text/css"
| Mime type for css.
const | MimeTypeCsv = "text/csv"
| MIME type for csv files (http://tools.ietf.org/html/rfc4180)
const | MimeTypeFormUrlEncoded = "application/x-www-form-urlencoded"
| Mime type for multipart form URL encoding.
const | MimeTypeHtml = "text/html"
| MIME type for HTML.
const | MimeTypeJavascript = "application/javascript"
| Mime type for Javascript.
const | MimeTypeJpeg = "image/jpeg"
| MIME type for jpeg images.
const | MimeTypeJson = "application/json"
| Mime type for JSON.
const | MimeTypeJsonRpc = MimeTypeJson
| Mime type for JSON-RPC.
const | MimeTypeMultipartFormData = "multipart/form-data"
| Mime type for multipart form data.
const | MimeTypeMultipartMixed = "multipart/mixed"
| Mime type for multipart mixed.
const | MimeTypeMultipartRelated = "multipart/related"
| Mime type for multipart related.
const | MimeTypeOctetStream = "application/octet-stream"
| MIME type for unknown file types.
const | MimeTypePng = "image/png"
| MIME type for png images.
const | MimeTypes
| A map of default mime types per file extension; the hash keys are file extensions in lower-case without the dot (ex: `"txt"`)
const | MimeTypeSoapXml = "application/soap+xml"
| Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023)
const | MimeTypeText = "text/plain"
| MIME type for text.
const | MimeTypeUnknown = MimeTypeOctetStream
| MIME type for unknown file types.
const | MimeTypeXml = "text/xml"
| Mime type for plain (human-readable) xml files.
const | MimeTypeXmlApp = "application/xml"
| Mime type for more complicated (not human-readable) xml files.
const | MimeTypeXmlRpc = MimeTypeXml
| Mime type for XML-RPC.
const | MimeTypeYaml = "text/x-yaml"
| Mime type for yaml data files.
const | MimeTypeYamlRpc = "application/x-yaml"
| Mime type for YAML-RPC.
const | MPT_ALTERNATIVE = "alternative"
| for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5.1.4)
const | MPT_BYTERANGES = "byteranges"
| for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616)
const | MPT_DIGEST = "digest"
| for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1.5)
const | MPT_ENCRYPTED = "encrypted"
| for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
const | MPT_FORM_DATA = "form-data"
| for form data (http://tools.ietf.org/html/rfc1867, http://tools.ietf.org/html/rfc2388)
const | MPT_MESSAGE = "message"
| for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
const | MPT_MIXED = "mixed"
| for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5.1.3)
const | MPT_RELATED = "related"
| for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387)
const | MPT_SIGNED = "signed"
| to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2.1)
const | UrlEncodedChars
| hash of non-alphanumeric characters that can be used unencoded in URL encoded format More...

## Detailed Description

public Mime namespace defines constants and functions relevant to MIME

## Function Documentation

## mime_decode_base64()

binary Mime::mime_decode_base64 | ( | data | str | ) |

returns a binary value from a string in "BASE64" encoding according to RFC 2045

Parameters

  str | the string to decode

Note
  this function is basically just a wrapper for the standard Qore function parse_base64_string()

## mime_decode_base64_to_string()

string Mime::mime_decode_base64_to_string | ( | data | str,
|  | *string | encoding
| ) |  |

returns a string value from a string in "BASE64" encoding according to RFC 2045

Parameters

  str | the string to decode
  encoding | the character encoding to use for the string returned (if not present the default encoding is used)

Note
  this function is basically just a wrapper for the standard Qore function parse_base64_string_to_string()

## mime_decode_header()

string Mime::mime_decode_header | ( | string | hdr | ) |

decodes a header string; if any part of the string is encoded with "B" ("BASE64") or "Q" ("quoted-printable") encodings according to RFC 2045 section 6.7, then those parts are decoded and the decoded string is returned

Parameters

  hdr | the header value string to decode

Returns
  the decoded value of the header

## mime_decode_quoted_printable()

string Mime::mime_decode_quoted_printable | ( | string | str,
|  | *string | encoding
| ) |  |

returns a string parsed from "quoted-printable" (or "QP") encoding according to RFC 2045 section 6.7

Parameters

  str | the string to decode
  encoding | the character encoding to use for the string returned (if not present the default encoding is used)

Exceptions

  QUOTED-PRINTABLE-DECODE-ERROR | an error occurred decoding the quoted-printable string

## mime_decode_transfer_data()

data Mime::mime_decode_transfer_data | ( | data | mime_data,
|  | string | enc,
|  | *string | ct
| ) |  |

decodes data according to the given encoding

Parameters

  mime_data | the data to decode
  enc | the decoding to use; see MIME Content Transfer Encoding Constants for possible values (case is ignored)
  ct | the content-type of the data; if there is a `"charset=xxx"` component and the data is decoded to a string, then it will be returned in the given character encoding

Exceptions

  MIME-TRANSFER-ENCODING-ERROR | unknown transfer encoding

## mime_decode_urlencoded_string()

string Mime::mime_decode_urlencoded_string | ( | string | str | ) |

decodes the given string from URL encoded format

Parameters

  str | the URL encoded string to decode

Returns
  the decoded string

See also
  RFC 2738 2.2

Since
  Mime 1.3.4.1

## mime_encode_base64()

string Mime::mime_encode_base64 | ( | data | str,
|  | int | len = `MimeBase64LineLen`
| ) |  |

returns a string in "BASE64" encoding according to RFC 2045

Parameters

  str | the string to encode
  len | the maximum line length

Note
  this function is basically just a wrapper for the standard Qore function make_base64_string()

## mime_encode_quoted_printable()

string Mime::mime_encode_quoted_printable | ( | string | str,
|  | bool | hdr = `False`
| ) |  |

returns a string in "quoted-printable" (or "QP") encoding according to RFC 2045 section 6.7

Parameters

  str | the string to encode
  hdr | use rules for a MIME header (RFC 2047)

## mime_encode_transfer_data()

data Mime::mime_encode_transfer_data | ( | data | mime_data,
|  | string | enc
| ) |  |

encodes data according to the given encoding

Parameters

  mime_data | the data to encode
  enc | the encoding to use; see MIME Content Transfer Encoding Constants for possible values (case is ignored)

Exceptions

  MIME-TRANSFER-ENCODING-ERROR | unknown transfer encoding

## mime_get_form_urlencoded_string()

string Mime::mime_get_form_urlencoded_string | ( | hash | h | ) |

returns a string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)

Parameters will be separated by `"&"` characters. All key values must be strings or convertible to strings or a URLENCODED-TYPE-ERROR exception is thrown

Parameters

  h | the hash to use to generate the string

Returns
  a string in `application/x-www-form-urlencoded` format

Exceptions

  URLENCODED-TYPE-ERROR | hash value cannot be converted to a string
  INVALID-CHARACTER | an invalid character has been found

See also
  RFC 2738 2.2

Since
  Mime 1.3.4.1

## mime_get_urlencoded_string()

string Mime::mime_get_urlencoded_string | ( | auto | val | ) |

returns a single string in MIME URL encoded format

reserved characters are replaced with percent encoding, characters outside the ASCII character set cause an exception to be thrown

Parameters

  val | the input value

Returns
  the output string in MIME URL encoded format

Exceptions

  INVALID-VALUE | the value given cannot be converted to a string
  INVALID-CHARACTER | an invalid character has been found

See also
  RFC 2738 2.2

Note
  spaces are not replaced with `'+'` signs but rather encoded as `%20` because `'+'` signs are often encoded and decoded improperly in URLs, and `%20` is unambiguous

Since
  Mime 1.3.4.1

## mime_parse_form_urlencoded_string()

hash<auto> Mime::mime_parse_form_urlencoded_string | ( | string | str | ) |

returns a hash corresponding to the string in MIME multipart form URL encoded format (for use with `"Content-Type: application/x-www-form-urlencoded"` data)

Parameters

  str | the string to parse

Returns
  the hash corresponding to the string, where values are always of type *string unlessa key is repeated, in which case the key's value will be a list of all elements provided

Exceptions

  URLENCODED-PARSE-ERROR | cannot parse the given string

See also
  RFC 2738 2.2

Since
  Mime 1.3.4.1

## Variable Documentation

## MimeBase64LineLen

const Mime::MimeBase64LineLen = 76

maximum line length for base64 encoding

RFC 2045 section 6.8

## MimeQuotedPrintableLineLen

const Mime::MimeQuotedPrintableLineLen = 76

maximum line length for quoted-printable encoding

RFC 2045 section 6.7

## UrlEncodedChars

const Mime::UrlEncodedChars

Initial value:
= (
"\$": True,
"-": True,
"_": True,
".": True,
"!": True,
"*": True,
"'": True,
"(": True,
")": True,
",": True
)

hash of non-alphanumeric characters that can be used unencoded in URL encoded format

Note
  the plus character can also appear unencoded in a URL string, but because many decoders interpret it as a space (which is it in the query part of a URL string), it's not in this list

See also
  RFC 2738 2.2

True
const True