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 "MimeTypeDefinitions": constant for common MIME types
Mime::MimeTypes "MimeTypes": a map of common file name extensions to the default MIME type
MimeEncodingFunctions "MimeEncodingFunctions": functions for encoding MIME data
MimeDecodingFunctions "MimeDecodingFunctions": functions for decoding MIME data
MultiPartConstants "MultiPartConstants": constants for the MultiPartMessage classes
- MultiPartAlternativeMessage: a class for handling multipart/alternative messages
- MultiPartByteRangesMessage: a class for handling HTTP 206 partial content responses
- MultiPartDigestMessage: a class for handling email digests
- MultiPartEncryptedMessage: a class for handling S/MIME and PGP/MIME encrypted messages
- MultiPartFormDataMessage: a class for handling multipart/form-data messages
- MultiPartMessage: the base class for MultiPartMessage classes
Mime::MultiPartMessage::parseBody() "MultiPartMessage::parseBody()": this static function can be used to parse a multipart message body (including parts with subparts 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)
- MultiPartMessageMessage: a class for encapsulating RFC 822 messages
- MultiPartMixedMessage: a class for handling multipart/mixed messages
- MultiPartRelatedMessage: a class for handling multipart/related messages
- MultiPartSignedMessage: a class for handling S/MIME and PGP/MIME signed messages
based on:
- 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.7
- added new multipart message classes:
- added new MIME type constants:
- added the is_mime_json() function and MimeTypesJson constant for detecting JSON-compatible MIME types
- added additional JSON-compatible MIME types to MimeTypesJson:
"application/hal+json", "application/problem+json", "application/merge-patch+json", "application/json-patch+json", "application/geo+json", "application/manifest+json"
- added new file extensions to MimeTypes:
gql, graphql, heic, heif, jsx, md, markdown, rst, sql, toml, ts, tsx, wasm
- fixed incorrect MIME types for
weba (now "audio/webm") and webm (now "video/webm")
- fixed a bug in mime_decode_transfer_data() where the transfer encoding was incorrectly used as a character encoding when decoding base64 and quoted-printable data
- improved type safety by adding explicit type annotations to hash declarations
- added
strict-args, require-types, and enable-all-warnings parse directives
v1.6.1
v1.6
v1.5
- added a constant for SVG types
v1.4.4
v1.4.3
- fixed bugs parsing binary data in multipart messages (issue 4223)
v1.4.2
- fixed bugs parsing binary data in multipart messages (issue 2936)
v1.4.1
v1.4
- added complex type support
- added the following constants:
- added the following methods:
- fixed a bug parsing multipart messages where unnecessary characters were searched (issue 2099)
v1.3.4.1
- added support for generating and parsing MIME multipart form encoded data
v1.3.4
v1.3.3
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
v1.3
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
v1.0
- pulled MIME implementation out of other code and made a user module to aggregate MIME definitions and functions