Qore MailMessage Module Reference  1.3.1
 All Classes Namespaces Functions Variables Groups Pages
MailMessage.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file MailMessage.qm MailMessage module definition
3 
4 /* MailMessage.qm Copyright 2012 - 2017 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 
99 
105 namespace MailMessage {
109 
114  const EncDefault = "default";
115 
117  const EncNone = "none";
118 
121 
124 
126  const Encodings = (
127  EncDefault,
128  EncNone,
129  EncBase64,
131  );
133 
135 
172  class Message {
173 
174 public:
176  private :
177  // the sender
178  string from;
179  // subject is a header field
180  string subject;
181 
182  // additional headers
183  hash headers; // hash of additional headers except the ones below
184  // message statuses
185  bool importance = False;
186  bool deliveryReceipt = False;
187  bool readReceipt = False;
188 
189  // names
190  list<string> to(); // list of names for to (header only) will be prefilled (and overwritten) with the recipients
191  list<string> cc(); // list of cc's
192  list<string> bcc(); // list of bcc's
193 
194  // message data itself
195  *data body;
196 
197  // message body content transfer encoding
198  string bodyEncoding = EncDefault;
199 
200  // message body content type
201  *string bodyContentType;
202 
203  // list of Attachments
204  list<Attachment> attachments();
205 
206  // list of Parts that are not Attachments (and not the main Message body - could be alternative representations of the body, for example)
207  list<Part> parts();
208 
209  string sender;
210 
211 public:
213 
214  public :
216  string mpboundary = replace(make_base64_string(string(now_us())), "=", "");
217 
218 public:
219 
221 
228  constructor(string n_sender, string n_subject);
229 
230 
232 
236  constructor(string msg);
237 
238 
240 
243  string serialize();
244 
245 
246 
247 private:
248  processPart(hash p);
249 public:
250 
251 
253  static *string getEmailAddress(string str);
254 
256  static bool checkEmailAddress(string str);
257 
259 
264  list<string> addTO(string recipient);
265 
266 
268 
273  list<string> addCC(string recipient);
274 
275 
277 
282  list<string> addBCC(string recipient);
283 
284 
286  *string getSender();
287 
288 
290  *string getFrom();
291 
292 
294  list<string> getTO();
295 
296 
298  list<string> getCC();
299 
300 
302  list<string> getBCC();
303 
304 
306  string getSubject();
307 
308 
310  list<string> getRecipients();
311 
312 
314 
321  bool sendPossible();
322 
323 
325 
333 
334 
336 
342  setBody(data n_body, string n_enc = EncDefault, *string n_content_type);
343 
344 
346 
350  addBody(string str);
351 
352 
354 
358  addBody(binary bin);
359 
360 
362  *data getBody();
363 
364 
366  string getBodyTransferEncoding();
367 
368 
370 
377  static hash parseHeader(string hdr, bool decode = True);
378 
380 
386  setHeader(string hdr);
387 
388 
390 
396  setHeader(list hdrs);
397 
398 
400 
404  setHeader(hash hdrs);
405 
406 
408 
412  addHeader(string hdr);
413 
414 
416 
420  addHeader(list hdrs);
421 
422 
424 
428  addHeader(hash hdrs);
429 
430 
432  softlist getHeader();
433 
434 
436  *hash getHeaders();
437 
438 
440 
445  bool important();
446 
447 
449 
454  important(softbool i);
455 
456 
458 
461  bool receiptRead();
462 
463 
465 
468  receiptRead(bool arg);
469 
470 
472 
475  bool receiptDelivery();
476 
477 
479 
482  receiptDelivery(bool arg);
483 
484 
486 
495  attach(string name, string mime, data att, string enc = EncDefault, *hash hdr);
496 
497 
499 
501  attach(Attachment att);
502 
503 
505  list<Attachment> getAttachments();
506 
507 
509 
511  list<Part> getParts();
512 
513 
515 
522  static string doHeaderValue(string hdr, string val, string eol = "\r\n", bool encode = True);
523 
525 
530  string getHeaderString(string eol = "\r\n", bool encode = True);
531 
532 
534 
536  string toString(bool include_body = False);
537 
538 
540 
542  string toLine();
543 
544 
546 
555  static string checkEncoding(data data, string enc, bool noneok = False);
556 
558 
564  static string encodeTransferData(data data, string enc, reference<hash> hdr);
565 
567  static string encodeData(data data, string mime, string disp, string enc);
568 
570 
576  static string getLine(reference<string> msg, reference<int> pos);
577 
579 
580 private:
581  list<string> getEnvelopeList();
582 public:
583 
585  };
586 
588 
594  class Part {
595 
596 public:
597  // no public members
598 private:
599 
600 public:
601 
603  private :
604  string name;
605  string mime;
606  data data;
608  string enc;
609  // any extra headers for the message
610  *hash headers;
611 
612 public:
613 
614  // will only be called internally when parsing a Message
615  constructor(string filename, string mimetype, data filedata, string encoding = EncDefault, *hash hdr);
616 
618 
620  string getName();
621 
622 
624  string getMime();
625 
626 
628  data getData();
629 
630 
632  string getTransferEncoding();
633 
634 
636  *hash getHeaders();
637 
638 
640  add(MultiPartMixedMessage mpm);
641 
642  };
643 
645 
660 class Attachment : public Part {
661 
662 public:
663  // no public members
664 private:
665 
666 public:
667 
669 
678  constructor(string name, string mime, data data, string enc = EncDefault, *hash hdr) ;
679 
680  };
681 };
string getHeaderString(string eol="\r\n", bool encode=True)
returns a string of the message headers
data getData()
returns the data of the Part
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(string str)
concatenates a string to the message body
list< Attachment > getAttachments()
returns a list of Attachment objects for the Message
addHeader(string hdr)
adds a header to the Message
class representing a MIME part of a Message
Definition: MailMessage.qm.dox.h:594
const Encodings
a list of all known content encoding schemes encodings
Definition: MailMessage.qm.dox.h:126
static string encodeTransferData(data data, string enc, reference< hash > hdr)
returns a string of message data according to the encoding passed
date now_us()
*string getSender()
returns the sender&#39;s address in display format
string toLine()
returns a single line string summarizing the Message
The Message class holds the information for a single email Message.
Definition: MailMessage.qm.dox.h:172
string make_base64_string(string str, softint maxlinelen=-1)
static *string getEmailAddress(string str)
fetch the email address out of a sender/rcpt string
softlist getHeader()
returns the current Message headers as a list of strings
*hash getHeaders()
returns any headers for the Part
const True
string getMime()
returns the mime type of the Part
string getSubject()
returns the subject of the Message
list< string > getTO()
returns the list of &quot;To:&quot; addresses
bool sendPossible()
returns True if the message can be sent, False if not
binary binary()
list< string > getCC()
returns the list of &quot;CC:&quot; addresses
list< string > addBCC(string recipient)
add a recipient to the Message&#39;s bcc list
const ContentTransEncBase64
attach(string name, string mime, data att, string enc=EncDefault, *hash hdr)
creates an attachment for the Message
const False
string replace(string str, string source, string target, int start=0, int end=-1)
list list(...)
*hash getHeaders()
returns the current Message headers as a hash
const EncQuotedPrintable
&quot;quoted-printable&quot; content transfer encoding
Definition: MailMessage.qm.dox.h:123
bool important()
returns the current importance setting
class representing a MIME Attachment for the Message
Definition: MailMessage.qm.dox.h:660
*data getBody()
returns the Message body
list< Part > getParts()
returns a list of non-attachment Part objects for the Message
constructor(string name, string mime, data data, string enc=EncDefault, *hash hdr)
creates an Attachment object for a Message object
constructor(string n_sender, string n_subject)
creates a Message object from the arguments given; this variant of the constructor is designed to be ...
bool receiptRead()
returns the current read delivery receipt setting
string mpboundary
create a different multipart boundary string every time based on the current time ...
Definition: MailMessage.qm.dox.h:216
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 ...
string getTransferEncoding()
returns the transfer encoding of the Part
string serialize()
serializes the message to a string that can be sent to an SMTP server, for example ...
const EncBase64
base-64 content transfer encoding
Definition: MailMessage.qm.dox.h:120
static string doHeaderValue(string hdr, string val, string eol="\r\n", bool encode=True)
encodes a header value according to the parameters
string getBodyTransferEncoding()
returns the transfer encoding for the mssage body (see Message Encodings for possible values) ...
list< string > getRecipients()
return all the email addresses the message will be sent to, a combination of the &quot;To:&quot;, &quot;CC:&quot;, and &quot;BCC:&quot; lists
const ContentTransEncQuotedPrintable
static string getLine(reference< string > msg, reference< int > pos)
returns the first &quot;\r\n&quot; terminated line from the argument, updates the byte position argument ...
setHeader(string hdr)
sets/replaces the Message headers
setBody(data n_body, string n_enc=EncDefault, *string n_content_type)
sets or replaces the Message body
const EncNone
no content transfer encoding (not recommended as SMTP servers break up long lines automatically) ...
Definition: MailMessage.qm.dox.h:117
add(MultiPartMixedMessage mpm)
adds itself to a multipart/mixed message
static string encodeData(data data, string mime, string disp, string enc)
returns a string of message data according to the encoding passed
string getName()
returns the name of the Part
list< string > getBCC()
returns the list of &quot;BCC:&quot; addresses
static bool checkEmailAddress(string str)
returns True if the string contains an email address, False if not
*string getFrom()
returns the sender&#39;s email address
bool receiptDelivery()
returns the delivery receipt setting
hash hash(object obj)
checkSendPossible()
throws a MESSAGE-ERROR exception if the Message cannot be sent
list< string > addCC(string recipient)
add a recipient to the Message&#39;s cc list
list< string > addTO(string recipient)
add a recipient to the Message&#39;s recipient list
const EncDefault
default content transfer encoding depending on attachment type
Definition: MailMessage.qm.dox.h:114
string toString(bool include_body=False)
returns a multi-line string representing the Message