Qore Mime Module Reference  1.3.4
 All Classes Namespaces Functions Variables Groups Pages
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 - 2014 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 
111 namespace Mime {
117  const MimeTypeUnknown = MimeTypeOctetStream;
118 
120  const MimeTypeOctetStream = "application/octet-stream";
121 
123  const MimeTypeText = "text/plain";
124 
126  const MimeTypeHtml = "text/html";
127 
129  const MimeTypeCsv = "text/csv";
130 
132  const MimeTypeJpeg = "image/jpeg";
133 
135  const MimeTypePng = "image/png";
136 
138  const MimeTypeSoapXml = "application/soap+xml";
139 
141  const MimeTypeYaml = "text/x-yaml";
142 
144  const MimeTypeXml = "text/xml";
145 
147  const MimeTypeXmlApp = "application/xml";
148 
150  const MimeTypeJson = "application/json";
151 
154 
157 
159  const MimeTypeYamlRpc = "application/x-yaml";
160 
162  const MimeTypeJavascript = "application/javascript";
163 
165  const MimeTypeCss = "text/css";
166 
168 
170  const MimeTypes = (
171  "7z": "application/x-7z-compressed",
172  "ai": "application/postscript",
173  "aif": "audio/x-aiff",
174  "aifc": "audio/x-aiff",
175  "aiff": "audio/x-aiff",
176  "asc": MimeTypeText,
177  "atom": "application/atom+xml",
178  "au": "audio/basic",
179  "avi": "video/x-msvideo",
180  "bcpio": "application/x-bcpio",
181  "bin": MimeTypeUnknown,
182  "bmp": "image/bmp",
183  "bz2": "application/x-bzip",
184  "cc": MimeTypeText,
185  "cdf": "application/x-netcdf",
186  "cgm": "image/cgm",
187  "class": MimeTypeUnknown,
188  "cpio": "application/x-cpio",
189  "cpp": MimeTypeText,
190  "cpt": "application/mac-compactpro",
191  "csh": "application/x-csh",
192  "css": MimeTypeCss,
193  "csv": MimeTypeCsv,
194  "dcr": "application/x-director",
195  "dif": "video/x-dv",
196  "dir": "application/x-director",
197  "djv": "image/vnd.djvu",
198  "djvu": "image/vnd.djvu",
199  "dll": MimeTypeUnknown,
200  "dmg": MimeTypeUnknown,
201  "dms": MimeTypeUnknown,
202  "doc": "application/msword",
203  "dtd": "application/xml-dtd",
204  "dv": "video/x-dv",
205  "dvi": "application/x-dvi",
206  "dxr": "application/x-director",
207  "eps": "application/postscript",
208  "etx": "text/x-setext",
209  "exe": MimeTypeUnknown,
210  "ez": "application/andrew-inset",
211  "gif": "image/gif",
212  "gram": "application/srgs",
213  "grxml": "application/srgs+xml",
214  "gtar": "application/x-gtar",
215  "gz": "application/x-gzip",
216  "h": MimeTypeText,
217  "hdf": "application/x-hdf",
218  "hh": MimeTypeText,
219  "hpp": MimeTypeText,
220  "hqx": "application/mac-binhex40",
221  "htm": MimeTypeHtml,
222  "html": MimeTypeHtml,
223  "ice": "x-conference/x-cooltalk",
224  "ico": "image/x-icon",
225  "ics": "text/calendar",
226  "ief": "image/ief",
227  "ifb": "text/calendar",
228  "iges": "model/iges",
229  "igs": "model/iges",
230  "jar": "application/java-archive",
231  "java": MimeTypeText,
232  "jnlp": "application/x-java-jnlp-file",
233  "jp2": "image/jp2",
234  "jpe": MimeTypeJpeg,
235  "jpeg": MimeTypeJpeg,
236  "jpg": MimeTypeJpeg,
237  "js": MimeTypeJavascript,
238  "kar": "audio/midi",
239  "latex": "application/x-latex",
240  "lha": MimeTypeUnknown,
241  "lzh": MimeTypeUnknown,
242  "m3u": "audio/x-mpegurl",
243  "m4a": "audio/mp4a-latm",
244  "m4b": "audio/mp4a-latm",
245  "m4p": "audio/mp4a-latm",
246  "m4u": "video/vnd.mpegurl",
247  "m4v": "video/x-m4v",
248  "mac": "image/x-macpaint",
249  "man": "application/x-troff-man",
250  "mathml": "application/mathml+xml",
251  "me": "application/x-troff-me",
252  "mesh": "model/mesh",
253  "mid": "audio/midi",
254  "midi": "audio/midi",
255  "mif": "application/vnd.mif",
256  "mov": "video/quicktime",
257  "movie": "video/x-sgi-movie",
258  "mp2": "audio/mpeg",
259  "mp3": "audio/mpeg",
260  "mp4": "video/mp4",
261  "mpe": "video/mpeg",
262  "mpeg": "video/mpeg",
263  "mpg": "video/mpeg",
264  "mpga": "audio/mpeg",
265  "ms": "application/x-troff-ms",
266  "msh": "model/mesh",
267  "mxu": "video/vnd.mpegurl",
268  "nc": "application/x-netcdf",
269  "oda": "application/oda",
270  "ogg": "application/ogg",
271  "pbm": "image/x-portable-bitmap",
272  "pct": "image/pict",
273  "pdb": "chemical/x-pdb",
274  "pdf": "application/pdf",
275  "pgm": "image/x-portable-graymap",
276  "pgn": "application/x-chess-pgn",
277  "pic": "image/pict",
278  "pict": "image/pict",
279  "png": MimeTypePng,
280  "pnm": "image/x-portable-anymap",
281  "pnt": "image/x-macpaint",
282  "pntg": "image/x-macpaint",
283  "ppm": "image/x-portable-pixmap",
284  "ppt": "application/vnd.ms-powerpoint",
285  "ps": "application/postscript",
286 
287  // Qore script
288  "q": MimeTypeText,
289 
290  // Qore class include file
291  "qc": MimeTypeText,
292 
293  // Qorus function definition file
294  "qfd": MimeTypeText,
295 
296  // Qorus class definition file
297  "qclass": MimeTypeText,
298 
299  // Qorus constant definition file
300  "qconst": MimeTypeText,
301 
302  // Qorus job definition
303  "qjob": MimeTypeText,
304 
305  // Qore include file
306  "ql": MimeTypeText,
307 
308  // Qore user module source
309  "qm": MimeTypeText,
310 
311  // Qorus service definition
312  "qsd": MimeTypeText,
313 
314  // Qorus workflow definition
315  "qwf": MimeTypeText,
316 
317  "qt": "video/quicktime",
318  "qti": "image/x-quicktime",
319  "qtif": "image/x-quicktime",
320  "ra": "audio/x-pn-realaudio",
321  "ram": "audio/x-pn-realaudio",
322  "ras": "image/x-cmu-raster",
323  "rdf": "application/rdf+xml",
324  "rgb": "image/x-rgb",
325  "rm": "application/vnd.rn-realmedia",
326  "roff": "application/x-troff",
327  "rtf": "text/rtf",
328  "rtx": "text/richtext",
329  "sgm": "text/sgml",
330  "sgml": "text/sgml",
331  "sh": "application/x-sh",
332  "shar": "application/x-shar",
333  "silo": "model/mesh",
334  "sit": "application/x-stuffit",
335  "skd": "application/x-koan",
336  "skm": "application/x-koan",
337  "skp": "application/x-koan",
338  "skt": "application/x-koan",
339  "smi": "application/smil",
340  "smil": "application/smil",
341  "snd": "audio/basic",
342  "so": MimeTypeUnknown,
343  "spl": "application/x-futuresplash",
344  "src": "application/x-wais-source",
345  "sv4cpio": "application/x-sv4cpio",
346  "sv4crc": "application/x-sv4crc",
347  "svg": "image/svg+xml",
348  "swf": "application/x-shockwave-flash",
349  "t": "application/x-troff",
350  "tar": "application/x-tar",
351  "tar.bz2": "application/x-bzip-compressed-tar",
352  "tar.gz": "application/x-tar-gz",
353  "tbz": "application/x-bzip-compressed-tar",
354  "tcl": "application/x-tcl",
355  "tex": "application/x-tex",
356  "texi": "application/x-texinfo",
357  "texinfo": "application/x-texinfo",
358  "text": MimeTypeText,
359  "tgz": "application/x-tar-gz",
360  "tif": "image/tiff",
361  "tiff": "image/tiff",
362  "tr": "application/x-troff",
363  "tsv": "text/tab-separated-values",
364  "txt": MimeTypeText,
365  "ustar": "application/x-ustar",
366  "vcd": "application/x-cdlink",
367  "vrml": "model/vrml",
368  "vxml": "application/voicexml+xml",
369  "wav": "audio/x-wav",
370  "wbmp": "image/vnd.wap.wbmp",
371  "wbmxl": "application/vnd.wap.wbxml",
372  "wml": "text/vnd.wap.wml",
373  "wmlc": "application/vnd.wap.wmlc",
374  "wmls": "text/vnd.wap.wmlscript",
375  "wmlsc": "application/vnd.wap.wmlscriptc",
376  "wrl": "model/vrml",
377  "wsdl": "application/wsdl+xml",
378  "xbm": "image/x-xbitmap",
379  "xht": "application/xhtml+xml",
380  "xhtml": "application/xhtml+xml",
381  "xls": "application/vnd.ms-excel",
382  "xml": MimeTypeXml,
383  "xpm": "image/x-xpixmap",
384  "xsd": MimeTypeXml,
385  "xsl": "application/xml",
386  "xslt": "application/xslt+xml",
387  "xul": "application/vnd.mozilla.xul+xml",
388  "xwd": "image/x-xwindowdump",
389  "xyz": "chemical/x-xyz",
390  "yaml": MimeTypeYaml,
391  "zip": "application/zip",
392  );
394 
398  const ContentTransEnc7Bit = "7bit";
400 
402  const ContentTransEnc8Bit = "8bit";
403 
405  const ContentTransEncBinary = "binary";
406 
408  const ContentTransEncBase64 = "base64";
409 
411  const ContentTransEncQuotedPrintable = "quoted-printable";
412 
414 
416  const MimeBase64LineLen = 76;
417 
419 
423 
427 
433  string mime_encode_base64(data str, int len = MimeBase64LineLen);
434 
435 
437 
440  string mime_encode_quoted_printable(string str, bool hdr = False);
441 
442 
444 
449  data mime_encode_transfer_data(data data, string enc);
450 
451 
453  string mime_encode_header_word_b(string str);
454 
455 
457  string mime_encode_header_word_q(string str);
458 
460 
464 
469  binary mime_decode_base64(data str);
470 
471 
473 
478  string mime_decode_base64_to_string(data str, *string encoding);
479 
480 
482 
487  string mime_decode_quoted_printable(string str, *string encoding);
488 
489 
491 
497  data mime_decode_transfer_data(data data, string enc, *string ct);
498 
499 
501 
504  string mime_decode_header(string hdr);
505 
507 
511  string get_mime_type_from_ext(string path);
513 
515 
519  const MPT_FORM_DATA = "form-data";
521 
523  const MPT_MIXED = "mixed";
524 
526  const MPT_MESSAGE = "message";
527 
529  const MPT_DIGEST = "digest";
530 
532  const MPT_ALTERNATIVE = "alternative";
533 
535  const MPT_RELATED = "related";
536 
538  const MPT_SIGNED = "signed";
539 
541  const MPT_ENCRYPTED = "encrypted";
542 
544  const MPT_BYTERANGES = "byteranges";
546 
549 
550 public:
551  const MP_DEFAULT_MSG = "This is a MIME multipart message";
552 
554  private :
556  string mptype;
557 
559  string boundary;
560 
562  string ct;
563 
565  list l = ();
566 
568  hash hdr;
569 
570 public:
572 
574 
577  constructor(string mptype, string boundary = MultiPartMessage::getBoundary());
578 
579 
581  static string getBoundary();
582 
584 
588  static string getRandomString(int len);
589 
591 
649  static hash parseBody(string boundary, string body, bool decode = True);
650 
652  binary serialize();
653 
654 
656 
660  static binary serializeHeaders(hash hdr);
661 
663 
667  abstract hash getMsgAndHeaders();
668 
670 
671  // don't reimplement this method; fix/enhance it in the module
672  final private hash getMsgAndHeadersIntern(*string content_type, bool conlen = True);
673 
674 
675  // don't reimplement this method; fix/enhance it in the module
676  private splicePartIntern(data data, hash hdr);
677 
678 
679  // don't reimplement this method; fix/enhance it in the module
680  private addPartIntern(data data, hash hdr);
681 
682 
683 
684 private:
685  static hash getPart(data data, hash hdr);
686 public:
687 
689  };
690 
693 
694 public:
696  private :
697  // the starting part ID
698  string startid;
699 
700 public:
702 
704 
706  constructor(string boundary = MultiPartMessage::getBoundary());
707 
708 
710 
717  splicePart(data data, string id, string content_type, *hash hdr);
718 
719 
721 
728  addPart(data data, string id, string content_type, *hash hdr);
729 
730 
732 
737 
738  };
739 
742 
743 public:
745 
747  constructor(string boundary = MultiPartMessage::getBoundary());
748 
749 
751 
763  splicePart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
764 
765 
767 
779  addPart(data data, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
780 
781 
783 
797  spliceEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
798 
799 
801 
815  addEncodePart(data data, string enc, string content_type = MimeTypeText, string disp = "inline", *hash hdr);
816 
817 
819 
824 
825  };
826 };
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387) ...
Definition: Mime.qm.dox.h:535
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:132
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:526
constructor(string mptype, string boundary=MultiPartMessage::getBoundary())
creates the object
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:402
MultiPartMessage class implementation.
Definition: Mime.qm.dox.h:548
const MimeTypeYaml
Mime type for yaml data files.
Definition: Mime.qm.dox.h:141
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition: Mime.qm.dox.h:144
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition: Mime.qm.dox.h:541
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:741
const MPT_ALTERNATIVE
for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5...
Definition: Mime.qm.dox.h:532
binary binary()
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition: Mime.qm.dox.h:153
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616) ...
Definition: Mime.qm.dox.h:544
const MimeTypeJson
Mime type for JSON.
Definition: Mime.qm.dox.h:150
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:538
const ContentTransEncBase64
base-64 Content-Transfer-Encoding
Definition: Mime.qm.dox.h:408
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:135
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition: Mime.qm.dox.h:421
const False
const MimeTypeJavascript
Mime type for Javascript.
Definition: Mime.qm.dox.h:162
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:120
const MimeTypeCss
Mime type for css.
Definition: Mime.qm.dox.h:165
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:159
abstract hash getMsgAndHeaders()
returns a hash of the message
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition: Mime.qm.dox.h:156
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:523
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:529
const MPT_FORM_DATA
for form data (http://tools.ietf.org/html/rfc1867, http://tools.ietf.org/html/rfc2388) ...
Definition: Mime.qm.dox.h:520
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:411
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
const MimeBase64LineLen
maximum line length for base64 encoding
Definition: Mime.qm.dox.h:416
const MimeTypeHtml
MIME type for HTML.
Definition: Mime.qm.dox.h:126
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:170
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:138
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition: Mime.qm.dox.h:405
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition: Mime.qm.dox.h:147
const ContentTransEnc7Bit
default Content-Transfer-Encoding if none is present; implies lines < 1000 chars (= no encoding) ...
Definition: Mime.qm.dox.h:399
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition: Mime.qm.dox.h:129
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:123
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...