Mime.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file Mime.qm Mime module definition
/* Mime.qm Copyright (C) 2012 - 2015 David Nichols
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum required Qore version
// assume local var scope, do not use "$" for vars, members, and method calls
namespace Mime {
const MimeTypeUnknown = MimeTypeOctetStream;
const MimeTypeOctetStream = "application/octet-stream";
const MimeTypeText = "text/plain";
const MimeTypeHtml = "text/html";
const MimeTypeCsv = "text/csv";
const MimeTypeJpeg = "image/jpeg";
const MimeTypePng = "image/png";
const MimeTypeSoapXml = "application/soap+xml";
const MimeTypeYaml = "text/x-yaml";
const MimeTypeXml = "text/xml";
const MimeTypeXmlApp = "application/xml";
const MimeTypeJson = "application/json";
const MimeTypeJsonRpc = MimeTypeJson;
const MimeTypeXmlRpc = MimeTypeXml;
const MimeTypeYamlRpc = "application/x-yaml";
const MimeTypeJavascript = "application/javascript";
const MimeTypeCss = "text/css";
const MimeTypes = (
"7z": "application/x-7z-compressed",
"ai": "application/postscript",
"aif": "audio/x-aiff",
"aifc": "audio/x-aiff",
"aiff": "audio/x-aiff",
"asc": MimeTypeText,
"atom": "application/atom+xml",
"au": "audio/basic",
"avi": "video/x-msvideo",
"bcpio": "application/x-bcpio",
"bin": MimeTypeUnknown,
"bmp": "image/bmp",
"bz2": "application/x-bzip",
"cc": MimeTypeText,
"cdf": "application/x-netcdf",
"cgm": "image/cgm",
"class": MimeTypeUnknown,
"cpio": "application/x-cpio",
"cpp": MimeTypeText,
"cpt": "application/mac-compactpro",
"csh": "application/x-csh",
"css": MimeTypeCss,
"csv": MimeTypeCsv,
"dcr": "application/x-director",
"dif": "video/x-dv",
"dir": "application/x-director",
"djv": "image/vnd.djvu",
"djvu": "image/vnd.djvu",
"dll": MimeTypeUnknown,
"dmg": MimeTypeUnknown,
"dms": MimeTypeUnknown,
"doc": "application/msword",
"dtd": "application/xml-dtd",
"dv": "video/x-dv",
"dvi": "application/x-dvi",
"dxr": "application/x-director",
"eps": "application/postscript",
"etx": "text/x-setext",
"exe": MimeTypeUnknown,
"ez": "application/andrew-inset",
"gif": "image/gif",
"gram": "application/srgs",
"grxml": "application/srgs+xml",
"gtar": "application/x-gtar",
"gz": "application/x-gzip",
"h": MimeTypeText,
"hdf": "application/x-hdf",
"hh": MimeTypeText,
"hpp": MimeTypeText,
"hqx": "application/mac-binhex40",
"htm": MimeTypeHtml,
"html": MimeTypeHtml,
"ice": "x-conference/x-cooltalk",
"ico": "image/x-icon",
"ics": "text/calendar",
"ief": "image/ief",
"ifb": "text/calendar",
"iges": "model/iges",
"igs": "model/iges",
"jar": "application/java-archive",
"java": MimeTypeText,
"jnlp": "application/x-java-jnlp-file",
"jp2": "image/jp2",
"jpe": MimeTypeJpeg,
"jpeg": MimeTypeJpeg,
"jpg": MimeTypeJpeg,
"js": MimeTypeJavascript,
"kar": "audio/midi",
"latex": "application/x-latex",
"lha": MimeTypeUnknown,
"lzh": MimeTypeUnknown,
"m3u": "audio/x-mpegurl",
"m4a": "audio/mp4a-latm",
"m4b": "audio/mp4a-latm",
"m4p": "audio/mp4a-latm",
"m4u": "video/vnd.mpegurl",
"m4v": "video/x-m4v",
"mac": "image/x-macpaint",
"man": "application/x-troff-man",
"mathml": "application/mathml+xml",
"me": "application/x-troff-me",
"mesh": "model/mesh",
"mid": "audio/midi",
"midi": "audio/midi",
"mif": "application/vnd.mif",
"mov": "video/quicktime",
"movie": "video/x-sgi-movie",
"mp2": "audio/mpeg",
"mp3": "audio/mpeg",
"mp4": "video/mp4",
"mpe": "video/mpeg",
"mpeg": "video/mpeg",
"mpg": "video/mpeg",
"mpga": "audio/mpeg",
"ms": "application/x-troff-ms",
"msh": "model/mesh",
"mxu": "video/vnd.mpegurl",
"nc": "application/x-netcdf",
"oda": "application/oda",
"ogg": "application/ogg",
"pbm": "image/x-portable-bitmap",
"pct": "image/pict",
"pdb": "chemical/x-pdb",
"pdf": "application/pdf",
"pgm": "image/x-portable-graymap",
"pgn": "application/x-chess-pgn",
"pic": "image/pict",
"pict": "image/pict",
"png": MimeTypePng,
"pnm": "image/x-portable-anymap",
"pnt": "image/x-macpaint",
"pntg": "image/x-macpaint",
"ppm": "image/x-portable-pixmap",
"ppt": "application/vnd.ms-powerpoint",
"ps": "application/postscript",
// Qore script
"q": MimeTypeText,
// Qore class include file
"qc": MimeTypeText,
// Qorus function definition file
"qfd": MimeTypeText,
// Qorus class definition file
"qclass": MimeTypeText,
// Qorus constant definition file
"qconst": MimeTypeText,
// Qorus job definition
"qjob": MimeTypeText,
// Qore include file
"ql": MimeTypeText,
// Qore user module source
"qm": MimeTypeText,
// Qorus service definition
"qsd": MimeTypeText,
// Qorus workflow definition
"qwf": MimeTypeText,
"qt": "video/quicktime",
"qti": "image/x-quicktime",
"qtif": "image/x-quicktime",
"ra": "audio/x-pn-realaudio",
"ram": "audio/x-pn-realaudio",
"ras": "image/x-cmu-raster",
"rdf": "application/rdf+xml",
"rgb": "image/x-rgb",
"rm": "application/vnd.rn-realmedia",
"roff": "application/x-troff",
"rtf": "text/rtf",
"rtx": "text/richtext",
"sgm": "text/sgml",
"sgml": "text/sgml",
"sh": "application/x-sh",
"shar": "application/x-shar",
"silo": "model/mesh",
"sit": "application/x-stuffit",
"skd": "application/x-koan",
"skm": "application/x-koan",
"skp": "application/x-koan",
"skt": "application/x-koan",
"smi": "application/smil",
"smil": "application/smil",
"snd": "audio/basic",
"so": MimeTypeUnknown,
"spl": "application/x-futuresplash",
"src": "application/x-wais-source",
"sv4cpio": "application/x-sv4cpio",
"sv4crc": "application/x-sv4crc",
"svg": "image/svg+xml",
"swf": "application/x-shockwave-flash",
"t": "application/x-troff",
"tar": "application/x-tar",
"tar.bz2": "application/x-bzip-compressed-tar",
"tar.gz": "application/x-tar-gz",
"tbz": "application/x-bzip-compressed-tar",
"tcl": "application/x-tcl",
"tex": "application/x-tex",
"texi": "application/x-texinfo",
"texinfo": "application/x-texinfo",
"text": MimeTypeText,
"tgz": "application/x-tar-gz",
"tif": "image/tiff",
"tiff": "image/tiff",
"tr": "application/x-troff",
"tsv": "text/tab-separated-values",
"txt": MimeTypeText,
"ustar": "application/x-ustar",
"vcd": "application/x-cdlink",
"vrml": "model/vrml",
"vxml": "application/voicexml+xml",
"wav": "audio/x-wav",
"wbmp": "image/vnd.wap.wbmp",
"wbmxl": "application/vnd.wap.wbxml",
"wml": "text/vnd.wap.wml",
"wmlc": "application/vnd.wap.wmlc",
"wmls": "text/vnd.wap.wmlscript",
"wmlsc": "application/vnd.wap.wmlscriptc",
"wrl": "model/vrml",
"wsdl": "application/wsdl+xml",
"xbm": "image/x-xbitmap",
"xht": "application/xhtml+xml",
"xhtml": "application/xhtml+xml",
"xls": "application/vnd.ms-excel",
"xml": MimeTypeXml,
"xpm": "image/x-xpixmap",
"xsd": MimeTypeXml,
"xsl": "application/xml",
"xslt": "application/xslt+xml",
"xul": "application/vnd.mozilla.xul+xml",
"xwd": "image/x-xwindowdump",
"xyz": "chemical/x-xyz",
"yaml": MimeTypeYaml,
"zip": "application/zip",
);
const ContentTransEnc7Bit = "7bit";
const ContentTransEnc8Bit = "8bit";
const ContentTransEncBinary = "binary";
const ContentTransEncBase64 = "base64";
const ContentTransEncQuotedPrintable = "quoted-printable";
const MimeBase64LineLen = 76;
const MimeQuotedPrintableLineLen = 76;
string mime_encode_base64(data str, int len = MimeBase64LineLen);
string mime_encode_quoted_printable(string str, bool hdr = False);
data mime_encode_transfer_data(data data, string enc);
string mime_encode_header_word_b(string str);
string mime_encode_header_word_q(string str);
binary mime_decode_base64(data str);
string mime_decode_base64_to_string(data str, *string encoding);
string mime_decode_quoted_printable(string str, *string encoding);
data mime_decode_transfer_data(data data, string enc, *string ct);
string mime_decode_header(string hdr);
string get_mime_type_from_ext(string path);
const MPT_FORM_DATA = "form-data";
const MPT_MIXED = "mixed";
const MPT_MESSAGE = "message";
const MPT_DIGEST = "digest";
const MPT_ALTERNATIVE = "alternative";
const MPT_RELATED = "related";
const MPT_SIGNED = "signed";
const MPT_ENCRYPTED = "encrypted";
const MPT_BYTERANGES = "byteranges";
class MultiPartMessage {
public:
const MP_DEFAULT_MSG = "This is a MIME multipart message";
private :
string mptype;
string boundary;
string ct;
list l = ();
hash hdr;
public:
constructor(string n_mptype, string n_boundary = MultiPartMessage::getBoundary());
static string getBoundary();
static string getRandomString(int len);
static hash parseBody(string boundary, string body, bool decode = True);
binary serialize();
static binary serializeHeaders(hash hdr);
abstract hash getMsgAndHeaders();
// don't reimplement this method; fix/enhance it in the module
final private hash getMsgAndHeadersIntern(*string content_type, bool conlen = True);
// don't reimplement this method; fix/enhance it in the module
private splicePartIntern(data data, hash hdr);
// don't reimplement this method; fix/enhance it in the module
private addPartIntern(data data, hash hdr);
private:
static hash getPart(data data, hash hdr);
public:
};
class MultiPartRelatedMessage : public MultiPartMessage {
public:
private :
// the starting part ID
string startid;
public:
constructor(string boundary = MultiPartMessage::getBoundary()) ;
splicePart(data data, string id, string content_type, *hash hdr);
addPart(data data, string id, string content_type, *hash hdr);
hash getMsgAndHeaders();
};
class MultiPartMixedMessage : public MultiPartMessage {
public:
constructor(string boundary = MultiPartMessage::getBoundary()) ;
splicePart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
addPart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
spliceEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
addEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
hash getMsgAndHeaders();
};
};
Mime::MPT_RELATED
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387) ...
Definition: Mime.qm.dox.h:538
Mime::mime_encode_transfer_data
data mime_encode_transfer_data(data data, string enc)
encodes data according to the given encoding
Mime::MimeTypeJpeg
const MimeTypeJpeg
MIME type for jpeg images.
Definition: Mime.qm.dox.h:135
Mime::MultiPartRelatedMessage::constructor
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
Mime::MultiPartMixedMessage::constructor
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
Mime::MPT_MESSAGE
const MPT_MESSAGE
for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
Definition: Mime.qm.dox.h:529
Mime::mime_encode_header_word_q
string mime_encode_header_word_q(string str)
returns a string in "Q" ("quoted-printable") encoding for MIME header string words according to RFC 2...
Mime::ContentTransEnc8Bit
const ContentTransEnc8Bit
implies lines < 1000 chars (= no encoding)
Definition: Mime.qm.dox.h:405
Mime::MultiPartMessage
MultiPartMessage class implementation.
Definition: Mime.qm.dox.h:551
Mime::MimeTypeYaml
const MimeTypeYaml
Mime type for yaml data files.
Definition: Mime.qm.dox.h:144
Mime::MimeTypeXml
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition: Mime.qm.dox.h:147
Mime::MPT_ENCRYPTED
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition: Mime.qm.dox.h:544
Mime::mime_encode_quoted_printable
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...
Mime::MultiPartMessage::serializeHeaders
static binary serializeHeaders(hash hdr)
serializes a header hash to a binary object
Mime::MultiPartMixedMessage::addEncodePart
addEncodePart(data data, string enc, string content_type=MimeTypeText, string disp="inline", *hash hdr)
adds a message part to the end of the list; encodes the data according to the transfer encoding argum...
True
const True
Mime::MultiPartMixedMessage
implements a MultiPartMixedMessage class, a specialization of MultiPartMessage
Definition: Mime.qm.dox.h:744
Mime::MPT_ALTERNATIVE
const MPT_ALTERNATIVE
for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5...
Definition: Mime.qm.dox.h:535
binary
binary binary()
Mime::MimeTypeJsonRpc
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition: Mime.qm.dox.h:156
Mime::MPT_BYTERANGES
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616) ...
Definition: Mime.qm.dox.h:547
Mime::MimeTypeJson
const MimeTypeJson
Mime type for JSON.
Definition: Mime.qm.dox.h:153
Mime::MPT_SIGNED
const MPT_SIGNED
to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2.1)
Definition: Mime.qm.dox.h:541
Mime::ContentTransEncBase64
const ContentTransEncBase64
base-64 Content-Transfer-Encoding
Definition: Mime.qm.dox.h:411
Mime::MultiPartMessage::serialize
binary serialize()
serializes the message and returns a binary object ready to send over a socket
Mime::MimeTypePng
const MimeTypePng
MIME type for png images.
Definition: Mime.qm.dox.h:138
Mime::MimeQuotedPrintableLineLen
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition: Mime.qm.dox.h:424
False
const False
Mime::MimeTypeJavascript
const MimeTypeJavascript
Mime type for Javascript.
Definition: Mime.qm.dox.h:165
list
list list(...)
Mime::mime_decode_base64_to_string
string mime_decode_base64_to_string(data str, *string encoding)
returns a string value from a string in "BASE64" encoding according to RFC 2045
Mime::MultiPartRelatedMessage
implements a MultiPartRelatedMessage class, a specialization of MultiPartMessage
Definition: Mime.qm.dox.h:695
Mime::MultiPartMixedMessage::splicePart
splicePart(data data, string content_type=MimeTypeText, string disp="inline", *hash hdr)
adds a message part to the start of the list; the data muyst already be encoded and any Content-Trans...
Mime::MimeTypeOctetStream
const MimeTypeOctetStream
MIME type for unknown file types.
Definition: Mime.qm.dox.h:123
Mime::MimeTypeCss
const MimeTypeCss
Mime type for css.
Definition: Mime.qm.dox.h:168
Mime::mime_decode_header
string mime_decode_header(string hdr)
decodes a header string; if any part of the string is encoded with "B" ("BASE64") or "Q" ("quoted-pri...
Mime::mime_decode_base64
binary mime_decode_base64(data str)
returns a binary value from a string in "BASE64" encoding according to RFC 2045
Mime::MimeTypeYamlRpc
const MimeTypeYamlRpc
Mime type for YAML-RPC.
Definition: Mime.qm.dox.h:162
Mime::MultiPartMessage::getMsgAndHeaders
abstract hash getMsgAndHeaders()
returns a hash of the message
Mime::MimeTypeXmlRpc
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition: Mime.qm.dox.h:159
Mime::get_mime_type_from_ext
string get_mime_type_from_ext(string path)
returns the mime type for the given filename from the extension or MimeTypeUnknown if the extension i...
Mime::MPT_MIXED
const MPT_MIXED
for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5...
Definition: Mime.qm.dox.h:526
Mime::mime_encode_base64
string mime_encode_base64(data str, int len=MimeBase64LineLen)
returns a string in "BASE64" encoding according to RFC 2045
Mime::MultiPartRelatedMessage::splicePart
splicePart(data data, string id, string content_type, *hash hdr)
adds a message part to the start of the list
Mime::MPT_DIGEST
const MPT_DIGEST
for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1.5)
Definition: Mime.qm.dox.h:532
Mime::MPT_FORM_DATA
const MPT_FORM_DATA
for form data (http://tools.ietf.org/html/rfc1867, http://tools.ietf.org/html/rfc2388) ...
Definition: Mime.qm.dox.h:523
Mime::MultiPartMixedMessage::spliceEncodePart
spliceEncodePart(data data, string enc, string content_type=MimeTypeText, string disp="inline", *hash hdr)
adds a message part to the start of the list; encodes the data according to the transfer encoding arg...
Mime::ContentTransEncQuotedPrintable
const ContentTransEncQuotedPrintable
quoted-printable Content-Transfer-Encoding
Definition: Mime.qm.dox.h:414
Mime::MultiPartMixedMessage::getMsgAndHeaders
hash getMsgAndHeaders()
returns a hash of the message
Mime::mime_encode_header_word_b
string mime_encode_header_word_b(string str)
returns a string in "B" ("BASE64") encoding for MIME header string words according to RFC 2047 ...
Mime::MultiPartMessage::parseBody
static hash parseBody(string boundary, string body, bool decode=True)
returns a hash representing a parsed multipart message body from a boundary string and body arguments...
Mime::MultiPartMessage::getRandomString
static string getRandomString(int len)
returns a string of random characters
Mime::mime_decode_transfer_data
data mime_decode_transfer_data(data data, string enc, *string ct)
decodes data according to the given encoding
Mime
public Mime namespace defines constants and functions relevant to MIME
Definition: Mime.qm.dox.h:115
Mime::MimeBase64LineLen
const MimeBase64LineLen
maximum line length for base64 encoding
Definition: Mime.qm.dox.h:419
Mime::MultiPartMessage::constructor
constructor(string n_mptype, string n_boundary=MultiPartMessage::getBoundary())
creates the object
Mime::MultiPartRelatedMessage::getMsgAndHeaders
hash getMsgAndHeaders()
returns a hash of the message
Mime::MimeTypeHtml
const MimeTypeHtml
MIME type for HTML.
Definition: Mime.qm.dox.h:129
Mime::MimeTypes
const MimeTypes
A map of default mime types per file extension; the hash keys are file extensions in lower-case witho...
Definition: Mime.qm.dox.h:173
Mime::MultiPartMessage::getBoundary
static string getBoundary()
returns a string embedded with the current timestamp designed to be used as MultiPart boundary string...
hash
hash hash(object obj)
Mime::MimeTypeSoapXml
const MimeTypeSoapXml
Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023) ...
Definition: Mime.qm.dox.h:141
Mime::ContentTransEncBinary
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition: Mime.qm.dox.h:408
Mime::MimeTypeXmlApp
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition: Mime.qm.dox.h:150
Mime::ContentTransEnc7Bit
const ContentTransEnc7Bit
default Content-Transfer-Encoding if none is present; implies lines < 1000 chars (= no encoding) ...
Definition: Mime.qm.dox.h:402
Mime::MimeTypeCsv
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition: Mime.qm.dox.h:132
Mime::MultiPartRelatedMessage::addPart
addPart(data data, string id, string content_type, *hash hdr)
adds a message part to the end of the list
Mime::MultiPartMixedMessage::addPart
addPart(data data, string content_type=MimeTypeText, string disp="inline", *hash hdr)
adds a message part to the end of the list; the data muyst already be encoded and any Content-Transfe...
Mime::MimeTypeText
const MimeTypeText
MIME type for text.
Definition: Mime.qm.dox.h:126
Mime::mime_decode_quoted_printable
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...