Qore MailMessage Module Reference 1.1

- Main Page
- Modules
- Namespaces
- Classes

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 - 2013 Qore Technologies, sro
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
32 /* Version History
33 * 2013-06-05 v1.1: David Nichols <david@qore.org>
34 + added the Message::serialize() method
35
36 * 2012-11-02 v1.0.4: David Nichols <david@qore.org>
37 + minor doc corrections and non-functional code changes
38
39 * 2012-11-02 v1.0.3: David Nichols <david@qore.org>
40 + requires Mime module 1.3 for the MultiPartMessage::parseBody() method
41 + fixed a bug where the part/attachment content-type was set to the content-type of the message
42 + try to get the filename of attachments from the content-type header if not set in the content-disposition header
43 + message parts that themselves have parts are now supported
44 + fixed recognizing mime messages with additional text after the version number (ex: "Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\))")
45
46 * 2012-09-17 v1.0.2: David Nichols <david@qore.org>
47 + use <string>::isPrintableAscii() to determine which mail headers need encoding
48
49 * 2012-09-17 v1.0.1: David Nichols <david@qore.org>
50 + fixed a bug encoding mail headers where mail headers requiring encoding were not encoded and those not requiring encoding were encoded with Q encoding
51
52 * 2012-06-14 v1.0: David Nichols <david@qore.org>
53 + moved from the SmtpClient module to an independent module to also support the Pop3Client class
54 */
55
80
81
86 namespace MailMessage {
90
91
95 const EncDefault = "default";
96
98 const EncNone = "none";
99
101 const EncBase64 = ContentTransEncBase64;
102
104 const EncQuotedPrintable = ContentTransEncQuotedPrintable;
105
107 const Encodings = (
108 EncDefault,
109 EncNone,
110 EncBase64,
111 EncQuotedPrintable,
112 );
114
116
153 class Message {
154
155 public:
157 private :
158 // the sender
159 string from;
160 // subject is a header field
161 string subject;
162
163 // additional headers
164 hash headers; // hash of additional headers except the ones below
165 // message statuses
166 bool importance = False;
167 bool deliveryReceipt = False;
168 bool readReceipt = False;
169
170 // names
171 list to = (); // list of names for to (header only) will be prefilled (and overwritten) with the recipients
172 list cc = (); // list of cc's
173 list bcc = (); // list of bcc's
174
175 // message data itself
176 *data body;
177
178 // message body content transfer encoding
179 string bodyEncoding = EncDefault;
180
181 // message body content type
182 *string bodyContentType;
183
184 // list of Attachments
185 list attachments = ();
186
187 // list of Parts that are not Attachments (and not the main Message body - could be alternative representations of the body, for example)
188 list parts = ();
189
190 string sender;
191
192 public:
194
195 public :
197 string mpboundary = replace(makeBase64String(string(now_us())), "=", "");
198
199 public:
200
202
209 constructor(string sender, string subject);
210
211
213
217 constructor(string msg);
218
219
221
224 string serialize();
225
226
227
228 private:
229 processPart(hash p);
230 public:
231
232
234 static *string getEmailAddress(string str);
235
237 static bool checkEmailAddress(string str);
238
240
245 list addTO(string recipient);
246
247
249
254 list addCC(string recipient);
255
256
258
263 list addBCC(string recipient);
264
265
267 *string getSender();
268
269
271 *string getFrom();
272
273
275 list getTO();
276
277
279 list getCC();
280
281
283 list getBCC();
284
285
287 string getSubject();
288
289
291 list getRecipients();
292
293
295
302 bool sendPossible();
303
304
306
313 checkSendPossible();
314
315
317
323 setBody(data body, string enc = EncDefault, *string content_type);
324
325
327
331 addBody(string str);
332
333
335
339 addBody(binary bin);
340
341
343 *data getBody();
344
345
347 string getBodyTransferEncoding();
348
349
351
358 static hash parseHeader(string hdr, bool decode = True);
359
361
367 setHeader(string hdr);
368
369
371
377 setHeader(list hdrs);
378
379
381
385 setHeader(hash hdrs);
386
387
389
393 addHeader(string hdr);
394
395
397
401 addHeader(list hdrs);
402
403
405
409 addHeader(hash hdrs);
410
411
413 softlist getHeader();
414
415
417 *hash getHeaders();
418
419
421
426 bool important();
427
428
430
435 important(softbool i);
436
437
439
442 bool receiptRead();
443
444
446
449 receiptRead(bool arg);
450
451
453
456 bool receiptDelivery();
457
458
460
463 receiptDelivery(bool arg);
464
465
467
476 attach(string name, string mime, data att, string enc = EncDefault, *hash hdr);
477
478
480
482 attach(Attachment att);
483
484
486 list getAttachments();
487
488
490
492 list getParts();
493
494
496
503 static string doHeaderValue(string hdr, string val, string eol = "\r\n", bool encode = True);
504
505
507
512 string getHeaderString(string eol = "\r\n", bool encode = True);
513
514
516
518 string toString(bool body = False);
519
520
522
524 string toLine();
525
526
528
537 static string checkEncoding(data data, string enc, bool noneok = False);
538
540
546 static string encodeTransferData(data data, string enc, reference hdr);
547
549 static string encodeData(data data, string mime, string disp, string enc);
550
552
558 static string getLine(reference msg, reference pos);
559
561
562 private:
563 list getEnvelopeList();
564 public:
565
567 };
568
570
576 class Part {
577
578 public:
579 // no public members
580 private:
581
582 public:
583
585 private :
586 string name;
587 string mime;
588 data data;
590 string enc;
591 // any extra headers for the message
592 *hash headers;
593
594 public:
595
596 // will only be called internally when parsing a Message
597 constructor(string name, string mime, data data, string enc = EncDefault, *hash hdr);
598
600
602 string getName();
603
604
606 string getMime();
607
608
610 data getData();
611
612
614 string getTransferEncoding();
615
616
618 *hash getHeaders();
619
620
622 add(MultiPartMixedMessage mpm);
623
624 };
625
627
642 class Attachment : public Part {
643
644 public:
645 // no public members
646 private:
647
648 public:
649
651
660 constructor(string name, string mime, data data, string enc = EncDefault, *hash hdr);
661
662 };
663 };