Qore MailMessage Module Reference 1.4
Loading...
Searching...
No Matches
MailMessage.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* MailMessage.qm Copyright 2012 - 2024 Qore Technologies, s.r.o.
5
6 Original Authors: Wolfgang Ritzinger, Marian Bonda, Pavol Potoncok
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 and/or sell copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25*/
26
27// minimum qore version
28
29// need mime definitions
30
31// assume local var scope, do not use "$" for vars, members, and method calls
32// require type declarations everywhere
33// disallows access to backwards-compatible "noop" variants
34// enables all warnings
35
36
121
126namespace MailMessage {
128public hashdecl PartInfo {
130 string name;
131
133 string mime;
134
137
139 *hash<auto> headers;
140
143};
144
146public hashdecl MailMessageInfo {
148 *string from;
149
151 *string sender;
152
154 *string subject;
155
157 *list<string> to;
158
160 *list<string> cc;
161
163 *list<string> bcc;
164
166 *data body;
167
170
173
175 *hash<auto> headers;
176
179
182
185
187 *list<hash<PartInfo>> attachments;
188
190 *list<hash<PartInfo>> parts;
191};
192
197
201const EncDefault = "default";
202
204const EncNone = "none";
205
207const EncBase64 = ContentTransEncBase64;
208
210const EncQuotedPrintable = ContentTransEncQuotedPrintable;
211
213const Encodings = ...;
214
216
218
255class Message {
256
257public:
259protected:
260 // the sender
261 string from;
262 // subject is a header field
263 string subject;
264
265 // additional headers
266 hash headers; // hash of additional headers except the ones below
267 // message statuses
268 bool importance = False;
269 bool deliveryReceipt = False;
270 bool readReceipt = False;
271
272 // names
273 list<string> to(); // list of names for to (header only) will be prefilled (and overwritten) with the recipients
274 list<string> cc(); // list of cc's
275 list<string> bcc(); // list of bcc's
276
277 // message data itself
278 *data body;
279
280 // message body content transfer encoding
281 string bodyEncoding = EncDefault;
282
283 // message body content type
284 *string bodyContentType;
285
286 // list of Attachments
287 list<Attachment> attachments();
288
289 // list of Parts that are not Attachments (and not the main Message body - could be alternative representations of the body, for example)
290 list<Part> parts();
291
292 string sender;
293
294 // SMTP mode: do not serialize a single "." alone on a line
295 bool smtp_mode = True;
296
297public:
299
301 string mpboundary = replace(make_base64_string(string(now_us())), "=", "");
302
304
316 constructor(string sender, string subject, bool smtp_mode = True);
317
318
320
324 constructor(string msg);
325
326
328 hash<MailMessageInfo> getInfo();
329
330
332
335 string serialize();
336
337
338protected:
339 processPart(hash<auto> p);
340public:
341
342
344 static *string getEmailAddress(string str);
345
347 static bool checkEmailAddress(string str);
348
350
355 list<string> addTO(string recipient);
356
357
359
364 list<string> addCC(string recipient);
365
366
368
373 list<string> addBCC(string recipient);
374
375
377 *string getSender();
378
379
381 *string getFrom();
382
383
385 list<string> getTO();
386
387
389 list<string> getCC();
390
391
393 list<string> getBCC();
394
395
397 string getSubject();
398
399
401 list<string> getRecipients();
402
403
405
413
414
416
424
425
427
433 setBody(data body, string enc = EncDefault, *string content_type);
434
435
437
441 addBody(string str);
442
443
445
449 addBody(binary bin);
450
451
453 *data getBody();
454
455
458
459
461
468 static hash parseHeader(string hdr, bool decode = True);
469
471
477 setHeader(string hdr);
478
479
481
487 setHeader(list hdrs);
488
489
491
495 setHeader(hash hdrs);
496
497
499
503 addHeader(string hdr);
504
505
507
511 addHeader(list<auto> hdrs);
512
513
515
519 addHeader(hash<auto> hdrs);
520
521
523 softlist getHeader();
524
525
527 *hash<auto> getHeaders();
528
529
531
536 bool important();
537
538
540
545 important(softbool i);
546
547
549
553
554
556
559 receiptRead(bool arg);
560
561
563
567
568
570
574
575
577
586 attach(string name, string mime, data att, string enc = EncBase64, *hash<auto> hdr);
587
588
590
593
594
596 list<Attachment> getAttachments();
597
598
600
602 list<Part> getParts();
603
604
606
613 static string doHeaderValue(string hdr, string val, string eol = '\r\n', bool encode = True);
614
616
621 string getHeaderString(string eol = '\r\n', bool encode = True);
622
623
625
627 string toString(bool include_body = False);
628
629
631
633 string toLine();
634
635
637
646 static string checkEncoding(data data, string enc, bool noneok = False);
647
649
655 static string encodeTransferData(data data, string enc, reference<hash> hdr);
656
658 static string encodeData(data data, string mime, string disp, string enc);
659
661
667 static string getLine(reference<string> msg, reference<int> pos);
668
670protected:
671 list<string> getEnvelopeList();
672public:
673
675};
676
678
684class Part {
685
686public:
687 // no public members
688
689
691protected:
692 string name;
693 string mime;
694 data part_data;
696 string enc;
697 // any extra headers for the message
698 *hash<auto> headers;
699
700public:
701
702 // will only be called internally when parsing a Message
703 constructor(string filename, string mimetype, data filedata, string encoding = EncDefault, *hash<auto> hdr);
704
706
708 hash<auto> getInfo();
709
710
712 string getName();
713
714
716 string getMime();
717
718
720 data getData();
721
722
725
726
728 *hash<auto> getHeaders();
729
730
732 add(MultiPartAlternativeMessage mpa);
733
734};
735
737
752class Attachment : public Part {
753
754public:
755 // no public members
756
757
759
769 constructor(string name, string mime, data part_data, string enc = EncBase64, *hash<auto> hdr) ;
770
771
773 add(MultiPartMixedMessage mpm);
774
775};
776};
class representing a MIME Attachment for the Message
Definition MailMessage.qm.dox.h:752
constructor(string name, string mime, data part_data, string enc=EncBase64, *hash< auto > hdr)
creates an Attachment object for a Message object
add(MultiPartMixedMessage mpm)
adds itself to a multipart/mixed message
The Message class holds the information for a single email Message.
Definition MailMessage.qm.dox.h:255
constructor(string sender, string subject, bool smtp_mode=True)
creates a Message object from the arguments given
receiptDelivery(bool arg)
sets the delivery receipt setting
string mpboundary
create a different multipart boundary string every time based on the current time
Definition MailMessage.qm.dox.h:301
string getBodyTransferEncoding()
returns the transfer encoding for the mssage body (see Message Encodings for possible values)
bool important()
returns the current importance setting
string toString(bool include_body=False)
returns a multi-line string representing the Message
list< string > addTO(string recipient)
add a recipient to the Message's recipient list
addHeader(string hdr)
adds a header to the Message
bool receiptRead()
returns the current read delivery receipt setting
attach(Attachment att)
adds an Attachment to the Message
static string doHeaderValue(string hdr, string val, string eol='\r\n', bool encode=True)
encodes a header value according to the parameters
static string encodeData(data data, string mime, string disp, string enc)
returns a string of message data according to the encoding passed
checkSendPossible()
throws a MESSAGE-ERROR exception if the Message cannot be sent
string serialize()
serializes the message to a string that can be sent to an SMTP server, for example
static string getLine(reference< string > msg, reference< int > pos)
returns the first "\r\n" terminated line from the argument, updates the byte position argument
setBody(data body, string enc=EncDefault, *string content_type)
sets or replaces the Message body
addHeader(list< auto > hdrs)
adds a list of headers to the Message
list< string > addBCC(string recipient)
add a recipient to the Message's bcc list
static bool checkEmailAddress(string str)
returns True if the string contains an email address, False if not
setHeader(hash hdrs)
sets/replaces the list of Message headers from a hash of header info
static string encodeTransferData(data data, string enc, reference< hash > hdr)
returns a string of message data according to the encoding passed
string getHeaderString(string eol='\r\n', bool encode=True)
returns a string of the message headers
receiptRead(bool arg)
sets the read delivery receipt setting
setHeader(list hdrs)
sets/replaces the list of Message headers from a list of header strings
list< Part > getParts()
returns a list of non-attachment Part objects for the Message
*data getBody()
returns the Message body
attach(string name, string mime, data att, string enc=EncBase64, *hash< auto > hdr)
creates an attachment for the Message
list< string > addCC(string recipient)
add a recipient to the Message's cc list
string toLine()
returns a single line string summarizing the Message
list< string > getRecipients()
return all the email addresses the message will be sent to, a combination of the "To:",...
list< Attachment > getAttachments()
returns a list of Attachment objects for the Message
static *string getEmailAddress(string str)
fetch the email address out of a sender/rcpt string
*string getFrom()
returns the sender's email address
static string checkEncoding(data data, string enc, bool noneok=False)
checks the data against the encoding and returns the new encoding (if the encoding is EncDefault for ...
hash< MailMessageInfo > getInfo()
Returns information about the message.
list< string > getTO()
returns the list of "To:" addresses
list< string > getBCC()
returns the list of "BCC:" addresses
bool receiptDelivery()
returns the delivery receipt setting
setHeader(string hdr)
sets/replaces the Message headers
string getSubject()
returns the subject of the Message
softlist getHeader()
returns the current Message headers as a list of strings
bool sendPossible()
returns True if the message can be sent, False if not
addBody(string str)
concatenates a string to the message body
important(softbool i)
sets the importance setting
*string getSender()
returns the sender's address in display format
addHeader(hash< auto > hdrs)
adds a hash of headers to the Message
*hash< auto > getHeaders()
returns the current Message headers as a hash
constructor(string msg)
creates a Message object from raw message text from a received email message
list< string > getCC()
returns the list of "CC:" addresses
static hash parseHeader(string hdr, bool decode=True)
parses the given string representing a header line and returns a single key - value hash for the head...
addBody(binary bin)
concatenates a binary object to the message body
class representing a MIME part of a Message
Definition MailMessage.qm.dox.h:684
hash< auto > getInfo()
Returns information about the part.
add(MultiPartAlternativeMessage mpa)
adds itself to a multipart/alternative message
string getTransferEncoding()
returns the transfer encoding of the Part
*hash< auto > getHeaders()
returns any headers for the Part
string getName()
returns the name of the Part
string getMime()
returns the mime type of the Part
data getData()
returns the data of the Part
const EncBase64
base-64 content transfer encoding
Definition MailMessage.qm.dox.h:207
const EncQuotedPrintable
"quoted-printable" content transfer encoding
Definition MailMessage.qm.dox.h:210
const EncDefault
Definition MailMessage.qm.dox.h:201
const EncNone
no content transfer encoding (not recommended as SMTP servers break up long lines automatically)
Definition MailMessage.qm.dox.h:204
const Encodings
a list of all known content encoding schemes encodings
Definition MailMessage.qm.dox.h:213
the MailMessage namespace holds all public definitions in the MailMessage module
Definition MailMessage.qm.dox.h:126
Message info.
Definition MailMessage.qm.dox.h:146
*string body_encoding
The encoding used for the message body, if any.
Definition MailMessage.qm.dox.h:169
*string sender
The sender's email address.
Definition MailMessage.qm.dox.h:151
*string from
The From: address.
Definition MailMessage.qm.dox.h:148
*list< string > cc
Any CC: addresses.
Definition MailMessage.qm.dox.h:160
*bool important
The important flag.
Definition MailMessage.qm.dox.h:178
*bool read_receipt
The read receipt flag.
Definition MailMessage.qm.dox.h:184
*list< string > to
Any To: addresses.
Definition MailMessage.qm.dox.h:157
*list< hash< PartInfo > > parts
Any message parts.
Definition MailMessage.qm.dox.h:190
*string subject
The message subject.
Definition MailMessage.qm.dox.h:154
*list< hash< PartInfo > > attachments
Any message attachments.
Definition MailMessage.qm.dox.h:187
*string body_content_type
The content type of the message body.
Definition MailMessage.qm.dox.h:172
*bool delivery_receipt
The delivery receipt flag.
Definition MailMessage.qm.dox.h:181
*data body
The message body, if any.
Definition MailMessage.qm.dox.h:166
*list< string > bcc
Any BCC: addresses.
Definition MailMessage.qm.dox.h:163
*hash< auto > headers
Any message headers.
Definition MailMessage.qm.dox.h:175
Message part info.
Definition MailMessage.qm.dox.h:128
string name
Part name.
Definition MailMessage.qm.dox.h:130
string mime
Part MIME type.
Definition MailMessage.qm.dox.h:133
string transfer_encoding
Part transfer encoding.
Definition MailMessage.qm.dox.h:142
*hash< auto > headers
Part headers, if any.
Definition MailMessage.qm.dox.h:139
data part_data
Part data.
Definition MailMessage.qm.dox.h:136