Qore Mime Module Reference  1.3.4
Mime.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file Mime.qm Mime module definition
3 
4 /* Mime.qm Copyright (C) 2012 - 2015 David Nichols
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // minimum required Qore version
26 
27 
28 // assume local var scope, do not use "$" for vars, members, and method calls
29 
30 
114 namespace Mime {
120  const MimeTypeUnknown = MimeTypeOctetStream;
121 
123  const MimeTypeOctetStream = "application/octet-stream";
124 
126  const MimeTypeText = "text/plain";
127 
129  const MimeTypeHtml = "text/html";
130 
132  const MimeTypeCsv = "text/csv";
133 
135  const MimeTypeJpeg = "image/jpeg";
136 
138  const MimeTypePng = "image/png";
139 
141  const MimeTypeSoapXml = "application/soap+xml";
142 
144  const MimeTypeYaml = "text/x-yaml";
145 
147  const MimeTypeXml = "text/xml";
148 
150  const MimeTypeXmlApp = "application/xml";
151 
153  const MimeTypeJson = "application/json";
154 
157 
160 
162  const MimeTypeYamlRpc = "application/x-yaml";
163 
165  const MimeTypeJavascript = "application/javascript";
166 
168  const MimeTypeCss = "text/css";
169 
171 
173  const MimeTypes = (
174  "7z": "application/x-7z-compressed",
175  "ai": "application/postscript",
176  "aif": "audio/x-aiff",
177  "aifc": "audio/x-aiff",
178  "aiff": "audio/x-aiff",
179  "asc": MimeTypeText,
180  "atom": "application/atom+xml",
181  "au": "audio/basic",
182  "avi": "video/x-msvideo",
183  "bcpio": "application/x-bcpio",
184  "bin": MimeTypeUnknown,
185  "bmp": "image/bmp",
186  "bz2": "application/x-bzip",
187  "cc": MimeTypeText,
188  "cdf": "application/x-netcdf",
189  "cgm": "image/cgm",
190  "class": MimeTypeUnknown,
191  "cpio": "application/x-cpio",
192  "cpp": MimeTypeText,
193  "cpt": "application/mac-compactpro",
194  "csh": "application/x-csh",
195  "css": MimeTypeCss,
196  "csv": MimeTypeCsv,
197  "dcr": "application/x-director",
198  "dif": "video/x-dv",
199  "dir": "application/x-director",
200  "djv": "image/vnd.djvu",
201  "djvu": "image/vnd.djvu",
202  "dll": MimeTypeUnknown,
203  "dmg": MimeTypeUnknown,
204  "dms": MimeTypeUnknown,
205  "doc": "application/msword",
206  "dtd": "application/xml-dtd",
207  "dv": "video/x-dv",
208  "dvi": "application/x-dvi",
209  "dxr": "application/x-director",
210  "eps": "application/postscript",
211  "etx": "text/x-setext",
212  "exe": MimeTypeUnknown,
213  "ez": "application/andrew-inset",
214  "gif": "image/gif",
215  "gram": "application/srgs",
216  "grxml": "application/srgs+xml",
217  "gtar": "application/x-gtar",
218  "gz": "application/x-gzip",
219  "h": MimeTypeText,
220  "hdf": "application/x-hdf",
221  "hh": MimeTypeText,
222  "hpp": MimeTypeText,
223  "hqx": "application/mac-binhex40",
224  "htm": MimeTypeHtml,
225  "html": MimeTypeHtml,
226  "ice": "x-conference/x-cooltalk",
227  "ico": "image/x-icon",
228  "ics": "text/calendar",
229  "ief": "image/ief",
230  "ifb": "text/calendar",
231  "iges": "model/iges",
232  "igs": "model/iges",
233  "jar": "application/java-archive",
234  "java": MimeTypeText,
235  "jnlp": "application/x-java-jnlp-file",
236  "jp2": "image/jp2",
237  "jpe": MimeTypeJpeg,
238  "jpeg": MimeTypeJpeg,
239  "jpg": MimeTypeJpeg,
240  "js": MimeTypeJavascript,
241  "kar": "audio/midi",
242  "latex": "application/x-latex",
243  "lha": MimeTypeUnknown,
244  "lzh": MimeTypeUnknown,
245  "m3u": "audio/x-mpegurl",
246  "m4a": "audio/mp4a-latm",
247  "m4b": "audio/mp4a-latm",
248  "m4p": "audio/mp4a-latm",
249  "m4u": "video/vnd.mpegurl",
250  "m4v": "video/x-m4v",
251  "mac": "image/x-macpaint",
252  "man": "application/x-troff-man",
253  "mathml": "application/mathml+xml",
254  "me": "application/x-troff-me",
255  "mesh": "model/mesh",
256  "mid": "audio/midi",
257  "midi": "audio/midi",
258  "mif": "application/vnd.mif",
259  "mov": "video/quicktime",
260  "movie": "video/x-sgi-movie",
261  "mp2": "audio/mpeg",
262  "mp3": "audio/mpeg",
263  "mp4": "video/mp4",
264  "mpe": "video/mpeg",
265  "mpeg": "video/mpeg",
266  "mpg": "video/mpeg",
267  "mpga": "audio/mpeg",
268  "ms": "application/x-troff-ms",
269  "msh": "model/mesh",
270  "mxu": "video/vnd.mpegurl",
271  "nc": "application/x-netcdf",
272  "oda": "application/oda",
273  "ogg": "application/ogg",
274  "pbm": "image/x-portable-bitmap",
275  "pct": "image/pict",
276  "pdb": "chemical/x-pdb",
277  "pdf": "application/pdf",
278  "pgm": "image/x-portable-graymap",
279  "pgn": "application/x-chess-pgn",
280  "pic": "image/pict",
281  "pict": "image/pict",
282  "png": MimeTypePng,
283  "pnm": "image/x-portable-anymap",
284  "pnt": "image/x-macpaint",
285  "pntg": "image/x-macpaint",
286  "ppm": "image/x-portable-pixmap",
287  "ppt": "application/vnd.ms-powerpoint",
288  "ps": "application/postscript",
289 
290  // Qore script
291  "q": MimeTypeText,
292 
293  // Qore class include file
294  "qc": MimeTypeText,
295 
296  // Qorus function definition file
297  "qfd": MimeTypeText,
298 
299  // Qorus class definition file
300  "qclass": MimeTypeText,
301 
302  // Qorus constant definition file
303  "qconst": MimeTypeText,
304 
305  // Qorus job definition
306  "qjob": MimeTypeText,
307 
308  // Qore include file
309  "ql": MimeTypeText,
310 
311  // Qore user module source
312  "qm": MimeTypeText,
313 
314  // Qorus service definition
315  "qsd": MimeTypeText,
316 
317  // Qorus workflow definition
318  "qwf": MimeTypeText,
319 
320  "qt": "video/quicktime",
321  "qti": "image/x-quicktime",
322  "qtif": "image/x-quicktime",
323  "ra": "audio/x-pn-realaudio",
324  "ram": "audio/x-pn-realaudio",
325  "ras": "image/x-cmu-raster",
326  "rdf": "application/rdf+xml",
327  "rgb": "image/x-rgb",
328  "rm": "application/vnd.rn-realmedia",
329  "roff": "application/x-troff",
330  "rtf": "text/rtf",
331  "rtx": "text/richtext",
332  "sgm": "text/sgml",
333  "sgml": "text/sgml",
334  "sh": "application/x-sh",
335  "shar": "application/x-shar",
336  "silo": "model/mesh",
337  "sit": "application/x-stuffit",
338  "skd": "application/x-koan",
339  "skm": "application/x-koan",
340  "skp": "application/x-koan",
341  "skt": "application/x-koan",
342  "smi": "application/smil",
343  "smil": "application/smil",
344  "snd": "audio/basic",
345  "so": MimeTypeUnknown,
346  "spl": "application/x-futuresplash",
347  "src": "application/x-wais-source",
348  "sv4cpio": "application/x-sv4cpio",
349  "sv4crc": "application/x-sv4crc",
350  "svg": "image/svg+xml",
351  "swf": "application/x-shockwave-flash",
352  "t": "application/x-troff",
353  "tar": "application/x-tar",
354  "tar.bz2": "application/x-bzip-compressed-tar",
355  "tar.gz": "application/x-tar-gz",
356  "tbz": "application/x-bzip-compressed-tar",
357  "tcl": "application/x-tcl",
358  "tex": "application/x-tex",
359  "texi": "application/x-texinfo",
360  "texinfo": "application/x-texinfo",
361  "text": MimeTypeText,
362  "tgz": "application/x-tar-gz",
363  "tif": "image/tiff",
364  "tiff": "image/tiff",
365  "tr": "application/x-troff",
366  "tsv": "text/tab-separated-values",
367  "txt": MimeTypeText,
368  "ustar": "application/x-ustar",
369  "vcd": "application/x-cdlink",
370  "vrml": "model/vrml",
371  "vxml": "application/voicexml+xml",
372  "wav": "audio/x-wav",
373  "wbmp": "image/vnd.wap.wbmp",
374  "wbmxl": "application/vnd.wap.wbxml",
375  "wml": "text/vnd.wap.wml",
376  "wmlc": "application/vnd.wap.wmlc",
377  "wmls": "text/vnd.wap.wmlscript",
378  "wmlsc": "application/vnd.wap.wmlscriptc",
379  "wrl": "model/vrml",
380  "wsdl": "application/wsdl+xml",
381  "xbm": "image/x-xbitmap",
382  "xht": "application/xhtml+xml",
383  "xhtml": "application/xhtml+xml",
384  "xls": "application/vnd.ms-excel",
385  "xml": MimeTypeXml,
386  "xpm": "image/x-xpixmap",
387  "xsd": MimeTypeXml,
388  "xsl": "application/xml",
389  "xslt": "application/xslt+xml",
390  "xul": "application/vnd.mozilla.xul+xml",
391  "xwd": "image/x-xwindowdump",
392  "xyz": "chemical/x-xyz",
393  "yaml": MimeTypeYaml,
394  "zip": "application/zip",
395  );
397 
401  const ContentTransEnc7Bit = "7bit";
403 
405  const ContentTransEnc8Bit = "8bit";
406 
408  const ContentTransEncBinary = "binary";
409 
411  const ContentTransEncBase64 = "base64";
412 
414  const ContentTransEncQuotedPrintable = "quoted-printable";
415 
417 
419  const MimeBase64LineLen = 76;
420 
422 
426 
430 
436  string mime_encode_base64(data str, int len = MimeBase64LineLen);
437 
438 
440 
443  string mime_encode_quoted_printable(string str, bool hdr = False);
444 
445 
447 
452  data mime_encode_transfer_data(data data, string enc);
453 
454 
456  string mime_encode_header_word_b(string str);
457 
458 
460  string mime_encode_header_word_q(string str);
461 
463 
467 
472  binary mime_decode_base64(data str);
473 
474 
476 
481  string mime_decode_base64_to_string(data str, *string encoding);
482 
483 
485 
490  string mime_decode_quoted_printable(string str, *string encoding);
491 
492 
494 
500  data mime_decode_transfer_data(data data, string enc, *string ct);
501 
502 
504 
507  string mime_decode_header(string hdr);
508 
510 
514  string get_mime_type_from_ext(string path);
516 
518 
522  const MPT_FORM_DATA = "form-data";
524 
526  const MPT_MIXED = "mixed";
527 
529  const MPT_MESSAGE = "message";
530 
532  const MPT_DIGEST = "digest";
533 
535  const MPT_ALTERNATIVE = "alternative";
536 
538  const MPT_RELATED = "related";
539 
541  const MPT_SIGNED = "signed";
542 
544  const MPT_ENCRYPTED = "encrypted";
545 
547  const MPT_BYTERANGES = "byteranges";
549 
552 
553 public:
554  const MP_DEFAULT_MSG = "This is a MIME multipart message";
555 
557  private :
559  string mptype;
560 
562  string boundary;
563 
565  string ct;
566 
568  list l = ();
569 
571  hash hdr;
572 
573 public:
575 
577 
580  constructor(string n_mptype, string n_boundary = MultiPartMessage::getBoundary());
581 
582 
584  static string getBoundary();
585 
587 
591  static string getRandomString(int len);
592 
594 
652  static hash parseBody(string boundary, string body, bool decode = True);
653 
655  binary serialize();
656 
657 
659 
663  static binary serializeHeaders(hash hdr);
664 
666 
670  abstract hash getMsgAndHeaders();
671 
673 
674  // don't reimplement this method; fix/enhance it in the module
675  final private hash getMsgAndHeadersIntern(*string content_type, bool conlen = True);
676 
677 
678  // don't reimplement this method; fix/enhance it in the module
679  private splicePartIntern(data data, hash hdr);
680 
681 
682  // don't reimplement this method; fix/enhance it in the module
683  private addPartIntern(data data, hash hdr);
684 
685 
686 
687 private:
688  static hash getPart(data data, hash hdr);
689 public:
690 
692  };
693 
696 
697 public:
699  private :
700  // the starting part ID
701  string startid;
702 
703 public:
705 
707 
709  constructor(string boundary = MultiPartMessage::getBoundary()) ;
710 
711 
713 
720  splicePart(data data, string id, string content_type, *hash hdr);
721 
722 
724 
731  addPart(data data, string id, string content_type, *hash hdr);
732 
733 
735 
740 
741  };
742 
745 
746 public:
748 
750  constructor(string boundary = MultiPartMessage::getBoundary()) ;
751 
752 
754 
766  splicePart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
767 
768 
770 
782  addPart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
783 
784 
786 
800  spliceEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
801 
802 
804 
818  addEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
819 
820 
822 
827 
828  };
829 };
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387) ...
Definition: Mime.qm.dox.h:538
data mime_encode_transfer_data(data data, string enc)
encodes data according to the given encoding
const MimeTypeJpeg
MIME type for jpeg images.
Definition: Mime.qm.dox.h:135
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
const MPT_MESSAGE
for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
Definition: Mime.qm.dox.h:529
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...
const ContentTransEnc8Bit
implies lines < 1000 chars (= no encoding)
Definition: Mime.qm.dox.h:405
MultiPartMessage class implementation.
Definition: Mime.qm.dox.h:551
const MimeTypeYaml
Mime type for yaml data files.
Definition: Mime.qm.dox.h:144
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition: Mime.qm.dox.h:147
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition: Mime.qm.dox.h:544
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...
static binary serializeHeaders(hash hdr)
serializes a header hash to a binary object
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...
const True
implements a MultiPartMixedMessage class, a specialization of MultiPartMessage
Definition: Mime.qm.dox.h:744
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()
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition: Mime.qm.dox.h:156
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616) ...
Definition: Mime.qm.dox.h:547
const MimeTypeJson
Mime type for JSON.
Definition: Mime.qm.dox.h:153
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
const ContentTransEncBase64
base-64 Content-Transfer-Encoding
Definition: Mime.qm.dox.h:411
binary serialize()
serializes the message and returns a binary object ready to send over a socket
const MimeTypePng
MIME type for png images.
Definition: Mime.qm.dox.h:138
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition: Mime.qm.dox.h:424
const False
const MimeTypeJavascript
Mime type for Javascript.
Definition: Mime.qm.dox.h:165
list list(...)
string mime_decode_base64_to_string(data str, *string encoding)
returns a string value from a string in "BASE64" encoding according to RFC 2045
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...
const MimeTypeOctetStream
MIME type for unknown file types.
Definition: Mime.qm.dox.h:123
const MimeTypeCss
Mime type for css.
Definition: Mime.qm.dox.h:168
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...
binary mime_decode_base64(data str)
returns a binary value from a string in "BASE64" encoding according to RFC 2045
const MimeTypeYamlRpc
Mime type for YAML-RPC.
Definition: Mime.qm.dox.h:162
abstract hash getMsgAndHeaders()
returns a hash of the message
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition: Mime.qm.dox.h:159
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...
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
string mime_encode_base64(data str, int len=MimeBase64LineLen)
returns a string in "BASE64" encoding according to RFC 2045
const MPT_DIGEST
for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1.5)
Definition: Mime.qm.dox.h:532
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
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...
const ContentTransEncQuotedPrintable
quoted-printable Content-Transfer-Encoding
Definition: Mime.qm.dox.h:414
hash getMsgAndHeaders()
returns a hash of the message
string mime_encode_header_word_b(string str)
returns a string in "B" ("BASE64") encoding for MIME header string words according to RFC 2047 ...
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...
static string getRandomString(int len)
returns a string of random characters
data mime_decode_transfer_data(data data, string enc, *string ct)
decodes data according to the given encoding
public Mime namespace defines constants and functions relevant to MIME
Definition: Mime.qm.dox.h:115
const MimeBase64LineLen
maximum line length for base64 encoding
Definition: Mime.qm.dox.h:419
constructor(string n_mptype, string n_boundary=MultiPartMessage::getBoundary())
creates the object
const MimeTypeHtml
MIME type for HTML.
Definition: Mime.qm.dox.h:129
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
static string getBoundary()
returns a string embedded with the current timestamp designed to be used as MultiPart boundary string...
hash hash(object obj)
const MimeTypeSoapXml
Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023) ...
Definition: Mime.qm.dox.h:141
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition: Mime.qm.dox.h:408
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition: Mime.qm.dox.h:150
const ContentTransEnc7Bit
default Content-Transfer-Encoding if none is present; implies lines < 1000 chars (= no encoding) ...
Definition: Mime.qm.dox.h:402
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition: Mime.qm.dox.h:132
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...
const MimeTypeText
MIME type for text.
Definition: Mime.qm.dox.h:126
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...