Qore Mime Module Reference 1.6
Loading...
Searching...
No Matches
Mime.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Mime.qm Copyright (C) 2012 - 2024 Qore Technologies, s.r.o.
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
168namespace Mime {
170
172 public hashdecl MessageInfo {
174 hash hdr;
176 data body;
178 list<hash<MessageInfo>> part();
179 };
180
182 public hashdecl MessagePartInfo {
186 hash hdr;
187 };
188
190 public hashdecl FormDataMessageInfo {
192 string name;
194 *string filename;
196 hash hdr;
198 data body;
199 };
200
207
209 const MimeTypeOctetStream = "application/octet-stream";
210
212 const MimeTypeText = "text/plain";
213
215 const MimeTypeHtml = "text/html";
216
218 const MimeTypeCsv = "text/csv";
219
221 const MimeTypeJpeg = "image/jpeg";
222
224 const MimeTypePng = "image/png";
225
227 const MimeTypeSoapXml = "application/soap+xml";
228
230 const MimeTypeYaml = "text/x-yaml";
231
233 const MimeTypeXml = "text/xml";
234
236 const MimeTypeXmlApp = "application/xml";
237
239 const MimeTypeJson = "application/json";
240
243
246
248 const MimeTypeYamlRpc = "application/x-yaml";
249
251 const MimeTypeJavascript = "application/javascript";
252
254 const MimeTypeCss = "text/css";
255
257 const MimeTypeFormUrlEncoded = "application/x-www-form-urlencoded";
258
260 const MimeTypeMultipartFormData = "multipart/form-data";
261
263 const MimeTypeMultipartRelated = "multipart/related";
264
266 const MimeTypeMultipartMixed = "multipart/mixed";
267
269 const MimeTypeSvg = "image/svg+xml";
270
272 const MimeTypeQore = "text/x-qore";
273
275 const MimeTypeJavaSource = "text/x-java-source";
276
278 const MimeTypeJava = "application/java";
279
281 const MimeTypeJar = "application/java-archive";
282
284 const MimeTypePython = "text/x-python-source";
285
287 const MimeTypePythonCode = "application/x-python-code";
288
290 const MimeTypePhp = "application/x-httpd-php";
291
293 const MimeTypeSse = "text/event-stream";
294
296
298 const MimeTypes = ...;
299
300
302
308 const UrlEncodedChars = ...;
309
311
316 const ContentTransEnc7Bit = "7bit";
317
319 const ContentTransEnc8Bit = "8bit";
320
322 const ContentTransEncBinary = "binary";
323
325 const ContentTransEncBase64 = "base64";
326
328 const ContentTransEncQuotedPrintable = "quoted-printable";
329
331
334
336
340
345
350 string mime_encode_base64(data str, int len = MimeBase64LineLen);
351
352
354
359 string mime_encode_quoted_printable(string str, bool hdr = False, *string encoding);
360
361
363
368 data mime_encode_transfer_data(data mime_data, string enc);
369
370
372
374 string mime_encode_header_word_b(string str);
375
376
378
380 string mime_encode_header_word_q(string str);
381
383
388
394 binary mime_decode_base64(data str);
395
396
398
405 string mime_decode_base64_to_string(data str, *string encoding);
406
407
409
416 string mime_decode_quoted_printable(string str, *string encoding, *bool is_body);
417
418
420
428 data mime_decode_transfer_data(data mime_data, string enc, *string ct, *bool is_body);
429
430
432
439 string mime_decode_header(string hdr);
440
442
447
453 bool is_mime_text(string mime);
454
455
457
463 bool is_filename_text(string path);
464
465
467 string get_mime_type_from_ext(string path, string def_type = MimeTypeUnknown);
468
469
471
487
488
490
505
506
508
518
519
521
532 hash<auto> mime_parse_form_urlencoded_string(string str);
533
535
540 const MPT_FORM_DATA = "form-data";
541
543 const MPT_MIXED = "mixed";
544
546 const MPT_MESSAGE = "message";
547
549 const MPT_DIGEST = "digest";
550
552 const MPT_ALTERNATIVE = "alternative";
553
555 const MPT_RELATED = "related";
556
558 const MPT_SIGNED = "signed";
559
561 const MPT_ENCRYPTED = "encrypted";
562
564 const MPT_BYTERANGES = "byteranges";
566
569
570public:
571 const MP_DEFAULT_MSG = "This is a MIME multipart message";
572
574protected:
576 string mptype;
577
579 string boundary;
580
582 string ct;
583
585 list<hash<MessagePartInfo>> l();
586
588 hash hdr;
589
591 const ASCII_CR = 13;
592 const ASCII_LF = 10;
593
594public:
596
598
601 constructor(string mptype, string boundary = MultiPartMessage::getBoundary());
602
603
605 binary serialize();
606
607
609
612
613
615
619 int size();
620
621
623
627 string getBoundary();
628
629
631
635 static binary serializeHeaders(hash hdr);
636
638 static string getBoundary();
639
641
645 static string getRandomString(int len);
646
648
707 static hash<MessageInfo> parseBody(string boundary, data body, bool decode = True);
708
710
714 abstract hash<MessageInfo> getMsgAndHeaders();
715
717 // don't reimplement this method; fix/enhance it in the module
718protected:
719 final hash<MessageInfo> getMsgAndHeadersIntern(*string content_type, bool conlen = True);
720public:
721
722
723 // don't reimplement this method; fix/enhance it in the module
724protected:
725 splicePartIntern(data mime_data, hash<auto> hdr);
726public:
727
728
729 // don't reimplement this method; fix/enhance it in the module
730protected:
731 addPartIntern(data mime_data, hash<auto> hdr);
732public:
733
734
735protected:
736 static hash<MessagePartInfo> getPart(data mime_data, hash<auto> hdr);
737public:
738
740 };
741
744
745public:
747protected:
748 // the starting part ID
749 string startid;
750
751public:
753
755
758
759
761
768 splicePart(data mime_data, string id, string content_type, *hash<auto> hdr);
769
770
772
779 addPart(data mime_data, string id, string content_type, *hash hdr);
780
781
783
787 hash<MessageInfo> getMsgAndHeaders();
788
789 };
790
793
794public:
796
799
800
802
814 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
815
816
818
830 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
831
832
834
848 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
849
850
852
866 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
867
868
870
874 hash<MessageInfo> getMsgAndHeaders();
875
876 };
877
880
881public:
883
886
887
889
903 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
904
905
907
919 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
920
921
923
937 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
938
939
941
955 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
956
957
959
963 hash<MessageInfo> getMsgAndHeaders();
964
965 };
966
968
971
972public:
973protected:
975 hash parts;
976
977public:
978
980
983
984
986
992 splicePart(data mime_data, string name, *hash hdr);
993
994
996
1004 splicePart(data mime_data, string name, string filename, string content_type, *hash hdr);
1005
1006
1008
1012 splicePart(hash<FormDataMessageInfo> h);
1013
1014
1016
1022 addPart(data mime_data, string name, *hash hdr);
1023
1024
1026
1034 addPart(data mime_data, string name, string filename, string content_type, *hash hdr);
1035
1036
1038
1042 addPart(hash<FormDataMessageInfo> h);
1043
1044
1046
1050 hash<MessageInfo> getMsgAndHeaders();
1051
1052
1054
1063 static hash<string, hash<FormDataMessageInfo>> parseMessage(string content, string body);
1064
1066
1070 static MultiPartFormDataMessage makeMessage(hash<string, hash<FormDataMessageInfo>> parts);
1071
1073
1077 static binary makeMessageBody(hash<string, hash<FormDataMessageInfo>> parts);
1078
1080protected:
1081 checkPartName(string name);
1082public:
1083
1084
1086protected:
1087 hash getPartHeader(string name, *string filename, *string content_type, *hash<auto> hdr);
1088public:
1089
1090 };
1091};
implements the MultiPartAlternativeMessage class, a specialization of MultiPartMessage
Definition Mime.qm.dox.h:879
spliceEncodePart(data mime_data, string enc, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the start of the list; encodes the data according to the transfer encoding arg...
splicePart(data mime_data, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the start of the list
addPart(data mime_data, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the end of the list; the data muyst already be encoded and any Content-Transfe...
hash< MessageInfo > getMsgAndHeaders()
returns a hash of the message
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
addEncodePart(data mime_data, string enc, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the end of the list; encodes the data according to the transfer encoding argum...
implements the MultiPartFormDataMessage class, a specialization of MultiPartMessage
Definition Mime.qm.dox.h:970
static MultiPartFormDataMessage makeMessage(hash< string, hash< FormDataMessageInfo > > parts)
creates a multipart/form-data message from a hash of FormDataMessageInfo hashes keyed by part name
static binary makeMessageBody(hash< string, hash< FormDataMessageInfo > > parts)
creates a multipart/form-data message body from a hash of FormDataMessageInfo hashes keyed by part na...
addPart(hash< FormDataMessageInfo > h)
adds a message part to the end of the list
addPart(data mime_data, string name, *hash hdr)
adds a message part to the end of the list
hash< MessageInfo > getMsgAndHeaders()
returns a hash of the message
hash parts
hash of part names to ensure uniqueness
Definition Mime.qm.dox.h:975
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
hash getPartHeader(string name, *string filename, *string content_type, *hash< auto > hdr)
builds the header for the part
checkPartName(string name)
check for unique part names and adds the part to the unique name hash
splicePart(data mime_data, string name, *hash hdr)
adds a message part to the start of the list
static hash< string, hash< FormDataMessageInfo > > parseMessage(string content, string body)
parses a multipart/form-data encoded message and returns a hash of its ContentTransEnc7Bit
splicePart(data mime_data, string name, string filename, string content_type, *hash hdr)
adds a message part to the start of the list
addPart(data mime_data, string name, string filename, string content_type, *hash hdr)
adds a message part to the end of the list
splicePart(hash< FormDataMessageInfo > h)
adds a message part to the start of the list
MultiPartMessage class implementation.
Definition Mime.qm.dox.h:568
binary serializeBody()
serializes the message body only and returns a binary object ready to send over a socket
int size()
returns the number of parts in the message
binary serialize()
serializes the message with the Content-Type header first and returns a binary object ready to send o...
static hash< MessageInfo > parseBody(string boundary, data body, bool decode=True)
returns a hash representing a parsed multipart message body from a boundary string and body arguments
static binary serializeHeaders(hash hdr)
serializes a header hash to a binary object
abstract hash< MessageInfo > getMsgAndHeaders()
returns a hash of the message
static string getRandomString(int len)
returns a string of random characters
string getBoundary()
returns the message boundary string used
constructor(string mptype, string boundary=MultiPartMessage::getBoundary())
creates the object
static string getBoundary()
returns a string embedded with the current timestamp designed to be used as MultiPart boundary string
implements the MultiPartMixedMessage class, a specialization of MultiPartMessage
Definition Mime.qm.dox.h:792
spliceEncodePart(data mime_data, string enc, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the start of the list; encodes the data according to the transfer encoding arg...
splicePart(data mime_data, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the start of the list; the data muyst already be encoded and any Content-Trans...
hash< MessageInfo > getMsgAndHeaders()
returns a hash of the message
addPart(data mime_data, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the end of the list; the data muyst already be encoded and any Content-Transfe...
addEncodePart(data mime_data, string enc, string content_type=MimeTypeText, string disp='inline', *hash< auto > hdr)
adds a message part to the end of the list; encodes the data according to the transfer encoding argum...
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
const ContentTransEncBase64
base-64 Content-Transfer-Encoding
Definition Mime.qm.dox.h:325
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition Mime.qm.dox.h:322
const ContentTransEnc7Bit
Definition Mime.qm.dox.h:316
const ContentTransEncQuotedPrintable
quoted-printable Content-Transfer-Encoding
Definition Mime.qm.dox.h:328
const MimeBase64LineLen
maximum line length for base64 encoding
Definition Mime.qm.dox.h:333
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition Mime.qm.dox.h:338
const ContentTransEnc8Bit
implies lines < 1000 chars (= no encoding)
Definition Mime.qm.dox.h:319
binary mime_decode_base64(data str)
data mime_decode_transfer_data(data mime_data, string enc, *string ct, *bool is_body)
decodes data according to the given encoding
string mime_decode_header(string hdr)
decodes a header string
string mime_decode_quoted_printable(string str, *string encoding, *bool is_body)
returns a string parsed from "quoted-printable" (or "QP") encoding
string mime_decode_base64_to_string(data str, *string encoding)
returns a string value from a string in "BASE64" encoding
string mime_encode_header_word_b(string str)
returns a string in "B" ("BASE64") encoding for MIME header string words
string mime_encode_quoted_printable(string str, bool hdr=False, *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_encode_header_word_q(string str)
returns a string in "Q" ("quoted-printable") encoding for MIME header string words
string mime_encode_base64(data str, int len=MimeBase64LineLen)
string get_mime_type_from_ext(string path, string def_type=MimeTypeUnknown)
returns the mime type for the given filename from the extension or the default type if the extension ...
bool is_mime_text(string mime)
bool is_filename_text(string path)
Returns True if the given filename / path is known to provide text content, False if not.
string mime_decode_urlencoded_string(string str)
decodes the given string from URL encoded format
string mime_get_urlencoded_string(auto val)
returns a single string in MIME URL encoded format
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...
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 "C...
const MimeTypeMultipartRelated
Mime type for multipart related.
Definition Mime.qm.dox.h:263
const MimeTypeJavascript
Mime type for Javascript.
Definition Mime.qm.dox.h:251
const MimeTypeSvg
Mime type for SVG files.
Definition Mime.qm.dox.h:269
const UrlEncodedChars
hash of non-alphanumeric characters that can be used unencoded in URL encoded format
Definition Mime.qm.dox.h:308
const MimeTypeMultipartFormData
Mime type for multipart form data.
Definition Mime.qm.dox.h:260
const MimeTypePythonCode
Mime type for Python compiled code.
Definition Mime.qm.dox.h:287
const MimeTypeUnknown
Definition Mime.qm.dox.h:206
const MimeTypePng
MIME type for png images.
Definition Mime.qm.dox.h:224
const MimeTypeFormUrlEncoded
Mime type for multipart form URL encoding.
Definition Mime.qm.dox.h:257
const MimeTypeText
MIME type for text.
Definition Mime.qm.dox.h:212
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:298
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition Mime.qm.dox.h:218
const MimeTypeHtml
MIME type for HTML.
Definition Mime.qm.dox.h:215
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition Mime.qm.dox.h:236
const MimeTypePython
Mime type for Python sources.
Definition Mime.qm.dox.h:284
const MimeTypePhp
Mime type for PHP sources.
Definition Mime.qm.dox.h:290
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition Mime.qm.dox.h:242
const MimeTypeSse
Mime type for server-sent events.
Definition Mime.qm.dox.h:293
const MimeTypeJavaSource
Mime type for Java sources.
Definition Mime.qm.dox.h:275
const MimeTypeQore
Mime type for Qore sources.
Definition Mime.qm.dox.h:272
const MimeTypeOctetStream
MIME type for unknown file types.
Definition Mime.qm.dox.h:209
const MimeTypeJar
Mime type for Java jar files.
Definition Mime.qm.dox.h:281
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition Mime.qm.dox.h:233
const MimeTypeMultipartMixed
Mime type for multipart mixed.
Definition Mime.qm.dox.h:266
const MimeTypeSoapXml
Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023)
Definition Mime.qm.dox.h:227
const MimeTypeYaml
Mime type for yaml data files.
Definition Mime.qm.dox.h:230
const MimeTypeYamlRpc
Mime type for YAML-RPC.
Definition Mime.qm.dox.h:248
const MimeTypeJpeg
MIME type for jpeg images.
Definition Mime.qm.dox.h:221
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition Mime.qm.dox.h:245
const MimeTypeCss
Mime type for css.
Definition Mime.qm.dox.h:254
const MimeTypeJava
Mime type for Java class files.
Definition Mime.qm.dox.h:278
const MimeTypeJson
Mime type for JSON.
Definition Mime.qm.dox.h:239
const MPT_DIGEST
for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1....
Definition Mime.qm.dox.h:549
const MPT_SIGNED
to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2....
Definition Mime.qm.dox.h:558
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition Mime.qm.dox.h:561
const MPT_MIXED
for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5...
Definition Mime.qm.dox.h:543
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387)
Definition Mime.qm.dox.h:555
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616)
Definition Mime.qm.dox.h:564
const MPT_ALTERNATIVE
for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5...
Definition Mime.qm.dox.h:552
const MPT_FORM_DATA
Definition Mime.qm.dox.h:540
const MPT_MESSAGE
for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
Definition Mime.qm.dox.h:546
public Mime namespace defines constants and functions relevant to MIME
Definition Mime.qm.dox.h:168
parsed form-data message part info
Definition Mime.qm.dox.h:190
hash hdr
message or part headers
Definition Mime.qm.dox.h:196
string name
the name of the part
Definition Mime.qm.dox.h:192
data body
the data for the message or part
Definition Mime.qm.dox.h:198
*string filename
the optional filename for the part
Definition Mime.qm.dox.h:194
message and part info hash
Definition Mime.qm.dox.h:172
hash hdr
message or part headers
Definition Mime.qm.dox.h:174
data body
the data for the message or part
Definition Mime.qm.dox.h:176
list< hash< MessageInfo > > part()
parts of the message or subparts of the part
message part hash
Definition Mime.qm.dox.h:182
data data
part body data
Definition Mime.qm.dox.h:184
hash hdr
part header hash
Definition Mime.qm.dox.h:186