Qore MailMessage Module Reference 1.3.3
Loading...
Searching...
No Matches
MailMessage.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* MailMessage.qm Copyright 2012 - 2023 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
114
119namespace MailMessage {
124
128 const EncDefault = "default";
129
131 const EncNone = "none";
132
134 const EncBase64 = ContentTransEncBase64;
135
137 const EncQuotedPrintable = ContentTransEncQuotedPrintable;
138
140 const Encodings = ...;
141
143
145
182 class Message {
183
184public:
186protected:
187 // the sender
188 string from;
189 // subject is a header field
190 string subject;
191
192 // additional headers
193 hash headers; // hash of additional headers except the ones below
194 // message statuses
195 bool importance = False;
196 bool deliveryReceipt = False;
197 bool readReceipt = False;
198
199 // names
200 list<string> to(); // list of names for to (header only) will be prefilled (and overwritten) with the recipients
201 list<string> cc(); // list of cc's
202 list<string> bcc(); // list of bcc's
203
204 // message data itself
205 *data body;
206
207 // message body content transfer encoding
208 string bodyEncoding = EncDefault;
209
210 // message body content type
211 *string bodyContentType;
212
213 // list of Attachments
214 list<Attachment> attachments();
215
216 // list of Parts that are not Attachments (and not the main Message body - could be alternative representations of the body, for example)
217 list<Part> parts();
218
219 string sender;
220
221 // SMTP mode: do not serialize a single "." alone on a line
222 bool smtp_mode = True;
223
224public:
226
228 string mpboundary = replace(make_base64_string(string(now_us())), "=", "");
229
231
243 constructor(string sender, string subject, bool smtp_mode = True);
244
245
247
251 constructor(string msg);
252
253
255
258 string serialize();
259
260
261protected:
262 processPart(hash<auto> p);
263public:
264
265
267 static *string getEmailAddress(string str);
268
270 static bool checkEmailAddress(string str);
271
273
278 list<string> addTO(string recipient);
279
280
282
287 list<string> addCC(string recipient);
288
289
291
296 list<string> addBCC(string recipient);
297
298
300 *string getSender();
301
302
304 *string getFrom();
305
306
308 list<string> getTO();
309
310
312 list<string> getCC();
313
314
316 list<string> getBCC();
317
318
320 string getSubject();
321
322
324 list<string> getRecipients();
325
326
328
336
337
339
347
348
350
356 setBody(data body, string enc = EncDefault, *string content_type);
357
358
360
364 addBody(string str);
365
366
368
372 addBody(binary bin);
373
374
376 *data getBody();
377
378
381
382
384
391 static hash parseHeader(string hdr, bool decode = True);
392
394
400 setHeader(string hdr);
401
402
404
410 setHeader(list hdrs);
411
412
414
418 setHeader(hash hdrs);
419
420
422
426 addHeader(string hdr);
427
428
430
434 addHeader(list<auto> hdrs);
435
436
438
442 addHeader(hash<auto> hdrs);
443
444
446 softlist getHeader();
447
448
450 *hash<auto> getHeaders();
451
452
454
459 bool important();
460
461
463
468 important(softbool i);
469
470
472
476
477
479
482 receiptRead(bool arg);
483
484
486
490
491
493
497
498
500
509 attach(string name, string mime, data att, string enc = EncBase64, *hash<auto> hdr);
510
511
513
516
517
519 list<Attachment> getAttachments();
520
521
523
525 list<Part> getParts();
526
527
529
536 static string doHeaderValue(string hdr, string val, string eol = '\r\n', bool encode = True);
537
539
544 string getHeaderString(string eol = '\r\n', bool encode = True);
545
546
548
550 string toString(bool include_body = False);
551
552
554
556 string toLine();
557
558
560
569 static string checkEncoding(data data, string enc, bool noneok = False);
570
572
578 static string encodeTransferData(data data, string enc, reference<hash> hdr);
579
581 static string encodeData(data data, string mime, string disp, string enc);
582
584
590 static string getLine(reference<string> msg, reference<int> pos);
591
593protected:
594 list<string> getEnvelopeList();
595public:
596
598 };
599
601
607 class Part {
608
609public:
610 // no public members
611
612
614protected:
615 string name;
616 string mime;
617 data part_data;
619 string enc;
620 // any extra headers for the message
621 *hash<auto> headers;
622
623public:
624
625 // will only be called internally when parsing a Message
626 constructor(string filename, string mimetype, data filedata, string encoding = EncDefault, *hash<auto> hdr);
627
629
631 string getName();
632
633
635 string getMime();
636
637
639 data getData();
640
641
644
645
647 *hash<auto> getHeaders();
648
649
651 add(MultiPartAlternativeMessage mpa);
652
653 };
654
656
671class Attachment : public Part {
672
673public:
674 // no public members
675
676
678
688 constructor(string name, string mime, data part_data, string enc = EncBase64, *hash<auto> hdr)
689 ;
690
691
693 add(MultiPartMixedMessage mpm);
694
695 };
696};
class representing a MIME Attachment for the Message
Definition: MailMessage.qm.dox.h:671
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:182
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:228
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 ...
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:607
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:134
const EncQuotedPrintable
"quoted-printable" content transfer encoding
Definition: MailMessage.qm.dox.h:137
const EncDefault
Definition: MailMessage.qm.dox.h:128
const EncNone
no content transfer encoding (not recommended as SMTP servers break up long lines automatically)
Definition: MailMessage.qm.dox.h:131
const Encodings
a list of all known content encoding schemes encodings
Definition: MailMessage.qm.dox.h:140
the MailMessage namespace holds all public definitions in the MailMessage module
Definition: MailMessage.qm.dox.h:119