Qore MailMessage Module Reference  1.0.4
 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 Wolfgang Ritzinger, Marian Bonda, Pavol Potoncok
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 qore version
26 
27 // need mime definitions
28 
29 
30 /* Version History
31  * 2012-11-02 v1.0.4: David Nichols <david@qore.org>
32  + minor doc corrections and non-functional code changes
33 
34  * 2012-11-02 v1.0.3: David Nichols <david@qore.org>
35  + requires Mime module 1.3 for the MultiPartMessage::parseBody() method
36  + fixed a bug where the part/attachment content-type was set to the content-type of the message
37  + try to get the filename of attachments from the content-type header if not set in the content-disposition header
38  + message parts that themselves have parts are now supported
39  + fixed recognizing mime messages with additional text after the version number (ex: "Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\))")
40 
41  * 2012-09-17 v1.0.2: David Nichols <david@qore.org>
42  + use <string>::isPrintableAscii() to determine which mail headers need encoding
43 
44  * 2012-09-17 v1.0.1: David Nichols <david@qore.org>
45  + fixed a bug encoding mail headers where mail headers requiring encoding were not encoded and those not requiring encoding were encoded with Q encoding
46 
47  * 2012-06-14 v1.0: David Nichols <david@qore.org>
48  + moved from the SmtpClient module to an independent module to also support the Pop3Client class
49 */
50 
75 
76 
81 namespace MailMessage {
85 
86 
90  const EncDefault = "default";
91 
93  const EncNone = "none";
94 
97 
100 
102  const Encodings = (
103  EncDefault,
104  EncNone,
105  EncBase64,
107  );
109 
111 
148  class Message {
149 
150 public:
152  private :
153  // the sender
154  string from;
155  // subject is a header field
156  string subject;
157 
158  // additional headers
159  hash headers; // hash of additional headers except the ones below
160  // message statuses
161  bool importance = False;
162  bool deliveryReceipt = False;
163  bool readReceipt = False;
164 
165  // names
166  list to = (); // list of names for to (header only) will be prefilled (and overwritten) with the recipients
167  list cc = (); // list of cc's
168  list bcc = (); // list of bcc's
169 
170  // message data itself
171  *data body;
172 
173  // message body content transfer encoding
174  string bodyEncoding = EncDefault;
175 
176  // list of Attachments
177  list attachments = ();
178 
179  // list of Parts that are not Attachments (and not the main Message body - could be alternative representations of the body, for example)
180  list parts = ();
181 
182  string sender;
183 
184 public:
186 
187 private:
188 
189 public:
190 
192 
199  constructor(string sender, string subject);
200 
201 
203 
207  constructor(string msg);
208 
209 
210 
211 private:
212  processPart(hash p);
213 public:
214 
215 
217  static *string getEmailAddress(string str);
218 
220  static bool checkEmailAddress(string str);
221 
223 
228  list addTO(string recipient);
229 
230 
232 
237  list addCC(string recipient);
238 
239 
241 
246  list addBCC(string recipient);
247 
248 
250  *string getSender();
251 
252 
254  *string getFrom();
255 
256 
258  list getTO();
259 
260 
262  list getCC();
263 
264 
266  list getBCC();
267 
268 
270  string getSubject();
271 
272 
275 
276 
278 
285  bool sendPossible();
286 
287 
289 
297 
298 
300 
305  setBody(data body, string enc = EncDefault);
306 
307 
309 
313  addBody(string str);
314 
315 
317 
321  addBody(binary bin);
322 
323 
325  *data getBody();
326 
327 
329  string getBodyTransferEncoding();
330 
331 
333 
340  static hash parseHeader(string hdr, bool decode = True);
341 
343 
349  setHeader(string hdr);
350 
351 
353 
359  setHeader(list hdrs);
360 
361 
363 
367  setHeader(hash hdrs);
368 
369 
371 
375  addHeader(string hdr);
376 
377 
379 
383  addHeader(list hdrs);
384 
385 
387 
391  addHeader(hash hdrs);
392 
393 
395  softlist getHeader();
396 
397 
399  *hash getHeaders();
400 
401 
403 
408  bool important();
409 
410 
412 
417  important(softbool i);
418 
419 
421 
424  bool receiptRead();
425 
426 
428 
431  receiptRead(bool arg);
432 
433 
435 
438  bool receiptDelivery();
439 
440 
442 
445  receiptDelivery(bool arg);
446 
447 
449 
458  attach(string name, string mime, data att, string enc = EncDefault, *hash hdr);
459 
460 
462 
464  attach(Attachment att);
465 
466 
469 
470 
472 
474  list getParts();
475 
476 
478 
485  static string doHeaderValue(string hdr, string val, string eol = "\r\n", bool encode = True);
486 
487 
489 
494  string getHeaderString(string eol = "\r\n", bool encode = True);
495 
496 
498 
500  string toString(bool body = False);
501 
502 
504 
506  string toLine();
507 
508 
510 
519  static string checkEncoding(data data, string enc, bool noneok = False);
520 
522 
528  static string encodeTransferData(data data, string enc, reference hdr);
529 
531  static string encodeData(data data, string mime, string disp, string enc);
532 
534 
540  static string getLine(reference msg, reference pos);
541 
543 
544 private:
545  list getEnvelopeList();
546 public:
547 
549  };
550 
552 
558  class Part {
559 
560 public:
561  // no public members
562 private:
563 
564 public:
565 
567  private :
568  string name;
569  string mime;
570  data data;
572  string enc;
573  // any extra headers for the message
574  *hash headers;
575 
576 public:
577 
578  // will only be called internally when parsing a Message
579  constructor(string name, string mime, data data, string enc = EncDefault, *hash hdr);
580 
582 
584  string getName();
585 
586 
588  string getMime();
589 
590 
592  data getData();
593 
594 
596  string getTransferEncoding();
597 
598 
600  *hash getHeaders();
601 
602 
604  add(MultiPartMixedMessage mpm);
605 
606  };
607 
609 
624 class Attachment : public Part {
625 
626 public:
627  // no public members
628 private:
629 
630 public:
631 
633 
642  constructor(string name, string mime, data data, string enc = EncDefault, *hash hdr);
643 
644  };
645 };