Qore Mime Module Reference 1.7
Loading...
Searching...
No Matches
Mime Namespace Reference

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

Classes

hashdecl  FormDataMessageInfo
 parsed form-data message part info More...
 
hashdecl  MessageInfo
 message and part info hash More...
 
hashdecl  MessagePartInfo
 message part hash More...
 
class  MultiPartAlternativeMessage
 implements the MultiPartAlternativeMessage class, a specialization of MultiPartMessage More...
 
class  MultiPartByteRangesMessage
 implements the MultiPartByteRangesMessage class for HTTP partial content responses (RFC 2616) More...
 
class  MultiPartDigestMessage
 implements the MultiPartDigestMessage class for email digests (RFC 2046 section 5.1.5) More...
 
class  MultiPartEncryptedMessage
 implements the MultiPartEncryptedMessage class for encrypted messages (RFC 1847 section 2.2) More...
 
class  MultiPartFormDataMessage
 implements the MultiPartFormDataMessage class, a specialization of MultiPartMessage More...
 
class  MultiPartMessage
 MultiPartMessage class implementation. More...
 
class  MultiPartMessageMessage
 implements the MultiPartMessageMessage class for encapsulating RFC 822 messages More...
 
class  MultiPartMixedMessage
 implements the MultiPartMixedMessage class, a specialization of MultiPartMessage More...
 
class  MultiPartRelatedMessage
 implements the MultiPartRelatedMessage class, a specialization of MultiPartMessage More...
 
class  MultiPartSignedMessage
 implements the MultiPartSignedMessage class for signed messages (RFC 1847 section 2.1) More...
 

Functions

string get_mime_type_from_ext (string path, string def_type)
 returns the mime type for the given filename from the extension or the default type if the extension is not present or unknown
 
bool is_filename_text (string path)
 Returns True if the given filename / path is known to provide text content, False if not.
 
bool is_mime_json (string mime)
 Returns True if the MIME type is JSON-compatible.
 
bool is_mime_text (string mime)
 Returns True if the given MIME type is known to provide text content, False if not.
 
binary mime_decode_base64 (data str)
 returns a binary value from a string in "BASE64" encoding
 
string mime_decode_base64_to_string (data str, soft< string > encoding)
 returns a string value from a string in "BASE64" encoding
 
string mime_decode_header (string hdr)
 decodes a header string
 
string mime_decode_quoted_printable (soft< bool > is_body, string str, soft< string > encoding)
 returns a string parsed from "quoted-printable" (or "QP") encoding
 
data mime_decode_transfer_data (soft< bool > is_body, soft< string > ct, data mime_data, string enc)
 decodes data according to the given encoding
 
string mime_decode_urlencoded_string (string str)
 decodes the given string from URL encoded format
 
string mime_encode_base64 (data str, int len)
 returns a string in "BASE64" encoding according to RFC 2045
 
string mime_encode_header_word_b (string str)
 returns a string in "B" ("BASE64") encoding for MIME header string words
 
string mime_encode_header_word_q (string str)
 returns a string in "Q" ("quoted-printable") encoding for MIME header string words
 
string mime_encode_quoted_printable (string str, bool hdr, soft< string > encoding)
 returns a string in "quoted-printable" (or "QP") encoding
 
data mime_encode_transfer_data (data mime_data, string enc)
 encodes data according to the given encoding
 
string mime_get_form_urlencoded_string (hash< auto > h)
 returns a string in MIME multipart form URL encoded format (for use with "Content-Type: application/x-www-form-urlencoded" data)
 
string mime_get_urlencoded_string (auto val)
 Returns a single string in MIME URL encoded format.
 
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)
 

Variables

const auto ContentTransEnc7Bit = ...
 default Content-Transfer-Encoding if none is present; implies lines < 1000 chars (= no encoding)
 
const auto ContentTransEnc8Bit = ...
 implies lines < 1000 chars (= no encoding)
 
const auto ContentTransEncBase64 = ...
 base-64 Content-Transfer-Encoding
 
const auto ContentTransEncBinary = ...
 binary transfer encoding; implies no maximum line length (= no encoding)
 
const auto ContentTransEncQuotedPrintable = ...
 quoted-printable Content-Transfer-Encoding
 
const auto MimeBase64LineLen = ...
 maximum line length for base64 encoding
 
const auto MimeQuotedPrintableLineLen = ...
 maximum line length for quoted-printable encoding
 
const auto MimeTypeCss = ...
 Mime type for css.
 
