All Classes Namespaces Functions Variables Groups Pages
Mime.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file Mime.qm Mime module definition
/* Mime.qm Copyright 2012 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.
*/
/* Version History
* 2012-11-02 v1.3: David Nichols <david@qore.org>
+ made get MultiPartMessage::getMsgAndHeaders() abstract as originally intended
+ added MultiPartMessage::parseBody() static method
* 2012-09-17 v1.2.1: David Nichols <david@qore.org>
+ fixed q-encoding mail headers (always encode '_' chars otherwise they will be decoded as spaces)
* 2012-06-14 v1.2: David Nichols <david@qore.org>
+ added MIME decoding functions
* 2012-05-31 v1.1: David Nichols <david@qore.org>
+ added initial MultiPartMessage classes
* 2012-05-24 v1.0: David Nichols <david@qore.org>
+ pulled MIME implementation out of other code and made a user module to aggregate MIME definitions and functions
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)
*/
namespace Mime {
const MimeTypeUnknown = "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 MimeTypeJsonRpc = "application/json";
const MimeTypeXmlRpc = MimeTypeXml;
const MimeTypeYamlRpc = "application/x-yaml";
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": "text/css",
"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": "application/x-javascript",
"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,
// Qore include file
"ql": MimeTypeText,
// Qore user module source
"qm": 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",
"xbm": "image/x-xbitmap",
"xht": "application/xhtml+xml",
"xhtml": "application/xhtml+xml",
"xls": "application/vnd.ms-excel",
"xml": MimeTypeXml,
"xpm": "image/x-xpixmap",
"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);
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 mptype, string 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
private:
final hash getMsgAndHeadersIntern(*string content_type, bool conlen = True);
public:
// don't reimplement this method; fix/enhance it in the module
private:
splicePartIntern(data data, hash hdr);
public:
// don't reimplement this method; fix/enhance it in the module
private:
addPartIntern(data data, hash hdr);
public:
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();
};
};