Qore Mime Module Reference 1.6.1
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
175namespace Mime {
177
179 public hashdecl MessageInfo {
181 hash hdr;
183 data body;
185 list<hash<MessageInfo>> part();
186 };
187
189 public hashdecl MessagePartInfo {
193 hash hdr;
194 };
195
197 public hashdecl FormDataMessageInfo {
199 string name;
201 *string filename;
203 hash hdr;
205 data body;
206 };
207
214
216 const MimeTypeOctetStream = "application/octet-stream";
217
219 const MimeTypeText = "text/plain";
220
222 const MimeTypeHtml = "text/html";
223
225 const MimeTypeCsv = "text/csv";
226
228 const MimeTypeJpeg = "image/jpeg";
229
231 const MimeTypePng = "image/png";
232
234 const MimeTypeSoapXml = "application/soap+xml";
235
237 const MimeTypeYaml = "text/x-yaml";
238
240 const MimeTypeXml = "text/xml";
241
243 const MimeTypeXmlApp = "application/xml";
244
246 const MimeTypeJson = "application/json";
247
250
253
255 const MimeTypeYamlRpc = "application/x-yaml";
256
258 const MimeTypeJavascript = "application/javascript";
259
261 const MimeTypeCss = "text/css";
262
264 const MimeTypeFormUrlEncoded = "application/x-www-form-urlencoded";
265
267 const MimeTypeMultipartFormData = "multipart/form-data";
268
270 const MimeTypeMultipartRelated = "multipart/related";
271
273 const MimeTypeMultipartMixed = "multipart/mixed";
274
276 const MimeTypeSvg = "image/svg+xml";
277
279 const MimeTypeQore = "text/x-qore";
280
282 const MimeTypeJavaSource = "text/x-java-source";
283
285 const MimeTypeJava = "application/java";
286
288 const MimeTypeJar = "application/java-archive";
289
291 const MimeTypePython = "text/x-python-source";
292
294 const MimeTypePythonCode = "application/x-python-code";
295
297 const MimeTypePdf = "application/pdf";
298
300 const MimeTypePhp = "application/x-httpd-php";
301
303 const MimeTypeSse = "text/event-stream";
304
306
308 const MimeTypes = ...;
309
310
312
318 const UrlEncodedChars = ...;
319
321
326 const ContentTransEnc7Bit = "7bit";
327
329 const ContentTransEnc8Bit = "8bit";
330
332 const ContentTransEncBinary = "binary";
333
335 const ContentTransEncBase64 = "base64";
336
338 const ContentTransEncQuotedPrintable = "quoted-printable";
339
341
344
346
350
355
360 string mime_encode_base64(data str, int len = MimeBase64LineLen);
361
362
364
369 string mime_encode_quoted_printable(string str, bool hdr = False, *string encoding);
370
371
373
378 data mime_encode_transfer_data(data mime_data, string enc);
379
380
382
384 string mime_encode_header_word_b(string str);
385
386
388
390 string mime_encode_header_word_q(string str);
391
393
398
404 binary mime_decode_base64(data str);
405
406
408
415 string mime_decode_base64_to_string(data str, *string encoding);
416
417
419
426 string mime_decode_quoted_printable(string str, *string encoding, *bool is_body);
427
428
430
438 data mime_decode_transfer_data(data mime_data, string enc, *string ct, *bool is_body);
439
440
442
449 string mime_decode_header(string hdr);
450
452
457
463 bool is_mime_text(string mime);
464
465
467
473 bool is_filename_text(string path);
474
475
477 string get_mime_type_from_ext(string path, string def_type = MimeTypeUnknown);
478
479
481
499
500
502
517
518
520
532
533
535
546 hash<auto> mime_parse_form_urlencoded_string(string str);
547
549
554 const MPT_FORM_DATA = "form-data";
555
557 const MPT_MIXED = "mixed";
558
560 const MPT_MESSAGE = "message";
561
563 const MPT_DIGEST = "digest";
564
566 const MPT_ALTERNATIVE = "alternative";
567
569 const MPT_RELATED = "related";
570
572 const MPT_SIGNED = "signed";
573
575 const MPT_ENCRYPTED = "encrypted";
576
578 const MPT_BYTERANGES = "byteranges";
580
583
584public:
585 const MP_DEFAULT_MSG = "This is a MIME multipart message";
586
588protected:
590 string mptype;
591
593 string boundary;
594
596 string ct;
597
599 list<hash<MessagePartInfo>> l();
600
602 hash hdr;
603
605 const ASCII_CR = 13;
606 const ASCII_LF = 10;
607
608public:
610
612
615 constructor(string mptype, string boundary = MultiPartMessage::getBoundary());
616
617
619 binary serialize();
620
621
623
626
627
629
633 int size();
634
635
637
641 string getBoundary();
642
643
645
649 static binary serializeHeaders(hash hdr);
650
652 static string getBoundary();
653
655
659 static string getRandomString(int len);
660
662
721 static hash<MessageInfo> parseBody(string boundary, data body, bool decode = True);
722
724
728 abstract hash<MessageInfo> getMsgAndHeaders();
729
731 // don't reimplement this method; fix/enhance it in the module
732protected:
733 final hash<MessageInfo> getMsgAndHeadersIntern(*string content_type, bool conlen = True);
734public:
735
736
737 // don't reimplement this method; fix/enhance it in the module
738protected:
739 splicePartIntern(data mime_data, hash<auto> hdr);
740public:
741
742
743 // don't reimplement this method; fix/enhance it in the module
744protected:
745 addPartIntern(data mime_data, hash<auto> hdr);
746public:
747
748
749protected:
750 static hash<MessagePartInfo> getPart(data mime_data, hash<auto> hdr);
751public:
752
754 };
755
758
759public:
761protected:
762 // the starting part ID
763 string startid;
764
765public:
767
769
772
773
775
782 splicePart(data mime_data, string id, string content_type, *hash<auto> hdr);
783
784
786
793 addPart(data mime_data, string id, string content_type, *hash hdr);
794
795
797
801 hash<MessageInfo> getMsgAndHeaders();
802
803 };
804
807
808public:
810
813
814
816
828 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
829
830
832
844 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
845
846
848
862 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
863
864
866
880 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
881
882
884
888 hash<MessageInfo> getMsgAndHeaders();
889
890 };
891
894
895public:
897
900
901
903
917 splicePart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
918
919
921
933 addPart(data mime_data, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
934
935
937
951 spliceEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
952
953
955
969 addEncodePart(data mime_data, string enc, string content_type = MimeTypeText, string disp = 'inline', *hash<auto> hdr);
970
971
973
977 hash<MessageInfo> getMsgAndHeaders();
978
979 };
980
982
985
986public:
987protected:
989 hash parts;
990
991public:
992
994
997
998
1000
1006 splicePart(data mime_data, string name, *hash hdr);
1007
1008
1010
1018 splicePart(data mime_data, string name, string filename, string content_type, *hash hdr);
1019
1020
1022
1026 splicePart(hash<FormDataMessageInfo> h);
1027
1028
1030
1036 addPart(data mime_data, string name, *hash hdr);
1037
1038
1040
1048 addPart(data mime_data, string name, string filename, string content_type, *hash hdr);
1049
1050
1052
1056 addPart(hash<FormDataMessageInfo> h);
1057
1058
1060
1064 hash<MessageInfo> getMsgAndHeaders();
1065
1066
1068
1077 static hash<string, hash<FormDataMessageInfo>> parseMessage(string content, string body);
1078
1080
1084 static MultiPartFormDataMessage makeMessage(hash<string, hash<FormDataMessageInfo>> parts);
1085
1087
1091 static binary makeMessageBody(hash<string, hash<FormDataMessageInfo>> parts);
1092
1094protected:
1095 checkPartName(string name);
1096public:
1097
1098
1100protected:
1101 hash getPartHeader(string name, *string filename, *string content_type, *hash<auto> hdr);
1102public:
1103
1104 };
1105};
implements the MultiPartAlternativeMessage class, a specialization of MultiPartMessage
Definition Mime.qm.dox.h:893
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:984
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:989
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:582
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:806
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:335
const ContentTransEncBinary
binary transfer encoding; implies no maximum line length (= no encoding)
Definition Mime.qm.dox.h:332
const ContentTransEnc7Bit
Definition Mime.qm.dox.h:326
const ContentTransEncQuotedPrintable
quoted-printable Content-Transfer-Encoding
Definition Mime.qm.dox.h:338
const MimeBase64LineLen
maximum line length for base64 encoding
Definition Mime.qm.dox.h:343
const MimeQuotedPrintableLineLen
maximum line length for quoted-printable encoding
Definition Mime.qm.dox.h:348
const ContentTransEnc8Bit
implies lines < 1000 chars (= no encoding)
Definition Mime.qm.dox.h:329
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:270
const MimeTypeJavascript
Mime type for Javascript.
Definition Mime.qm.dox.h:258
const MimeTypePdf
Mime type for PDF documents.
Definition Mime.qm.dox.h:297
const MimeTypeSvg
Mime type for SVG files.
Definition Mime.qm.dox.h:276
const UrlEncodedChars
hash of non-alphanumeric characters that can be used unencoded in URL encoded format
Definition Mime.qm.dox.h:318
const MimeTypeMultipartFormData
Mime type for multipart form data.
Definition Mime.qm.dox.h:267
const MimeTypePythonCode
Mime type for Python compiled code.
Definition Mime.qm.dox.h:294
const MimeTypeUnknown
Definition Mime.qm.dox.h:213
const MimeTypePng
MIME type for png images.
Definition Mime.qm.dox.h:231
const MimeTypeFormUrlEncoded
Mime type for multipart form URL encoding.
Definition Mime.qm.dox.h:264
const MimeTypeText
MIME type for text.
Definition Mime.qm.dox.h:219
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:308
const MimeTypeCsv
MIME type for csv files (http://tools.ietf.org/html/rfc4180)
Definition Mime.qm.dox.h:225
const MimeTypeHtml
MIME type for HTML.
Definition Mime.qm.dox.h:222
const MimeTypeXmlApp
Mime type for more complicated (not human-readable) xml files.
Definition Mime.qm.dox.h:243
const MimeTypePython
Mime type for Python sources.
Definition Mime.qm.dox.h:291
const MimeTypePhp
Mime type for PHP sources.
Definition Mime.qm.dox.h:300
const MimeTypeJsonRpc
Mime type for JSON-RPC.
Definition Mime.qm.dox.h:249
const MimeTypeSse
Mime type for server-sent events.
Definition Mime.qm.dox.h:303
const MimeTypeJavaSource
Mime type for Java sources.
Definition Mime.qm.dox.h:282
const MimeTypeQore
Mime type for Qore sources.
Definition Mime.qm.dox.h:279
const MimeTypeOctetStream
MIME type for unknown file types.
Definition Mime.qm.dox.h:216
const MimeTypeJar
Mime type for Java jar files.
Definition Mime.qm.dox.h:288
const MimeTypeXml
Mime type for plain (human-readable) xml files.
Definition Mime.qm.dox.h:240
const MimeTypeMultipartMixed
Mime type for multipart mixed.
Definition Mime.qm.dox.h:273
const MimeTypeSoapXml
Mime type for SOAP XML messages (XML MIME type reference: http://tools.ietf.org/html/rfc3023)
Definition Mime.qm.dox.h:234
const MimeTypeYaml
Mime type for yaml data files.
Definition Mime.qm.dox.h:237
const MimeTypeYamlRpc
Mime type for YAML-RPC.
Definition Mime.qm.dox.h:255
const MimeTypeJpeg
MIME type for jpeg images.
Definition Mime.qm.dox.h:228
const MimeTypeXmlRpc
Mime type for XML-RPC.
Definition Mime.qm.dox.h:252
const MimeTypeCss
Mime type for css.
Definition Mime.qm.dox.h:261
const MimeTypeJava
Mime type for Java class files.
Definition Mime.qm.dox.h:285
const MimeTypeJson
Mime type for JSON.
Definition Mime.qm.dox.h:246
const MPT_DIGEST
for sending multiple text messages (http://tools.ietf.org/html/rfc2046#section-5.1....
Definition Mime.qm.dox.h:563
const MPT_SIGNED
to attach a digital signature to a message (http://tools.ietf.org/html/rfc1847#section-2....
Definition Mime.qm.dox.h:572
const MPT_ENCRYPTED
for sending encrypted messages (http://tools.ietf.org/html/rfc1847#section-2.2)
Definition Mime.qm.dox.h:575
const MPT_MIXED
for sending files with different "Content-Type" headers (http://tools.ietf.org/html/rfc2046#section-5...
Definition Mime.qm.dox.h:557
const MPT_RELATED
for sending multiple components of an aggregated whole (http://tools.ietf.org/html/rfc2387)
Definition Mime.qm.dox.h:569
const MPT_BYTERANGES
for sending noncontiguous byte ranges of a single message (http://tools.ietf.org/html/rfc2616)
Definition Mime.qm.dox.h:578
const MPT_ALTERNATIVE
for sending multiple "alternatives" of the same content (http://tools.ietf.org/html/rfc2046#section-5...
Definition Mime.qm.dox.h:566
const MPT_FORM_DATA
Definition Mime.qm.dox.h:554
const MPT_MESSAGE
for email/MIME messages with headers (http://tools.ietf.org/html/rfc2046)
Definition Mime.qm.dox.h:560
public Mime namespace defines constants and functions relevant to MIME
Definition Mime.qm.dox.h:175
parsed form-data message part info
Definition Mime.qm.dox.h:197
hash hdr
message or part headers
Definition Mime.qm.dox.h:203
string name
the name of the part
Definition Mime.qm.dox.h:199
data body
the data for the message or part
Definition Mime.qm.dox.h:205
*string filename
the optional filename for the part
Definition Mime.qm.dox.h:201
message and part info hash
Definition Mime.qm.dox.h:179
hash hdr
message or part headers
Definition Mime.qm.dox.h:181
data body
the data for the message or part
Definition Mime.qm.dox.h:183
list< hash< MessageInfo > > part()
parts of the message or subparts of the part
message part hash
Definition Mime.qm.dox.h:189
data data
part body data
Definition Mime.qm.dox.h:191
hash hdr
part header hash
Definition Mime.qm.dox.h:193