const auto MimeTypeCsv = ...
 MIME type for csv files (http://tools.ietf.org/html/rfc4180)
 
const auto MimeTypeFormUrlEncoded = ...
 Mime type for multipart form URL encoding.
 
const auto MimeTypeHtml = ...
 MIME type for HTML.
 
const auto MimeTypeJar = ...
 Mime type for Java jar files.
 
const auto MimeTypeJava = ...
 Mime type for Java class files.
 
const auto MimeTypeJavascript = ...
 Mime type for Javascript.
 
const auto MimeTypeJavaSource = ...
 Mime type for Java sources.
 
const auto MimeTypeJpeg = ...
 MIME type for jpeg images.
 
const auto MimeTypeJson = ...
 Mime type for JSON.
 
const auto MimeTypeJsonRpc = ...
 Mime type for JSON-RPC.
 
const auto MimeTypeMessage = ...
 Mime type for RFC 822 messages.
 
const auto MimeTypeMultipartAlternative = ...
 Mime type for multipart alternative.
 
const auto MimeTypeMultipartByteranges = ...
 Mime type for multipart byteranges (HTTP partial content)
 
const auto MimeTypeMultipartDigest = ...
 Mime type for multipart digest.
 
const auto MimeTypeMultipartEncrypted = ...
 Mime type for multipart encrypted (RFC 1847)
 
const auto MimeTypeMultipartFormData = ...
 Mime type for multipart form data.
 
const auto MimeTypeMultipartMixed = ...
 Mime type for multipart mixed.
 
const auto MimeTypeMultipartRelated = ...
 Mime type for multipart related.
 
const auto MimeTypeMultipartSigned = ...
 Mime type for multipart signed (RFC 1847)
 
const auto MimeTypeOctetStream = ...
 MIME type for unknown file types.
 
const auto MimeTypePdf = ...
 Mime type for PDF documents.
 
const auto MimeTypePhp = ...
 Mime type for PHP sources.
 
const auto MimeTypePng = ...
 MIME type for png images.
 
const auto MimeTypePython = ...
 Mime type for Python sources.
 
const auto MimeTypePythonCode = ...
 Mime type for Python compiled code.
 
const auto MimeTypeQore = ...
 Mime type for Qore sources.
 
const auto 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 auto MimeTypesJson = ...
 Set of MIME types that are JSON-compatible (can be parsed with parse_json())
 
const auto MimeTypeSoapXml = ...
 Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023)
 
const auto MimeTypeSse = ...
 Mime type for server-sent events.
 
const auto MimeTypeSvg = ...
 Mime type for SVG files.
 
const auto MimeTypeText = ...
 MIME type for text.
 
const auto MimeTypeUnknown = ...
 MIME type for unknown file types.
 
const auto MimeTypeXml = ...
 Mime type for plain (human-readable) xml files.
 
const auto MimeTypeXmlApp = ...
 Mime type for more complicated (not human-readable) xml files.
 
const auto MimeTypeXmlRpc = ...
 Mime type for XML-RPC.
 
const auto MimeTypeYaml = ...
 Mime type for yaml data files.
 
const auto MimeTypeYamlRpc = ...
 Mime type for YAML-RPC.
 
const auto MPT_ALTERNATIVE = ...
 for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5.1.4)
 
const auto MPT_BYTERANGES = ...
 for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616)
 
const auto MPT_DIGEST = ...
 for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1.5)
 
const auto MPT_ENCRYPTED = ...
 for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
 
const auto MPT_FORM_DATA = ...
 for form data (http://tools.ietf.org/html/rfc1867, http://tools.ietf.org/html/rfc2388)
 
const auto MPT_MESSAGE = ...
 for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
 
const auto MPT_MIXED = ...
 for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5.1.3)
 
const auto MPT_RELATED = ...
 for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387)
 
const auto MPT_SIGNED = ...
 to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2.1)
 
const auto UrlEncodedChars = ...
 hash of non-alphanumeric characters that can be used unencoded in URL encoded format
 

Detailed Description

public Mime namespace defines constants and functions relevant to MIME

Function Documentation

◆ is_filename_text()

bool Mime::is_filename_text ( string  path)

Returns True if the given filename / path is known to provide text content, False if not.

Parameters
pathThe filename or path to test
Returns
True if the given filename / path is known to provide text content, False if not
Since
Mime 1.6

◆ is_mime_json()

bool Mime::is_mime_json ( string  mime)

Returns True if the MIME type is JSON-compatible.

Parameters
mimethe MIME type to check (may include charset and other modifiers which are stripped)
Returns
True if the MIME type can be parsed as JSON

◆ is_mime_text()

bool Mime::is_mime_text ( string  mime)

Returns True if the given MIME type is known to provide text content, False if not.

