Added feature #15998: Create a new API to send mails based on SwiftMailer to replace...
[Packages/TYPO3.CMS.git] / typo3 / contrib / swiftmailer / classes / Swift / Message.php
1 <?php
2
3 /*
4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 //@require 'Swift/Mime/SimpleMessage.php';
12 //@require 'Swift/MimePart.php';
13 //@require 'Swift/DependencyContainer.php';
14
15 /**
16 * The Message class for building emails.
17 * @package Swift
18 * @subpackage Mime
19 * @author Chris Corbyn
20 */
21 class Swift_Message extends Swift_Mime_SimpleMessage
22 {
23
24 /**
25 * Create a new Message.
26 * Details may be optionally passed into the constructor.
27 * @param string $subject
28 * @param string $body
29 * @param string $contentType
30 * @param string $charset
31 */
32 public function __construct($subject = null, $body = null,
33 $contentType = null, $charset = null)
34 {
35 call_user_func_array(
36 array($this, 'Swift_Mime_SimpleMessage::__construct'),
37 Swift_DependencyContainer::getInstance()
38 ->createDependenciesFor('mime.message')
39 );
40
41 if (!isset($charset))
42 {
43 $charset = Swift_DependencyContainer::getInstance()
44 ->lookup('properties.charset');
45 }
46 $this->setSubject($subject);
47 $this->setBody($body);
48 $this->setCharset($charset);
49 if ($contentType)
50 {
51 $this->setContentType($contentType);
52 }
53 }
54
55 /**
56 * Create a new Message.
57 * @param string $subject
58 * @param string $body
59 * @param string $contentType
60 * @param string $charset
61 * @return Swift_Mime_Message
62 */
63 public static function newInstance($subject = null, $body = null,
64 $contentType = null, $charset = null)
65 {
66 return new self($subject, $body, $contentType, $charset);
67 }
68
69 /**
70 * Add a MimePart to this Message.
71 * @param string|Swift_OutputByteStream $body
72 * @param string $contentType
73 * @param string $charset
74 */
75 public function addPart($body, $contentType = null, $charset = null)
76 {
77 return $this->attach(Swift_MimePart::newInstance(
78 $body, $contentType, $charset
79 ));
80 }
81
82 }