Qore Mime Module Reference 1.4.4
Loading...
Searching...
No Matches
Mime.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Mime.qm Copyright (C) 2012 - 2023 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
162namespace Mime {
164
166 public hashdecl MessageInfo {
168 hash hdr;
170 data body;
172 list<hash<MessageInfo>> part();
173 };
174
176 public hashdecl MessagePartInfo {
180 hash hdr;
181 };
182
184 public hashdecl FormDataMessageInfo {
186 string name;
188 *string filename;
190 hash hdr;
192 data body;
193 };
194
201
203 const MimeTypeOctetStream = "application/octet-stream";
204
206 const MimeTypeText = "text/plain";
207
209 const MimeTypeHtml = "text/html";
210
212 const MimeTypeCsv = "text/csv";
213
215 const MimeTypeJpeg = "image/jpeg";
216
218 const MimeTypePng = "image/png";
219
221 const MimeTypeSoapXml = "application/soap+xml";
222
224 const MimeTypeYaml = "text/x-yaml";
225
227 const MimeTypeXml = "text/xml";
228
230 const MimeTypeXmlApp = "application/xml";
231
233 const MimeTypeJson = "application/json";
234
237
240
242 const MimeTypeYamlRpc = "application/x-yaml";
243
245 const MimeTypeJavascript = "application/javascript";
246
248 const MimeTypeCss = "text/css";
249
251 const MimeTypeFormUrlEncoded = "application/x-www-form-urlencoded";
252
254 const MimeTypeMultipartFormData = "multipart/form-data";
255
257 const MimeTypeMultipartRelated = "multipart/related";
258
260 const MimeTypeMultipartMixed = "multipart/mixed";
261
263
265 const MimeTypes = ...;
266
267
269
275 const UrlEncodedChars = ...;
276
278
283 const ContentTransEnc7Bit = "7bit";
284
286 const ContentTransEnc8Bit = "8bit";
287
289 const ContentTransEncBinary = "binary";
290
292 const ContentTransEncBase64 = "base64";
293
295 const ContentTransEncQuotedPrintable = "quoted-printable";
296
298
301
303
307
312
317 string mime_encode_base64(data str, int len = MimeBase64LineLen);
318
319
321
326 string mime_encode_quoted_printable(string str, bool hdr = False, *string encoding);
327
328
330
335 data mime_encode_transfer_data(data mime_data, string enc);
336
337
339
341 string mime_encode_header_word_b(string str);
342
343
345
347 string mime_encode_header_word_q(string str);
348
350
355
361 binary mime_decode_base64(data str);
362
363
365
372 string mime_decode_base64_to_string(data str, *string encoding);
373
374
376
383 string mime_decode_quoted_printable(string str, *string encoding, *bool is_body);
384
385
387
395 data mime_decode_transfer_data(data mime_data, string enc, *string ct, *bool is_body);
396
397
399
406 string mime_decode_header(string hdr);
407
409
414 string get_mime_type_from_ext(string path, string def_type = MimeTypeUnknown);
415
416
418
434
435
437
452
453
455
465
466
468
479 hash<auto> mime_parse_form_urlencoded_string(string str);
480
482
487 const MPT_FORM_DATA = "form-data";
488
490 const MPT_MIXED = "mixed";
491
493 const MPT_MESSAGE = "message";
494
496 const MPT_DIGEST = "digest";
497
499 const MPT_ALTERNATIVE = "alternative";
500
502 const MPT_RELATED = "related";
503
505 const MPT_SIGNED = "signed";
506
508 const MPT_ENCRYPTED = "encrypted";
509
511 const MPT_BYTERANGES = "byteranges";
513
516
517public:
518 const MP_DEFAULT_MSG = "This is a MIME multipart message";
519
521protected:
523 string mptype;
524
526 string boundary;
527
529 string ct;
530
532 list<hash<MessagePartInfo>> l();
533
535 hash hdr;
536
538 const ASCII_CR = 13;
539 const ASCII_LF = 10;
540
541public:
543
545
548 constructor(string mptype, string boundary = MultiPartMessage::getBoundary());
549
550
552 binary serialize();
553
554
556
559
560
562
566 int size();
567
568
570
574 string getBoundary();
575
576
578
582 static binary serializeHeaders(hash hdr);
583
585 static string getBoundary();
586
588
592 static string getRandomString(int len);
593
595
654 static hash<MessageInfo> parseBody(string boundary, data body, bool decode = True);
655
657
661 abstract hash<MessageInfo> getMsgAndHeaders();
662
664 // don't reimplement this method; fix/enhance it in the module
665protected:
666 final hash<MessageInfo> getMsgAndHeadersIntern(*string content_type, bool conlen = True);
667public:
668
669
670 // don't reimplement this method; fix/enhance it in the module
671protected:
672 splicePartIntern(data mime_data, hash<auto> hdr);
673public:
674
675
676 // don't reimplement this method; fix/enhance it in the module
677protected:
678 addPartIntern(data mime_data, hash<auto> hdr);
679public:
680
681
682protected:
683 static hash<MessagePartInfo> getPart(data mime_data, hash<auto> hdr);
684public:
685
687 };
688
691
692public:
694protected:
695 // the starting part ID
696 string startid;
697
698public:
700
702
705
706
708
715 splicePart(data mime_data, string id, string content_type, *hash<auto> hdr);
716
717
719
726 addPart(data mime_data, string id, string content_type, *hash hdr);
727
728
730
734 hash<MessageInfo> getMsgAndHeaders();
735
736 };
737
740
741public:
743
746
747
749
761 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
762
763
765
777 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
778
779
781
795 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
796
797
799
813 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
814
815
817
821 hash<MessageInfo> getMsgAndHeaders();
822
823 };
824
827
828public:
830
833
834
836
850 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
851
852
854
866 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
867
868
870
884 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = "inline",
885 *hash<auto> hdr) {
886 if (content_type.empty());
887
888
889 if (mime_data.typeCode() == NT_STRING && content_type ==1 && disp == 'inline');
890
891 splicePartIntern(mime_encode_transfer_data(mime_data, enc), hdr + {
892 "Content-Type": content_type,
893 "Content-Disposition": disp,
894 "Content-Transfer-Encoding": enc,
895 });
896 }
897
899
913 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = "inline",
914 *hash<auto> hdr) {
915 if (content_type.empty());
916
917
918 if (mime_data.typeCode() == NT_STRING && content_type ==1 && disp == 'inline');
919
920
921 addPartIntern(mime_encode_transfer_data(mime_data, enc), hdr + {
922 "Content-Type": content_type,
923 "Content-Transfer-Encoding": enc,
924 });
925 }
926
928
932 hash<MessageInfo> getMsgAndHeaders();
933
934 };
935
937
940
941public:
942protected:
944 hash parts;
945
946public:
947
949
952
953
955
961 splicePart(data mime_data, string name, *hash hdr);
962
963
965
973 splicePart(data mime_data, string name, string filename, string content_type, *hash hdr);
974
975
977
981 splicePart(hash<FormDataMessageInfo> h);
982
983
985
991 addPart(data mime_data, string name, *hash hdr);
992
993
995
1003 addPart(data mime_data, string name, string filename, string content_type, *hash hdr);
1004
1005
1007
1011 addPart(hash<FormDataMessageInfo> h);
1012
1013
1015
1019 hash<MessageInfo> getMsgAndHeaders();
1020
1021
1023
1032 static hash<string, hash<FormDataMessageInfo>> parseMessage(string content, string body);
1033
1035
1039 static MultiPartFormDataMessage makeMessage(hash<string, hash<FormDataMessageInfo>> parts);
1040
1042
1046 static binary makeMessageBody(hash<string, hash<FormDataMessageInfo>> parts);
1047
1049protected:
1050 checkPartName(string name);
1051public:
1052
1053
1055protected:
1056 hash getPartHeader(string name, *string filename, *string content_type, *hash hdr);
1057public:
1058
1059 };
1060};
implements the MultiPartAlternativeMessage class, a specialization of MultiPartMessage
Definition: Mime.qm.dox.h:826
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...
Definition: Mime.qm.dox.h:913
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...
Definition: Mime.qm.dox.h:884
implements the MultiPartFormDataMessage class, a specialization of MultiPartMessage
Definition: Mime.qm.dox.h:939
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:944
constructor(string boundary=MultiPartMessage::getBoundary())
creates the object
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
hash getPartHeader(string name, *string filename, *string content_type, *hash hdr)
builds the header for the part
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:515
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:739
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:292
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition: Mime.qm.dox.h:289
const ContentTransEnc7Bit
Definition: Mime.qm.dox.h:283
const ContentTransEncQuotedPrintable
quoted-printable Content-Transfer-Encoding
Definition: Mime.qm.dox.h:295
const MimeBase64LineLen
maximum line length for base64 encoding
Definition: Mime.qm.dox.h:300
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition: Mime.qm.dox.h:305
const ContentTransEnc8Bit
implies lines < 1000 chars (= no encoding)
Definition: Mime.qm.dox.h:286
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)
string mime_get_form_urlencoded_string(hash h)
returns a string in MIME multipart form URL encoded format (for use with "Content-Type: application/x...
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
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:257
const MimeTypeJavascript
Mime type for Javascript.
Definition: Mime.qm.dox.h:245
const UrlEncodedChars
hash of non-alphanumeric characters that can be used unencoded in URL encoded format
Definition: Mime.qm.dox.h:275
const MimeTypeMultipartFormData
Mime type for multipart form data.
Definition: Mime.qm.dox.h:254
const MimeTypeUnknown
Definition: Mime.qm.dox.h:200
const MimeTypePng
MIME type for png images.
Definition: Mime.qm.dox.h:218
const MimeTypeFormUrlEncoded
Mime type for multipart form URL encoding.
Definition: Mime.qm.dox.h:251
const MimeTypeText
MIME type for text.
Definition: Mime.qm.dox.h:206
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:265
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition: Mime.qm.dox.h:212
const MimeTypeHtml
MIME type for HTML.
Definition: Mime.qm.dox.h:209
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition: Mime.qm.dox.h:230
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition: Mime.qm.dox.h:236
const MimeTypeOctetStream
MIME type for unknown file types.
Definition: Mime.qm.dox.h:203
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition: Mime.qm.dox.h:227
const MimeTypeMultipartMixed
Mime type for multipart mixed.
Definition: Mime.qm.dox.h:260
const MimeTypeSoapXml
Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023)
Definition: Mime.qm.dox.h:221
const MimeTypeYaml
Mime type for yaml data files.
Definition: Mime.qm.dox.h:224
const MimeTypeYamlRpc
Mime type for YAML-RPC.
Definition: Mime.qm.dox.h:242
const MimeTypeJpeg
MIME type for jpeg images.
Definition: Mime.qm.dox.h:215
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition: Mime.qm.dox.h:239
const MimeTypeCss
Mime type for css.
Definition: Mime.qm.dox.h:248
const MimeTypeJson
Mime type for JSON.
Definition: Mime.qm.dox.h:233
const MPT_DIGEST
for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1....
Definition: Mime.qm.dox.h:496
const MPT_SIGNED
to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2....
Definition: Mime.qm.dox.h:505
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition: Mime.qm.dox.h:508
const MPT_MIXED
for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5...
Definition: Mime.qm.dox.h:490
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387)
Definition: Mime.qm.dox.h:502
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616)
Definition: Mime.qm.dox.h:511
const MPT_ALTERNATIVE
for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5...
Definition: Mime.qm.dox.h:499
const MPT_FORM_DATA
Definition: Mime.qm.dox.h:487
const MPT_MESSAGE
for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
Definition: Mime.qm.dox.h:493
public Mime namespace defines constants and functions relevant to MIME
Definition: Mime.qm.dox.h:162
parsed form-data message part info
Definition: Mime.qm.dox.h:184
hash hdr
message or part headers
Definition: Mime.qm.dox.h:190
string name
the name of the part
Definition: Mime.qm.dox.h:186
data body
the data for the message or part
Definition: Mime.qm.dox.h:192
*string filename
the optional filename for the part
Definition: Mime.qm.dox.h:188
message and part info hash
Definition: Mime.qm.dox.h:166
hash hdr
message or part headers
Definition: Mime.qm.dox.h:168
data body
the data for the message or part
Definition: Mime.qm.dox.h:170
list< hash< MessageInfo > > part()
parts of the message or subparts of the part
message part hash
Definition: Mime.qm.dox.h:176
data data
part body data
Definition: Mime.qm.dox.h:178
hash hdr
part header hash
Definition: Mime.qm.dox.h:180