Parameters
mimeThe MIME type to test
Returns
True if the given MIME type is known to provide text content, False if not
Since
Mime 1.6

◆ 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
strthe 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,
soft< string >  encoding 
)

returns a string value from a string in "BASE64" encoding

According to RFC 2045

Parameters
strthe string to decode
encodingthe 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
hdrthe header value string to decode
Returns
the decoded value of the header

◆ mime_decode_quoted_printable()

string Mime::mime_decode_quoted_printable ( soft< bool >  is_body,
string  str,
soft< string >  encoding 
)

returns a string parsed from "quoted-printable" (or "QP") encoding

According to RFC 2045 section 6.7

Parameters
strthe string to decode
encodingthe character encoding to use for the string returned (if not present the default encoding is used)
is_bodyif true then the string is treated as a body (underscores are not converted to spaces)
Exceptions
QUOTED-PRINTABLE-DECODE-ERRORan error occurred decoding the quoted-printable string

◆ mime_decode_transfer_data()

data Mime::mime_decode_transfer_data ( soft< bool >  is_body,
soft< string >  ct,
data  mime_data,
string  enc 
)

decodes data according to the given encoding

Parameters
mime_datathe data to decode
encthe decoding to use; see MimeContentTransferEncodingConstants for possible values (case is ignored)
ctthe 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
is_bodyif true then the data is treated as a body for quoted-printable decoding
Exceptions
MIME-TRANSFER-ENCODING-ERRORunknown transfer encoding

◆ mime_decode_urlencoded_string()

string Mime::mime_decode_urlencoded_string ( string  str)

decodes the given string from URL encoded format

Parameters
strthe URL encoded string to decode
Returns
the decoded string
See also
RFC 2738 2.2
Since
  • Mime 1.3.4.1
  • Mime 1.4.1 this function is a wrapper for builtin function decode_url()

◆ mime_encode_base64()

string Mime::mime_encode_base64 ( data  str,
int  len 
)

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

Parameters
strthe string to encode
lenthe maximum line length
Note
this function is basically just a wrapper for the standard Qore function make_base64_string()

◆ mime_encode_header_word_b()

string Mime::mime_encode_header_word_b ( string  str)

returns a string in "B" ("BASE64") encoding for MIME header string words

According to RFC 2047

◆ mime_encode_header_word_q()

string Mime::mime_encode_header_word_q ( string  str)

returns a string in "Q" ("quoted-printable") encoding for MIME header string words

According to RFC 2047

◆ mime_encode_quoted_printable()

string Mime::mime_encode_quoted_printable ( string  str,
bool  hdr,
soft< string >  encoding 
)

returns a string in "quoted-printable" (or "QP") encoding

According to RFC 2045 section 6.7

Parameters
strthe string to encode
hdruse rules for a MIME header (RFC 2047)
encodingthe character encoding to use for header encoding

◆ mime_encode_transfer_data()

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

encodes data according to the given encoding

Parameters
mime_datathe data to encode
encthe encoding to use; see MimeContentTransferEncodingConstants for possible values (case is ignored)
Exceptions
MIME-TRANSFER-ENCODING-ERRORunknown transfer encoding

◆ mime_get_form_urlencoded_string()

string Mime::mime_get_form_urlencoded_string ( hash< auto >  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
hthe hash to use to generate the string
Returns
a string in application/x-www-form-urlencoded format
Exceptions
URLENCODED-TYPE-ERRORhash value cannot be converted to a string
INVALID-CHARACTERan 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.

The string is converted to UTF-8, if necessary, and then the encoded version is returned; reserved characters are replaced with percent encoding, characters outside the ASCII character are encoded with their UTF-8 bytes with binary encoding (ex: "%C3%B6" for "รถ")

Parameters
valthe input value
Returns
the output string in MIME URL encoded format
Exceptions
INVALID-VALUEthe value given cannot be converted to a string
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
strthe 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-ERRORcannot parse the given string
See also
RFC 2738 2.2
Since
Mime 1.3.4.1

Variable Documentation

◆ MimeBase64LineLen

const auto Mime::MimeBase64LineLen = ...

maximum line length for base64 encoding

RFC 2045 section 6.8

◆ MimeQuotedPrintableLineLen

const auto Mime::MimeQuotedPrintableLineLen = ...

maximum line length for quoted-printable encoding

RFC 2045 section 6.7

◆ MimeTypesJson

const auto Mime::MimeTypesJson = ...

Set of MIME types that are JSON-compatible (can be parsed with parse_json())

These MIME types represent JSON or JSON-derived formats that can be deserialized using the standard parse_json() function.

◆ UrlEncodedChars

const auto Mime::UrlEncodedChars = ...

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