@@ -19,146 +19,146 @@ |
||
19 | 19 | */ |
20 | 20 | class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_ContentEncoder |
21 | 21 | { |
22 | - /** |
|
23 | - * The name of this encoding scheme (probably 7bit or 8bit). |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private $name; |
|
28 | - |
|
29 | - /** |
|
30 | - * True if canonical transformations should be done. |
|
31 | - * |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $canonical; |
|
35 | - |
|
36 | - /** |
|
37 | - * Creates a new PlainContentEncoder with $name (probably 7bit or 8bit). |
|
38 | - * |
|
39 | - * @param string $name |
|
40 | - * @param bool $canonical if canonicalization transformation should be done |
|
41 | - */ |
|
42 | - public function __construct($name, $canonical = false) |
|
43 | - { |
|
44 | - $this->name = $name; |
|
45 | - $this->canonical = $canonical; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Encode a given string to produce an encoded string. |
|
50 | - * |
|
51 | - * @param string $string |
|
52 | - * @param int $firstLineOffset ignored |
|
53 | - * @param int $maxLineLength - 0 means no wrapping will occur |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
58 | - { |
|
59 | - if ($this->canonical) { |
|
60 | - $string = $this->canonicalize($string); |
|
61 | - } |
|
62 | - |
|
63 | - return $this->safeWordwrap($string, $maxLineLength, "\r\n"); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Encode stream $in to stream $out. |
|
68 | - * |
|
69 | - * @param int $firstLineOffset ignored |
|
70 | - * @param int $maxLineLength optional, 0 means no wrapping will occur |
|
71 | - */ |
|
72 | - public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
73 | - { |
|
74 | - $leftOver = ''; |
|
75 | - while (false !== $bytes = $os->read(8192)) { |
|
76 | - $toencode = $leftOver.$bytes; |
|
77 | - if ($this->canonical) { |
|
78 | - $toencode = $this->canonicalize($toencode); |
|
79 | - } |
|
80 | - $wrapped = $this->safeWordwrap($toencode, $maxLineLength, "\r\n"); |
|
81 | - $lastLinePos = strrpos($wrapped, "\r\n"); |
|
82 | - $leftOver = substr($wrapped, $lastLinePos); |
|
83 | - $wrapped = substr($wrapped, 0, $lastLinePos); |
|
84 | - |
|
85 | - $is->write($wrapped); |
|
86 | - } |
|
87 | - if (\strlen($leftOver)) { |
|
88 | - $is->write($leftOver); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Get the name of this encoding scheme. |
|
94 | - * |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getName() |
|
98 | - { |
|
99 | - return $this->name; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Not used. |
|
104 | - */ |
|
105 | - public function charsetChanged($charset) |
|
106 | - { |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * A safer (but weaker) wordwrap for unicode. |
|
111 | - * |
|
112 | - * @param string $string |
|
113 | - * @param int $length |
|
114 | - * @param string $le |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function safeWordwrap($string, $length = 75, $le = "\r\n") |
|
119 | - { |
|
120 | - if (0 >= $length) { |
|
121 | - return $string; |
|
122 | - } |
|
123 | - |
|
124 | - $originalLines = explode($le, $string); |
|
125 | - |
|
126 | - $lines = []; |
|
127 | - $lineCount = 0; |
|
128 | - |
|
129 | - foreach ($originalLines as $originalLine) { |
|
130 | - $lines[] = ''; |
|
131 | - $currentLine = &$lines[$lineCount++]; |
|
132 | - |
|
133 | - //$chunks = preg_split('/(?<=[\ \t,\.!\?\-&\+\/])/', $originalLine); |
|
134 | - $chunks = preg_split('/(?<=\s)/', $originalLine); |
|
135 | - |
|
136 | - foreach ($chunks as $chunk) { |
|
137 | - if (0 != \strlen($currentLine) |
|
138 | - && \strlen($currentLine.$chunk) > $length) { |
|
139 | - $lines[] = ''; |
|
140 | - $currentLine = &$lines[$lineCount++]; |
|
141 | - } |
|
142 | - $currentLine .= $chunk; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return implode("\r\n", $lines); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Canonicalize string input (fix CRLF). |
|
151 | - * |
|
152 | - * @param string $string |
|
153 | - * |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - private function canonicalize($string) |
|
157 | - { |
|
158 | - return str_replace( |
|
159 | - ["\r\n", "\r", "\n"], |
|
160 | - ["\n", "\n", "\r\n"], |
|
161 | - $string |
|
162 | - ); |
|
163 | - } |
|
22 | + /** |
|
23 | + * The name of this encoding scheme (probably 7bit or 8bit). |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private $name; |
|
28 | + |
|
29 | + /** |
|
30 | + * True if canonical transformations should be done. |
|
31 | + * |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $canonical; |
|
35 | + |
|
36 | + /** |
|
37 | + * Creates a new PlainContentEncoder with $name (probably 7bit or 8bit). |
|
38 | + * |
|
39 | + * @param string $name |
|
40 | + * @param bool $canonical if canonicalization transformation should be done |
|
41 | + */ |
|
42 | + public function __construct($name, $canonical = false) |
|
43 | + { |
|
44 | + $this->name = $name; |
|
45 | + $this->canonical = $canonical; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Encode a given string to produce an encoded string. |
|
50 | + * |
|
51 | + * @param string $string |
|
52 | + * @param int $firstLineOffset ignored |
|
53 | + * @param int $maxLineLength - 0 means no wrapping will occur |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
58 | + { |
|
59 | + if ($this->canonical) { |
|
60 | + $string = $this->canonicalize($string); |
|
61 | + } |
|
62 | + |
|
63 | + return $this->safeWordwrap($string, $maxLineLength, "\r\n"); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Encode stream $in to stream $out. |
|
68 | + * |
|
69 | + * @param int $firstLineOffset ignored |
|
70 | + * @param int $maxLineLength optional, 0 means no wrapping will occur |
|
71 | + */ |
|
72 | + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
73 | + { |
|
74 | + $leftOver = ''; |
|
75 | + while (false !== $bytes = $os->read(8192)) { |
|
76 | + $toencode = $leftOver.$bytes; |
|
77 | + if ($this->canonical) { |
|
78 | + $toencode = $this->canonicalize($toencode); |
|
79 | + } |
|
80 | + $wrapped = $this->safeWordwrap($toencode, $maxLineLength, "\r\n"); |
|
81 | + $lastLinePos = strrpos($wrapped, "\r\n"); |
|
82 | + $leftOver = substr($wrapped, $lastLinePos); |
|
83 | + $wrapped = substr($wrapped, 0, $lastLinePos); |
|
84 | + |
|
85 | + $is->write($wrapped); |
|
86 | + } |
|
87 | + if (\strlen($leftOver)) { |
|
88 | + $is->write($leftOver); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Get the name of this encoding scheme. |
|
94 | + * |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getName() |
|
98 | + { |
|
99 | + return $this->name; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Not used. |
|
104 | + */ |
|
105 | + public function charsetChanged($charset) |
|
106 | + { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * A safer (but weaker) wordwrap for unicode. |
|
111 | + * |
|
112 | + * @param string $string |
|
113 | + * @param int $length |
|
114 | + * @param string $le |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function safeWordwrap($string, $length = 75, $le = "\r\n") |
|
119 | + { |
|
120 | + if (0 >= $length) { |
|
121 | + return $string; |
|
122 | + } |
|
123 | + |
|
124 | + $originalLines = explode($le, $string); |
|
125 | + |
|
126 | + $lines = []; |
|
127 | + $lineCount = 0; |
|
128 | + |
|
129 | + foreach ($originalLines as $originalLine) { |
|
130 | + $lines[] = ''; |
|
131 | + $currentLine = &$lines[$lineCount++]; |
|
132 | + |
|
133 | + //$chunks = preg_split('/(?<=[\ \t,\.!\?\-&\+\/])/', $originalLine); |
|
134 | + $chunks = preg_split('/(?<=\s)/', $originalLine); |
|
135 | + |
|
136 | + foreach ($chunks as $chunk) { |
|
137 | + if (0 != \strlen($currentLine) |
|
138 | + && \strlen($currentLine.$chunk) > $length) { |
|
139 | + $lines[] = ''; |
|
140 | + $currentLine = &$lines[$lineCount++]; |
|
141 | + } |
|
142 | + $currentLine .= $chunk; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return implode("\r\n", $lines); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Canonicalize string input (fix CRLF). |
|
151 | + * |
|
152 | + * @param string $string |
|
153 | + * |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + private function canonicalize($string) |
|
157 | + { |
|
158 | + return str_replace( |
|
159 | + ["\r\n", "\r", "\n"], |
|
160 | + ["\n", "\n", "\r\n"], |
|
161 | + $string |
|
162 | + ); |
|
163 | + } |
|
164 | 164 | } |
@@ -15,120 +15,120 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_ContentEncoder |
17 | 17 | { |
18 | - protected $dotEscape; |
|
19 | - |
|
20 | - /** |
|
21 | - * Creates a new QpContentEncoder for the given CharacterStream. |
|
22 | - * |
|
23 | - * @param Swift_CharacterStream $charStream to use for reading characters |
|
24 | - * @param Swift_StreamFilter $filter if canonicalization should occur |
|
25 | - * @param bool $dotEscape if dot stuffing workaround must be enabled |
|
26 | - */ |
|
27 | - public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null, $dotEscape = false) |
|
28 | - { |
|
29 | - $this->dotEscape = $dotEscape; |
|
30 | - parent::__construct($charStream, $filter); |
|
31 | - } |
|
32 | - |
|
33 | - public function __sleep() |
|
34 | - { |
|
35 | - return ['charStream', 'filter', 'dotEscape']; |
|
36 | - } |
|
37 | - |
|
38 | - protected function getSafeMapShareId() |
|
39 | - { |
|
40 | - return static::class.($this->dotEscape ? '.dotEscape' : ''); |
|
41 | - } |
|
42 | - |
|
43 | - protected function initSafeMap() |
|
44 | - { |
|
45 | - parent::initSafeMap(); |
|
46 | - if ($this->dotEscape) { |
|
47 | - /* Encode . as =2e for buggy remote servers */ |
|
48 | - unset($this->safeMap[0x2e]); |
|
49 | - } |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Encode stream $in to stream $out. |
|
54 | - * |
|
55 | - * QP encoded strings have a maximum line length of 76 characters. |
|
56 | - * If the first line needs to be shorter, indicate the difference with |
|
57 | - * $firstLineOffset. |
|
58 | - * |
|
59 | - * @param Swift_OutputByteStream $os output stream |
|
60 | - * @param Swift_InputByteStream $is input stream |
|
61 | - * @param int $firstLineOffset |
|
62 | - * @param int $maxLineLength |
|
63 | - */ |
|
64 | - public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
65 | - { |
|
66 | - if ($maxLineLength > 76 || $maxLineLength <= 0) { |
|
67 | - $maxLineLength = 76; |
|
68 | - } |
|
69 | - |
|
70 | - $thisLineLength = $maxLineLength - $firstLineOffset; |
|
71 | - |
|
72 | - $this->charStream->flushContents(); |
|
73 | - $this->charStream->importByteStream($os); |
|
74 | - |
|
75 | - $currentLine = ''; |
|
76 | - $prepend = ''; |
|
77 | - $size = $lineLen = 0; |
|
78 | - |
|
79 | - while (false !== $bytes = $this->nextSequence()) { |
|
80 | - // If we're filtering the input |
|
81 | - if (isset($this->filter)) { |
|
82 | - // If we can't filter because we need more bytes |
|
83 | - while ($this->filter->shouldBuffer($bytes)) { |
|
84 | - // Then collect bytes into the buffer |
|
85 | - if (false === $moreBytes = $this->nextSequence(1)) { |
|
86 | - break; |
|
87 | - } |
|
88 | - |
|
89 | - foreach ($moreBytes as $b) { |
|
90 | - $bytes[] = $b; |
|
91 | - } |
|
92 | - } |
|
93 | - // And filter them |
|
94 | - $bytes = $this->filter->filter($bytes); |
|
95 | - } |
|
96 | - |
|
97 | - $enc = $this->encodeByteSequence($bytes, $size); |
|
98 | - |
|
99 | - $i = strpos($enc, '=0D=0A'); |
|
100 | - $newLineLength = $lineLen + (false === $i ? $size : $i); |
|
101 | - |
|
102 | - if ($currentLine && $newLineLength >= $thisLineLength) { |
|
103 | - $is->write($prepend.$this->standardize($currentLine)); |
|
104 | - $currentLine = ''; |
|
105 | - $prepend = "=\r\n"; |
|
106 | - $thisLineLength = $maxLineLength; |
|
107 | - $lineLen = 0; |
|
108 | - } |
|
109 | - |
|
110 | - $currentLine .= $enc; |
|
111 | - |
|
112 | - if (false === $i) { |
|
113 | - $lineLen += $size; |
|
114 | - } else { |
|
115 | - // 6 is the length of '=0D=0A'. |
|
116 | - $lineLen = $size - strrpos($enc, '=0D=0A') - 6; |
|
117 | - } |
|
118 | - } |
|
119 | - if (\strlen($currentLine)) { |
|
120 | - $is->write($prepend.$this->standardize($currentLine)); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get the name of this encoding scheme. |
|
126 | - * Returns the string 'quoted-printable'. |
|
127 | - * |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function getName() |
|
131 | - { |
|
132 | - return 'quoted-printable'; |
|
133 | - } |
|
18 | + protected $dotEscape; |
|
19 | + |
|
20 | + /** |
|
21 | + * Creates a new QpContentEncoder for the given CharacterStream. |
|
22 | + * |
|
23 | + * @param Swift_CharacterStream $charStream to use for reading characters |
|
24 | + * @param Swift_StreamFilter $filter if canonicalization should occur |
|
25 | + * @param bool $dotEscape if dot stuffing workaround must be enabled |
|
26 | + */ |
|
27 | + public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null, $dotEscape = false) |
|
28 | + { |
|
29 | + $this->dotEscape = $dotEscape; |
|
30 | + parent::__construct($charStream, $filter); |
|
31 | + } |
|
32 | + |
|
33 | + public function __sleep() |
|
34 | + { |
|
35 | + return ['charStream', 'filter', 'dotEscape']; |
|
36 | + } |
|
37 | + |
|
38 | + protected function getSafeMapShareId() |
|
39 | + { |
|
40 | + return static::class.($this->dotEscape ? '.dotEscape' : ''); |
|
41 | + } |
|
42 | + |
|
43 | + protected function initSafeMap() |
|
44 | + { |
|
45 | + parent::initSafeMap(); |
|
46 | + if ($this->dotEscape) { |
|
47 | + /* Encode . as =2e for buggy remote servers */ |
|
48 | + unset($this->safeMap[0x2e]); |
|
49 | + } |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Encode stream $in to stream $out. |
|
54 | + * |
|
55 | + * QP encoded strings have a maximum line length of 76 characters. |
|
56 | + * If the first line needs to be shorter, indicate the difference with |
|
57 | + * $firstLineOffset. |
|
58 | + * |
|
59 | + * @param Swift_OutputByteStream $os output stream |
|
60 | + * @param Swift_InputByteStream $is input stream |
|
61 | + * @param int $firstLineOffset |
|
62 | + * @param int $maxLineLength |
|
63 | + */ |
|
64 | + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
65 | + { |
|
66 | + if ($maxLineLength > 76 || $maxLineLength <= 0) { |
|
67 | + $maxLineLength = 76; |
|
68 | + } |
|
69 | + |
|
70 | + $thisLineLength = $maxLineLength - $firstLineOffset; |
|
71 | + |
|
72 | + $this->charStream->flushContents(); |
|
73 | + $this->charStream->importByteStream($os); |
|
74 | + |
|
75 | + $currentLine = ''; |
|
76 | + $prepend = ''; |
|
77 | + $size = $lineLen = 0; |
|
78 | + |
|
79 | + while (false !== $bytes = $this->nextSequence()) { |
|
80 | + // If we're filtering the input |
|
81 | + if (isset($this->filter)) { |
|
82 | + // If we can't filter because we need more bytes |
|
83 | + while ($this->filter->shouldBuffer($bytes)) { |
|
84 | + // Then collect bytes into the buffer |
|
85 | + if (false === $moreBytes = $this->nextSequence(1)) { |
|
86 | + break; |
|
87 | + } |
|
88 | + |
|
89 | + foreach ($moreBytes as $b) { |
|
90 | + $bytes[] = $b; |
|
91 | + } |
|
92 | + } |
|
93 | + // And filter them |
|
94 | + $bytes = $this->filter->filter($bytes); |
|
95 | + } |
|
96 | + |
|
97 | + $enc = $this->encodeByteSequence($bytes, $size); |
|
98 | + |
|
99 | + $i = strpos($enc, '=0D=0A'); |
|
100 | + $newLineLength = $lineLen + (false === $i ? $size : $i); |
|
101 | + |
|
102 | + if ($currentLine && $newLineLength >= $thisLineLength) { |
|
103 | + $is->write($prepend.$this->standardize($currentLine)); |
|
104 | + $currentLine = ''; |
|
105 | + $prepend = "=\r\n"; |
|
106 | + $thisLineLength = $maxLineLength; |
|
107 | + $lineLen = 0; |
|
108 | + } |
|
109 | + |
|
110 | + $currentLine .= $enc; |
|
111 | + |
|
112 | + if (false === $i) { |
|
113 | + $lineLen += $size; |
|
114 | + } else { |
|
115 | + // 6 is the length of '=0D=0A'. |
|
116 | + $lineLen = $size - strrpos($enc, '=0D=0A') - 6; |
|
117 | + } |
|
118 | + } |
|
119 | + if (\strlen($currentLine)) { |
|
120 | + $is->write($prepend.$this->standardize($currentLine)); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get the name of this encoding scheme. |
|
126 | + * Returns the string 'quoted-printable'. |
|
127 | + * |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function getName() |
|
131 | + { |
|
132 | + return 'quoted-printable'; |
|
133 | + } |
|
134 | 134 | } |
@@ -16,64 +16,64 @@ |
||
16 | 16 | */ |
17 | 17 | class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_ContentEncoder |
18 | 18 | { |
19 | - /** |
|
20 | - * The name of this encoding scheme (probably 7bit or 8bit). |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - private $name; |
|
19 | + /** |
|
20 | + * The name of this encoding scheme (probably 7bit or 8bit). |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + private $name; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Creates a new NullContentEncoder with $name (probably 7bit or 8bit). |
|
28 | - * |
|
29 | - * @param string $name |
|
30 | - */ |
|
31 | - public function __construct($name) |
|
32 | - { |
|
33 | - $this->name = $name; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Creates a new NullContentEncoder with $name (probably 7bit or 8bit). |
|
28 | + * |
|
29 | + * @param string $name |
|
30 | + */ |
|
31 | + public function __construct($name) |
|
32 | + { |
|
33 | + $this->name = $name; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Encode a given string to produce an encoded string. |
|
38 | - * |
|
39 | - * @param string $string |
|
40 | - * @param int $firstLineOffset ignored |
|
41 | - * @param int $maxLineLength ignored |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
46 | - { |
|
47 | - return $string; |
|
48 | - } |
|
36 | + /** |
|
37 | + * Encode a given string to produce an encoded string. |
|
38 | + * |
|
39 | + * @param string $string |
|
40 | + * @param int $firstLineOffset ignored |
|
41 | + * @param int $maxLineLength ignored |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
46 | + { |
|
47 | + return $string; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Encode stream $in to stream $out. |
|
52 | - * |
|
53 | - * @param int $firstLineOffset ignored |
|
54 | - * @param int $maxLineLength ignored |
|
55 | - */ |
|
56 | - public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
57 | - { |
|
58 | - while (false !== ($bytes = $os->read(8192))) { |
|
59 | - $is->write($bytes); |
|
60 | - } |
|
61 | - } |
|
50 | + /** |
|
51 | + * Encode stream $in to stream $out. |
|
52 | + * |
|
53 | + * @param int $firstLineOffset ignored |
|
54 | + * @param int $maxLineLength ignored |
|
55 | + */ |
|
56 | + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
57 | + { |
|
58 | + while (false !== ($bytes = $os->read(8192))) { |
|
59 | + $is->write($bytes); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Get the name of this encoding scheme. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getName() |
|
69 | - { |
|
70 | - return $this->name; |
|
71 | - } |
|
63 | + /** |
|
64 | + * Get the name of this encoding scheme. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getName() |
|
69 | + { |
|
70 | + return $this->name; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Not used. |
|
75 | - */ |
|
76 | - public function charsetChanged($charset) |
|
77 | - { |
|
78 | - } |
|
73 | + /** |
|
74 | + * Not used. |
|
75 | + */ |
|
76 | + public function charsetChanged($charset) |
|
77 | + { |
|
78 | + } |
|
79 | 79 | } |
@@ -15,107 +15,107 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string|null |
|
20 | - */ |
|
21 | - private $charset; |
|
18 | + /** |
|
19 | + * @var string|null |
|
20 | + */ |
|
21 | + private $charset; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string|null $charset |
|
25 | - */ |
|
26 | - public function __construct($charset = null) |
|
27 | - { |
|
28 | - $this->charset = $charset ?: 'utf-8'; |
|
29 | - } |
|
23 | + /** |
|
24 | + * @param string|null $charset |
|
25 | + */ |
|
26 | + public function __construct($charset = null) |
|
27 | + { |
|
28 | + $this->charset = $charset ?: 'utf-8'; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Notify this observer that the entity's charset has changed. |
|
33 | - * |
|
34 | - * @param string $charset |
|
35 | - */ |
|
36 | - public function charsetChanged($charset) |
|
37 | - { |
|
38 | - $this->charset = $charset; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Notify this observer that the entity's charset has changed. |
|
33 | + * |
|
34 | + * @param string $charset |
|
35 | + */ |
|
36 | + public function charsetChanged($charset) |
|
37 | + { |
|
38 | + $this->charset = $charset; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Encode $in to $out. |
|
43 | - * |
|
44 | - * @param Swift_OutputByteStream $os to read from |
|
45 | - * @param Swift_InputByteStream $is to write to |
|
46 | - * @param int $firstLineOffset |
|
47 | - * @param int $maxLineLength 0 indicates the default length for this encoding |
|
48 | - * |
|
49 | - * @throws RuntimeException |
|
50 | - */ |
|
51 | - public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
52 | - { |
|
53 | - if ('utf-8' !== $this->charset) { |
|
54 | - throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); |
|
55 | - } |
|
41 | + /** |
|
42 | + * Encode $in to $out. |
|
43 | + * |
|
44 | + * @param Swift_OutputByteStream $os to read from |
|
45 | + * @param Swift_InputByteStream $is to write to |
|
46 | + * @param int $firstLineOffset |
|
47 | + * @param int $maxLineLength 0 indicates the default length for this encoding |
|
48 | + * |
|
49 | + * @throws RuntimeException |
|
50 | + */ |
|
51 | + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
52 | + { |
|
53 | + if ('utf-8' !== $this->charset) { |
|
54 | + throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); |
|
55 | + } |
|
56 | 56 | |
57 | - $string = ''; |
|
57 | + $string = ''; |
|
58 | 58 | |
59 | - while (false !== $bytes = $os->read(8192)) { |
|
60 | - $string .= $bytes; |
|
61 | - } |
|
59 | + while (false !== $bytes = $os->read(8192)) { |
|
60 | + $string .= $bytes; |
|
61 | + } |
|
62 | 62 | |
63 | - $is->write($this->encodeString($string)); |
|
64 | - } |
|
63 | + $is->write($this->encodeString($string)); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get the MIME name of this content encoding scheme. |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getName() |
|
72 | - { |
|
73 | - return 'quoted-printable'; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Get the MIME name of this content encoding scheme. |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getName() |
|
72 | + { |
|
73 | + return 'quoted-printable'; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Encode a given string to produce an encoded string. |
|
78 | - * |
|
79 | - * @param string $string |
|
80 | - * @param int $firstLineOffset if first line needs to be shorter |
|
81 | - * @param int $maxLineLength 0 indicates the default length for this encoding |
|
82 | - * |
|
83 | - * @throws RuntimeException |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
88 | - { |
|
89 | - if ('utf-8' !== $this->charset) { |
|
90 | - throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); |
|
91 | - } |
|
76 | + /** |
|
77 | + * Encode a given string to produce an encoded string. |
|
78 | + * |
|
79 | + * @param string $string |
|
80 | + * @param int $firstLineOffset if first line needs to be shorter |
|
81 | + * @param int $maxLineLength 0 indicates the default length for this encoding |
|
82 | + * |
|
83 | + * @throws RuntimeException |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
88 | + { |
|
89 | + if ('utf-8' !== $this->charset) { |
|
90 | + throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); |
|
91 | + } |
|
92 | 92 | |
93 | - return $this->standardize(quoted_printable_encode($string)); |
|
94 | - } |
|
93 | + return $this->standardize(quoted_printable_encode($string)); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Make sure CRLF is correct and HT/SPACE are in valid places. |
|
98 | - * |
|
99 | - * @param string $string |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - protected function standardize($string) |
|
104 | - { |
|
105 | - // transform CR or LF to CRLF |
|
106 | - $string = preg_replace('~=0D(?!=0A)|(?<!=0D)=0A~', '=0D=0A', $string); |
|
107 | - // transform =0D=0A to CRLF |
|
108 | - $string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'], ["=09\r\n", "=20\r\n", "\r\n"], $string); |
|
96 | + /** |
|
97 | + * Make sure CRLF is correct and HT/SPACE are in valid places. |
|
98 | + * |
|
99 | + * @param string $string |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + protected function standardize($string) |
|
104 | + { |
|
105 | + // transform CR or LF to CRLF |
|
106 | + $string = preg_replace('~=0D(?!=0A)|(?<!=0D)=0A~', '=0D=0A', $string); |
|
107 | + // transform =0D=0A to CRLF |
|
108 | + $string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'], ["=09\r\n", "=20\r\n", "\r\n"], $string); |
|
109 | 109 | |
110 | - switch (\ord(substr($string, -1))) { |
|
111 | - case 0x09: |
|
112 | - $string = substr_replace($string, '=09', -1); |
|
113 | - break; |
|
114 | - case 0x20: |
|
115 | - $string = substr_replace($string, '=20', -1); |
|
116 | - break; |
|
117 | - } |
|
110 | + switch (\ord(substr($string, -1))) { |
|
111 | + case 0x09: |
|
112 | + $string = substr_replace($string, '=09', -1); |
|
113 | + break; |
|
114 | + case 0x20: |
|
115 | + $string = substr_replace($string, '=20', -1); |
|
116 | + break; |
|
117 | + } |
|
118 | 118 | |
119 | - return $string; |
|
120 | - } |
|
119 | + return $string; |
|
120 | + } |
|
121 | 121 | } |
@@ -17,80 +17,80 @@ |
||
17 | 17 | */ |
18 | 18 | class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_ContentEncoder |
19 | 19 | { |
20 | - /** |
|
21 | - * @var Swift_Mime_ContentEncoder_QpContentEncoder |
|
22 | - */ |
|
23 | - private $safeEncoder; |
|
20 | + /** |
|
21 | + * @var Swift_Mime_ContentEncoder_QpContentEncoder |
|
22 | + */ |
|
23 | + private $safeEncoder; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var Swift_Mime_ContentEncoder_NativeQpContentEncoder |
|
27 | - */ |
|
28 | - private $nativeEncoder; |
|
25 | + /** |
|
26 | + * @var Swift_Mime_ContentEncoder_NativeQpContentEncoder |
|
27 | + */ |
|
28 | + private $nativeEncoder; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string|null |
|
32 | - */ |
|
33 | - private $charset; |
|
30 | + /** |
|
31 | + * @var string|null |
|
32 | + */ |
|
33 | + private $charset; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor. |
|
37 | - * |
|
38 | - * @param string|null $charset |
|
39 | - */ |
|
40 | - public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset) |
|
41 | - { |
|
42 | - $this->safeEncoder = $safeEncoder; |
|
43 | - $this->nativeEncoder = $nativeEncoder; |
|
44 | - $this->charset = $charset; |
|
45 | - } |
|
35 | + /** |
|
36 | + * Constructor. |
|
37 | + * |
|
38 | + * @param string|null $charset |
|
39 | + */ |
|
40 | + public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset) |
|
41 | + { |
|
42 | + $this->safeEncoder = $safeEncoder; |
|
43 | + $this->nativeEncoder = $nativeEncoder; |
|
44 | + $this->charset = $charset; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Make a deep copy of object. |
|
49 | - */ |
|
50 | - public function __clone() |
|
51 | - { |
|
52 | - $this->safeEncoder = clone $this->safeEncoder; |
|
53 | - $this->nativeEncoder = clone $this->nativeEncoder; |
|
54 | - } |
|
47 | + /** |
|
48 | + * Make a deep copy of object. |
|
49 | + */ |
|
50 | + public function __clone() |
|
51 | + { |
|
52 | + $this->safeEncoder = clone $this->safeEncoder; |
|
53 | + $this->nativeEncoder = clone $this->nativeEncoder; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function charsetChanged($charset) |
|
60 | - { |
|
61 | - $this->charset = $charset; |
|
62 | - $this->safeEncoder->charsetChanged($charset); |
|
63 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function charsetChanged($charset) |
|
60 | + { |
|
61 | + $this->charset = $charset; |
|
62 | + $this->safeEncoder->charsetChanged($charset); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
69 | - { |
|
70 | - $this->getEncoder()->encodeByteStream($os, $is, $firstLineOffset, $maxLineLength); |
|
71 | - } |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) |
|
69 | + { |
|
70 | + $this->getEncoder()->encodeByteStream($os, $is, $firstLineOffset, $maxLineLength); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function getName() |
|
77 | - { |
|
78 | - return 'quoted-printable'; |
|
79 | - } |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function getName() |
|
77 | + { |
|
78 | + return 'quoted-printable'; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
85 | - { |
|
86 | - return $this->getEncoder()->encodeString($string, $firstLineOffset, $maxLineLength); |
|
87 | - } |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) |
|
85 | + { |
|
86 | + return $this->getEncoder()->encodeString($string, $firstLineOffset, $maxLineLength); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return Swift_Mime_ContentEncoder |
|
91 | - */ |
|
92 | - private function getEncoder() |
|
93 | - { |
|
94 | - return 'utf-8' === $this->charset ? $this->nativeEncoder : $this->safeEncoder; |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return Swift_Mime_ContentEncoder |
|
91 | + */ |
|
92 | + private function getEncoder() |
|
93 | + { |
|
94 | + return 'utf-8' === $this->charset ? $this->nativeEncoder : $this->safeEncoder; |
|
95 | + } |
|
96 | 96 | } |
@@ -15,27 +15,27 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment |
17 | 17 | { |
18 | - /** |
|
19 | - * Creates a new Attachment with $headers and $encoder. |
|
20 | - * |
|
21 | - * @param array $mimeTypes optional |
|
22 | - */ |
|
23 | - public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = []) |
|
24 | - { |
|
25 | - parent::__construct($headers, $encoder, $cache, $idGenerator, $mimeTypes); |
|
26 | - $this->setDisposition('inline'); |
|
27 | - $this->setId($this->getId()); |
|
28 | - } |
|
18 | + /** |
|
19 | + * Creates a new Attachment with $headers and $encoder. |
|
20 | + * |
|
21 | + * @param array $mimeTypes optional |
|
22 | + */ |
|
23 | + public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = []) |
|
24 | + { |
|
25 | + parent::__construct($headers, $encoder, $cache, $idGenerator, $mimeTypes); |
|
26 | + $this->setDisposition('inline'); |
|
27 | + $this->setId($this->getId()); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Get the nesting level of this EmbeddedFile. |
|
32 | - * |
|
33 | - * Returns {@see LEVEL_RELATED}. |
|
34 | - * |
|
35 | - * @return int |
|
36 | - */ |
|
37 | - public function getNestingLevel() |
|
38 | - { |
|
39 | - return self::LEVEL_RELATED; |
|
40 | - } |
|
30 | + /** |
|
31 | + * Get the nesting level of this EmbeddedFile. |
|
32 | + * |
|
33 | + * Returns {@see LEVEL_RELATED}. |
|
34 | + * |
|
35 | + * @return int |
|
36 | + */ |
|
37 | + public function getNestingLevel() |
|
38 | + { |
|
39 | + return self::LEVEL_RELATED; |
|
40 | + } |
|
41 | 41 | } |
@@ -13,42 +13,42 @@ |
||
13 | 13 | */ |
14 | 14 | class Swift_Mime_IdGenerator implements Swift_IdGenerator |
15 | 15 | { |
16 | - private $idRight; |
|
16 | + private $idRight; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @param string $idRight |
|
20 | - */ |
|
21 | - public function __construct($idRight) |
|
22 | - { |
|
23 | - $this->idRight = $idRight; |
|
24 | - } |
|
18 | + /** |
|
19 | + * @param string $idRight |
|
20 | + */ |
|
21 | + public function __construct($idRight) |
|
22 | + { |
|
23 | + $this->idRight = $idRight; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the right-hand side of the "@" used in all generated IDs. |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function getIdRight() |
|
32 | - { |
|
33 | - return $this->idRight; |
|
34 | - } |
|
26 | + /** |
|
27 | + * Returns the right-hand side of the "@" used in all generated IDs. |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function getIdRight() |
|
32 | + { |
|
33 | + return $this->idRight; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Sets the right-hand side of the "@" to use in all generated IDs. |
|
38 | - * |
|
39 | - * @param string $idRight |
|
40 | - */ |
|
41 | - public function setIdRight($idRight) |
|
42 | - { |
|
43 | - $this->idRight = $idRight; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Sets the right-hand side of the "@" to use in all generated IDs. |
|
38 | + * |
|
39 | + * @param string $idRight |
|
40 | + */ |
|
41 | + public function setIdRight($idRight) |
|
42 | + { |
|
43 | + $this->idRight = $idRight; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function generateId() |
|
50 | - { |
|
51 | - // 32 hex values for the left part |
|
52 | - return bin2hex(random_bytes(16)).'@'.$this->idRight; |
|
53 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function generateId() |
|
50 | + { |
|
51 | + // 32 hex values for the left part |
|
52 | + return bin2hex(random_bytes(16)).'@'.$this->idRight; |
|
53 | + } |
|
54 | 54 | } |
@@ -15,628 +15,628 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart |
17 | 17 | { |
18 | - const PRIORITY_HIGHEST = 1; |
|
19 | - const PRIORITY_HIGH = 2; |
|
20 | - const PRIORITY_NORMAL = 3; |
|
21 | - const PRIORITY_LOW = 4; |
|
22 | - const PRIORITY_LOWEST = 5; |
|
23 | - |
|
24 | - /** |
|
25 | - * Create a new SimpleMessage with $headers, $encoder and $cache. |
|
26 | - * |
|
27 | - * @param string $charset |
|
28 | - */ |
|
29 | - public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) |
|
30 | - { |
|
31 | - parent::__construct($headers, $encoder, $cache, $idGenerator, $charset); |
|
32 | - $this->getHeaders()->defineOrdering([ |
|
33 | - 'Return-Path', |
|
34 | - 'Received', |
|
35 | - 'DKIM-Signature', |
|
36 | - 'DomainKey-Signature', |
|
37 | - 'Sender', |
|
38 | - 'Message-ID', |
|
39 | - 'Date', |
|
40 | - 'Subject', |
|
41 | - 'From', |
|
42 | - 'Reply-To', |
|
43 | - 'To', |
|
44 | - 'Cc', |
|
45 | - 'Bcc', |
|
46 | - 'MIME-Version', |
|
47 | - 'Content-Type', |
|
48 | - 'Content-Transfer-Encoding', |
|
49 | - ]); |
|
50 | - $this->getHeaders()->setAlwaysDisplayed(['Date', 'Message-ID', 'From']); |
|
51 | - $this->getHeaders()->addTextHeader('MIME-Version', '1.0'); |
|
52 | - $this->setDate(new DateTimeImmutable()); |
|
53 | - $this->setId($this->getId()); |
|
54 | - $this->getHeaders()->addMailboxHeader('From'); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Always returns {@link LEVEL_TOP} for a message instance. |
|
59 | - * |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function getNestingLevel() |
|
63 | - { |
|
64 | - return self::LEVEL_TOP; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Set the subject of this message. |
|
69 | - * |
|
70 | - * @param string $subject |
|
71 | - * |
|
72 | - * @return $this |
|
73 | - */ |
|
74 | - public function setSubject($subject) |
|
75 | - { |
|
76 | - if (!$this->setHeaderFieldModel('Subject', $subject)) { |
|
77 | - $this->getHeaders()->addTextHeader('Subject', $subject); |
|
78 | - } |
|
79 | - |
|
80 | - return $this; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the subject of this message. |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getSubject() |
|
89 | - { |
|
90 | - return $this->getHeaderFieldModel('Subject'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Set the date at which this message was created. |
|
95 | - * |
|
96 | - * @return $this |
|
97 | - */ |
|
98 | - public function setDate(DateTimeInterface $dateTime) |
|
99 | - { |
|
100 | - if (!$this->setHeaderFieldModel('Date', $dateTime)) { |
|
101 | - $this->getHeaders()->addDateHeader('Date', $dateTime); |
|
102 | - } |
|
103 | - |
|
104 | - return $this; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get the date at which this message was created. |
|
109 | - * |
|
110 | - * @return DateTimeInterface |
|
111 | - */ |
|
112 | - public function getDate() |
|
113 | - { |
|
114 | - return $this->getHeaderFieldModel('Date'); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Set the return-path (the bounce address) of this message. |
|
119 | - * |
|
120 | - * @param string $address |
|
121 | - * |
|
122 | - * @return $this |
|
123 | - */ |
|
124 | - public function setReturnPath($address) |
|
125 | - { |
|
126 | - if (!$this->setHeaderFieldModel('Return-Path', $address)) { |
|
127 | - $this->getHeaders()->addPathHeader('Return-Path', $address); |
|
128 | - } |
|
129 | - |
|
130 | - return $this; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Get the return-path (bounce address) of this message. |
|
135 | - * |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function getReturnPath() |
|
139 | - { |
|
140 | - return $this->getHeaderFieldModel('Return-Path'); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Set the sender of this message. |
|
145 | - * |
|
146 | - * This does not override the From field, but it has a higher significance. |
|
147 | - * |
|
148 | - * @param string $address |
|
149 | - * @param string $name optional |
|
150 | - * |
|
151 | - * @return $this |
|
152 | - */ |
|
153 | - public function setSender($address, $name = null) |
|
154 | - { |
|
155 | - if (!\is_array($address) && isset($name)) { |
|
156 | - $address = [$address => $name]; |
|
157 | - } |
|
158 | - |
|
159 | - if (!$this->setHeaderFieldModel('Sender', (array) $address)) { |
|
160 | - $this->getHeaders()->addMailboxHeader('Sender', (array) $address); |
|
161 | - } |
|
162 | - |
|
163 | - return $this; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Get the sender of this message. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getSender() |
|
172 | - { |
|
173 | - return $this->getHeaderFieldModel('Sender'); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Add a From: address to this message. |
|
178 | - * |
|
179 | - * If $name is passed this name will be associated with the address. |
|
180 | - * |
|
181 | - * @param string $address |
|
182 | - * @param string $name optional |
|
183 | - * |
|
184 | - * @return $this |
|
185 | - */ |
|
186 | - public function addFrom($address, $name = null) |
|
187 | - { |
|
188 | - $current = $this->getFrom(); |
|
189 | - $current[$address] = $name; |
|
190 | - |
|
191 | - return $this->setFrom($current); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Set the from address of this message. |
|
196 | - * |
|
197 | - * You may pass an array of addresses if this message is from multiple people. |
|
198 | - * |
|
199 | - * If $name is passed and the first parameter is a string, this name will be |
|
200 | - * associated with the address. |
|
201 | - * |
|
202 | - * @param string|array $addresses |
|
203 | - * @param string $name optional |
|
204 | - * |
|
205 | - * @return $this |
|
206 | - */ |
|
207 | - public function setFrom($addresses, $name = null) |
|
208 | - { |
|
209 | - if (!\is_array($addresses) && isset($name)) { |
|
210 | - $addresses = [$addresses => $name]; |
|
211 | - } |
|
212 | - |
|
213 | - if (!$this->setHeaderFieldModel('From', (array) $addresses)) { |
|
214 | - $this->getHeaders()->addMailboxHeader('From', (array) $addresses); |
|
215 | - } |
|
216 | - |
|
217 | - return $this; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Get the from address of this message. |
|
222 | - * |
|
223 | - * @return mixed |
|
224 | - */ |
|
225 | - public function getFrom() |
|
226 | - { |
|
227 | - return $this->getHeaderFieldModel('From'); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Add a Reply-To: address to this message. |
|
232 | - * |
|
233 | - * If $name is passed this name will be associated with the address. |
|
234 | - * |
|
235 | - * @param string $address |
|
236 | - * @param string $name optional |
|
237 | - * |
|
238 | - * @return $this |
|
239 | - */ |
|
240 | - public function addReplyTo($address, $name = null) |
|
241 | - { |
|
242 | - $current = $this->getReplyTo(); |
|
243 | - $current[$address] = $name; |
|
244 | - |
|
245 | - return $this->setReplyTo($current); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Set the reply-to address of this message. |
|
250 | - * |
|
251 | - * You may pass an array of addresses if replies will go to multiple people. |
|
252 | - * |
|
253 | - * If $name is passed and the first parameter is a string, this name will be |
|
254 | - * associated with the address. |
|
255 | - * |
|
256 | - * @param mixed $addresses |
|
257 | - * @param string $name optional |
|
258 | - * |
|
259 | - * @return $this |
|
260 | - */ |
|
261 | - public function setReplyTo($addresses, $name = null) |
|
262 | - { |
|
263 | - if (!\is_array($addresses) && isset($name)) { |
|
264 | - $addresses = [$addresses => $name]; |
|
265 | - } |
|
266 | - |
|
267 | - if (!$this->setHeaderFieldModel('Reply-To', (array) $addresses)) { |
|
268 | - $this->getHeaders()->addMailboxHeader('Reply-To', (array) $addresses); |
|
269 | - } |
|
270 | - |
|
271 | - return $this; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Get the reply-to address of this message. |
|
276 | - * |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function getReplyTo() |
|
280 | - { |
|
281 | - return $this->getHeaderFieldModel('Reply-To'); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Add a To: address to this message. |
|
286 | - * |
|
287 | - * If $name is passed this name will be associated with the address. |
|
288 | - * |
|
289 | - * @param string $address |
|
290 | - * @param string $name optional |
|
291 | - * |
|
292 | - * @return $this |
|
293 | - */ |
|
294 | - public function addTo($address, $name = null) |
|
295 | - { |
|
296 | - $current = $this->getTo(); |
|
297 | - $current[$address] = $name; |
|
298 | - |
|
299 | - return $this->setTo($current); |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Set the to addresses of this message. |
|
304 | - * |
|
305 | - * If multiple recipients will receive the message an array should be used. |
|
306 | - * Example: array('[email protected]', '[email protected]' => 'A name') |
|
307 | - * |
|
308 | - * If $name is passed and the first parameter is a string, this name will be |
|
309 | - * associated with the address. |
|
310 | - * |
|
311 | - * @param mixed $addresses |
|
312 | - * @param string $name optional |
|
313 | - * |
|
314 | - * @return $this |
|
315 | - */ |
|
316 | - public function setTo($addresses, $name = null) |
|
317 | - { |
|
318 | - if (!\is_array($addresses) && isset($name)) { |
|
319 | - $addresses = [$addresses => $name]; |
|
320 | - } |
|
321 | - |
|
322 | - if (!$this->setHeaderFieldModel('To', (array) $addresses)) { |
|
323 | - $this->getHeaders()->addMailboxHeader('To', (array) $addresses); |
|
324 | - } |
|
325 | - |
|
326 | - return $this; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Get the To addresses of this message. |
|
331 | - * |
|
332 | - * @return array |
|
333 | - */ |
|
334 | - public function getTo() |
|
335 | - { |
|
336 | - return $this->getHeaderFieldModel('To'); |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Add a Cc: address to this message. |
|
341 | - * |
|
342 | - * If $name is passed this name will be associated with the address. |
|
343 | - * |
|
344 | - * @param string $address |
|
345 | - * @param string $name optional |
|
346 | - * |
|
347 | - * @return $this |
|
348 | - */ |
|
349 | - public function addCc($address, $name = null) |
|
350 | - { |
|
351 | - $current = $this->getCc(); |
|
352 | - $current[$address] = $name; |
|
353 | - |
|
354 | - return $this->setCc($current); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set the Cc addresses of this message. |
|
359 | - * |
|
360 | - * If $name is passed and the first parameter is a string, this name will be |
|
361 | - * associated with the address. |
|
362 | - * |
|
363 | - * @param mixed $addresses |
|
364 | - * @param string $name optional |
|
365 | - * |
|
366 | - * @return $this |
|
367 | - */ |
|
368 | - public function setCc($addresses, $name = null) |
|
369 | - { |
|
370 | - if (!\is_array($addresses) && isset($name)) { |
|
371 | - $addresses = [$addresses => $name]; |
|
372 | - } |
|
373 | - |
|
374 | - if (!$this->setHeaderFieldModel('Cc', (array) $addresses)) { |
|
375 | - $this->getHeaders()->addMailboxHeader('Cc', (array) $addresses); |
|
376 | - } |
|
377 | - |
|
378 | - return $this; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Get the Cc address of this message. |
|
383 | - * |
|
384 | - * @return array |
|
385 | - */ |
|
386 | - public function getCc() |
|
387 | - { |
|
388 | - return $this->getHeaderFieldModel('Cc'); |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Add a Bcc: address to this message. |
|
393 | - * |
|
394 | - * If $name is passed this name will be associated with the address. |
|
395 | - * |
|
396 | - * @param string $address |
|
397 | - * @param string $name optional |
|
398 | - * |
|
399 | - * @return $this |
|
400 | - */ |
|
401 | - public function addBcc($address, $name = null) |
|
402 | - { |
|
403 | - $current = $this->getBcc(); |
|
404 | - $current[$address] = $name; |
|
405 | - |
|
406 | - return $this->setBcc($current); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Set the Bcc addresses of this message. |
|
411 | - * |
|
412 | - * If $name is passed and the first parameter is a string, this name will be |
|
413 | - * associated with the address. |
|
414 | - * |
|
415 | - * @param mixed $addresses |
|
416 | - * @param string $name optional |
|
417 | - * |
|
418 | - * @return $this |
|
419 | - */ |
|
420 | - public function setBcc($addresses, $name = null) |
|
421 | - { |
|
422 | - if (!\is_array($addresses) && isset($name)) { |
|
423 | - $addresses = [$addresses => $name]; |
|
424 | - } |
|
425 | - |
|
426 | - if (!$this->setHeaderFieldModel('Bcc', (array) $addresses)) { |
|
427 | - $this->getHeaders()->addMailboxHeader('Bcc', (array) $addresses); |
|
428 | - } |
|
429 | - |
|
430 | - return $this; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Get the Bcc addresses of this message. |
|
435 | - * |
|
436 | - * @return array |
|
437 | - */ |
|
438 | - public function getBcc() |
|
439 | - { |
|
440 | - return $this->getHeaderFieldModel('Bcc'); |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Set the priority of this message. |
|
445 | - * |
|
446 | - * The value is an integer where 1 is the highest priority and 5 is the lowest. |
|
447 | - * |
|
448 | - * @param int $priority |
|
449 | - * |
|
450 | - * @return $this |
|
451 | - */ |
|
452 | - public function setPriority($priority) |
|
453 | - { |
|
454 | - $priorityMap = [ |
|
455 | - self::PRIORITY_HIGHEST => 'Highest', |
|
456 | - self::PRIORITY_HIGH => 'High', |
|
457 | - self::PRIORITY_NORMAL => 'Normal', |
|
458 | - self::PRIORITY_LOW => 'Low', |
|
459 | - self::PRIORITY_LOWEST => 'Lowest', |
|
460 | - ]; |
|
461 | - $pMapKeys = array_keys($priorityMap); |
|
462 | - if ($priority > max($pMapKeys)) { |
|
463 | - $priority = max($pMapKeys); |
|
464 | - } elseif ($priority < min($pMapKeys)) { |
|
465 | - $priority = min($pMapKeys); |
|
466 | - } |
|
467 | - if (!$this->setHeaderFieldModel('X-Priority', |
|
468 | - sprintf('%d (%s)', $priority, $priorityMap[$priority]))) { |
|
469 | - $this->getHeaders()->addTextHeader('X-Priority', |
|
470 | - sprintf('%d (%s)', $priority, $priorityMap[$priority])); |
|
471 | - } |
|
472 | - |
|
473 | - return $this; |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Get the priority of this message. |
|
478 | - * |
|
479 | - * The returned value is an integer where 1 is the highest priority and 5 |
|
480 | - * is the lowest. |
|
481 | - * |
|
482 | - * @return int |
|
483 | - */ |
|
484 | - public function getPriority() |
|
485 | - { |
|
486 | - list($priority) = sscanf($this->getHeaderFieldModel('X-Priority'), |
|
487 | - '%[1-5]' |
|
488 | - ); |
|
489 | - |
|
490 | - return $priority ?? 3; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Ask for a delivery receipt from the recipient to be sent to $addresses. |
|
495 | - * |
|
496 | - * @param array $addresses |
|
497 | - * |
|
498 | - * @return $this |
|
499 | - */ |
|
500 | - public function setReadReceiptTo($addresses) |
|
501 | - { |
|
502 | - if (!$this->setHeaderFieldModel('Disposition-Notification-To', $addresses)) { |
|
503 | - $this->getHeaders() |
|
504 | - ->addMailboxHeader('Disposition-Notification-To', $addresses); |
|
505 | - } |
|
506 | - |
|
507 | - return $this; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Get the addresses to which a read-receipt will be sent. |
|
512 | - * |
|
513 | - * @return string |
|
514 | - */ |
|
515 | - public function getReadReceiptTo() |
|
516 | - { |
|
517 | - return $this->getHeaderFieldModel('Disposition-Notification-To'); |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Attach a {@link Swift_Mime_SimpleMimeEntity} such as an Attachment or MimePart. |
|
522 | - * |
|
523 | - * @return $this |
|
524 | - */ |
|
525 | - public function attach(Swift_Mime_SimpleMimeEntity $entity) |
|
526 | - { |
|
527 | - $this->setChildren(array_merge($this->getChildren(), [$entity])); |
|
528 | - |
|
529 | - return $this; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Remove an already attached entity. |
|
534 | - * |
|
535 | - * @return $this |
|
536 | - */ |
|
537 | - public function detach(Swift_Mime_SimpleMimeEntity $entity) |
|
538 | - { |
|
539 | - $newChildren = []; |
|
540 | - foreach ($this->getChildren() as $child) { |
|
541 | - if ($entity !== $child) { |
|
542 | - $newChildren[] = $child; |
|
543 | - } |
|
544 | - } |
|
545 | - $this->setChildren($newChildren); |
|
546 | - |
|
547 | - return $this; |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * Attach a {@link Swift_Mime_SimpleMimeEntity} and return it's CID source. |
|
552 | - * |
|
553 | - * This method should be used when embedding images or other data in a message. |
|
554 | - * |
|
555 | - * @return string |
|
556 | - */ |
|
557 | - public function embed(Swift_Mime_SimpleMimeEntity $entity) |
|
558 | - { |
|
559 | - $this->attach($entity); |
|
560 | - |
|
561 | - return 'cid:'.$entity->getId(); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Get this message as a complete string. |
|
566 | - * |
|
567 | - * @return string |
|
568 | - */ |
|
569 | - public function toString() |
|
570 | - { |
|
571 | - if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { |
|
572 | - $this->setChildren(array_merge([$this->becomeMimePart()], $children)); |
|
573 | - $string = parent::toString(); |
|
574 | - $this->setChildren($children); |
|
575 | - } else { |
|
576 | - $string = parent::toString(); |
|
577 | - } |
|
578 | - |
|
579 | - return $string; |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Returns a string representation of this object. |
|
584 | - * |
|
585 | - * @see toString() |
|
586 | - * |
|
587 | - * @return string |
|
588 | - */ |
|
589 | - public function __toString() |
|
590 | - { |
|
591 | - return $this->toString(); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Write this message to a {@link Swift_InputByteStream}. |
|
596 | - */ |
|
597 | - public function toByteStream(Swift_InputByteStream $is) |
|
598 | - { |
|
599 | - if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { |
|
600 | - $this->setChildren(array_merge([$this->becomeMimePart()], $children)); |
|
601 | - parent::toByteStream($is); |
|
602 | - $this->setChildren($children); |
|
603 | - } else { |
|
604 | - parent::toByteStream($is); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - /** @see Swift_Mime_SimpleMimeEntity::getIdField() */ |
|
609 | - protected function getIdField() |
|
610 | - { |
|
611 | - return 'Message-ID'; |
|
612 | - } |
|
613 | - |
|
614 | - /** Turn the body of this message into a child of itself if needed */ |
|
615 | - protected function becomeMimePart() |
|
616 | - { |
|
617 | - $part = new parent($this->getHeaders()->newInstance(), $this->getEncoder(), |
|
618 | - $this->getCache(), $this->getIdGenerator(), $this->userCharset |
|
619 | - ); |
|
620 | - $part->setContentType($this->userContentType); |
|
621 | - $part->setBody($this->getBody()); |
|
622 | - $part->setFormat($this->userFormat); |
|
623 | - $part->setDelSp($this->userDelSp); |
|
624 | - $part->setNestingLevel($this->getTopNestingLevel()); |
|
625 | - |
|
626 | - return $part; |
|
627 | - } |
|
628 | - |
|
629 | - /** Get the highest nesting level nested inside this message */ |
|
630 | - private function getTopNestingLevel() |
|
631 | - { |
|
632 | - $highestLevel = $this->getNestingLevel(); |
|
633 | - foreach ($this->getChildren() as $child) { |
|
634 | - $childLevel = $child->getNestingLevel(); |
|
635 | - if ($highestLevel < $childLevel) { |
|
636 | - $highestLevel = $childLevel; |
|
637 | - } |
|
638 | - } |
|
639 | - |
|
640 | - return $highestLevel; |
|
641 | - } |
|
18 | + const PRIORITY_HIGHEST = 1; |
|
19 | + const PRIORITY_HIGH = 2; |
|
20 | + const PRIORITY_NORMAL = 3; |
|
21 | + const PRIORITY_LOW = 4; |
|
22 | + const PRIORITY_LOWEST = 5; |
|
23 | + |
|
24 | + /** |
|
25 | + * Create a new SimpleMessage with $headers, $encoder and $cache. |
|
26 | + * |
|
27 | + * @param string $charset |
|
28 | + */ |
|
29 | + public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) |
|
30 | + { |
|
31 | + parent::__construct($headers, $encoder, $cache, $idGenerator, $charset); |
|
32 | + $this->getHeaders()->defineOrdering([ |
|
33 | + 'Return-Path', |
|
34 | + 'Received', |
|
35 | + 'DKIM-Signature', |
|
36 | + 'DomainKey-Signature', |
|
37 | + 'Sender', |
|
38 | + 'Message-ID', |
|
39 | + 'Date', |
|
40 | + 'Subject', |
|
41 | + 'From', |
|
42 | + 'Reply-To', |
|
43 | + 'To', |
|
44 | + 'Cc', |
|
45 | + 'Bcc', |
|
46 | + 'MIME-Version', |
|
47 | + 'Content-Type', |
|
48 | + 'Content-Transfer-Encoding', |
|
49 | + ]); |
|
50 | + $this->getHeaders()->setAlwaysDisplayed(['Date', 'Message-ID', 'From']); |
|
51 | + $this->getHeaders()->addTextHeader('MIME-Version', '1.0'); |
|
52 | + $this->setDate(new DateTimeImmutable()); |
|
53 | + $this->setId($this->getId()); |
|
54 | + $this->getHeaders()->addMailboxHeader('From'); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Always returns {@link LEVEL_TOP} for a message instance. |
|
59 | + * |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function getNestingLevel() |
|
63 | + { |
|
64 | + return self::LEVEL_TOP; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Set the subject of this message. |
|
69 | + * |
|
70 | + * @param string $subject |
|
71 | + * |
|
72 | + * @return $this |
|
73 | + */ |
|
74 | + public function setSubject($subject) |
|
75 | + { |
|
76 | + if (!$this->setHeaderFieldModel('Subject', $subject)) { |
|
77 | + $this->getHeaders()->addTextHeader('Subject', $subject); |
|
78 | + } |
|
79 | + |
|
80 | + return $this; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the subject of this message. |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getSubject() |
|
89 | + { |
|
90 | + return $this->getHeaderFieldModel('Subject'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Set the date at which this message was created. |
|
95 | + * |
|
96 | + * @return $this |
|
97 | + */ |
|
98 | + public function setDate(DateTimeInterface $dateTime) |
|
99 | + { |
|
100 | + if (!$this->setHeaderFieldModel('Date', $dateTime)) { |
|
101 | + $this->getHeaders()->addDateHeader('Date', $dateTime); |
|
102 | + } |
|
103 | + |
|
104 | + return $this; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get the date at which this message was created. |
|
109 | + * |
|
110 | + * @return DateTimeInterface |
|
111 | + */ |
|
112 | + public function getDate() |
|
113 | + { |
|
114 | + return $this->getHeaderFieldModel('Date'); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Set the return-path (the bounce address) of this message. |
|
119 | + * |
|
120 | + * @param string $address |
|
121 | + * |
|
122 | + * @return $this |
|
123 | + */ |
|
124 | + public function setReturnPath($address) |
|
125 | + { |
|
126 | + if (!$this->setHeaderFieldModel('Return-Path', $address)) { |
|
127 | + $this->getHeaders()->addPathHeader('Return-Path', $address); |
|
128 | + } |
|
129 | + |
|
130 | + return $this; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Get the return-path (bounce address) of this message. |
|
135 | + * |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function getReturnPath() |
|
139 | + { |
|
140 | + return $this->getHeaderFieldModel('Return-Path'); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Set the sender of this message. |
|
145 | + * |
|
146 | + * This does not override the From field, but it has a higher significance. |
|
147 | + * |
|
148 | + * @param string $address |
|
149 | + * @param string $name optional |
|
150 | + * |
|
151 | + * @return $this |
|
152 | + */ |
|
153 | + public function setSender($address, $name = null) |
|
154 | + { |
|
155 | + if (!\is_array($address) && isset($name)) { |
|
156 | + $address = [$address => $name]; |
|
157 | + } |
|
158 | + |
|
159 | + if (!$this->setHeaderFieldModel('Sender', (array) $address)) { |
|
160 | + $this->getHeaders()->addMailboxHeader('Sender', (array) $address); |
|
161 | + } |
|
162 | + |
|
163 | + return $this; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Get the sender of this message. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getSender() |
|
172 | + { |
|
173 | + return $this->getHeaderFieldModel('Sender'); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Add a From: address to this message. |
|
178 | + * |
|
179 | + * If $name is passed this name will be associated with the address. |
|
180 | + * |
|
181 | + * @param string $address |
|
182 | + * @param string $name optional |
|
183 | + * |
|
184 | + * @return $this |
|
185 | + */ |
|
186 | + public function addFrom($address, $name = null) |
|
187 | + { |
|
188 | + $current = $this->getFrom(); |
|
189 | + $current[$address] = $name; |
|
190 | + |
|
191 | + return $this->setFrom($current); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Set the from address of this message. |
|
196 | + * |
|
197 | + * You may pass an array of addresses if this message is from multiple people. |
|
198 | + * |
|
199 | + * If $name is passed and the first parameter is a string, this name will be |
|
200 | + * associated with the address. |
|
201 | + * |
|
202 | + * @param string|array $addresses |
|
203 | + * @param string $name optional |
|
204 | + * |
|
205 | + * @return $this |
|
206 | + */ |
|
207 | + public function setFrom($addresses, $name = null) |
|
208 | + { |
|
209 | + if (!\is_array($addresses) && isset($name)) { |
|
210 | + $addresses = [$addresses => $name]; |
|
211 | + } |
|
212 | + |
|
213 | + if (!$this->setHeaderFieldModel('From', (array) $addresses)) { |
|
214 | + $this->getHeaders()->addMailboxHeader('From', (array) $addresses); |
|
215 | + } |
|
216 | + |
|
217 | + return $this; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Get the from address of this message. |
|
222 | + * |
|
223 | + * @return mixed |
|
224 | + */ |
|
225 | + public function getFrom() |
|
226 | + { |
|
227 | + return $this->getHeaderFieldModel('From'); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Add a Reply-To: address to this message. |
|
232 | + * |
|
233 | + * If $name is passed this name will be associated with the address. |
|
234 | + * |
|
235 | + * @param string $address |
|
236 | + * @param string $name optional |
|
237 | + * |
|
238 | + * @return $this |
|
239 | + */ |
|
240 | + public function addReplyTo($address, $name = null) |
|
241 | + { |
|
242 | + $current = $this->getReplyTo(); |
|
243 | + $current[$address] = $name; |
|
244 | + |
|
245 | + return $this->setReplyTo($current); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Set the reply-to address of this message. |
|
250 | + * |
|
251 | + * You may pass an array of addresses if replies will go to multiple people. |
|
252 | + * |
|
253 | + * If $name is passed and the first parameter is a string, this name will be |
|
254 | + * associated with the address. |
|
255 | + * |
|
256 | + * @param mixed $addresses |
|
257 | + * @param string $name optional |
|
258 | + * |
|
259 | + * @return $this |
|
260 | + */ |
|
261 | + public function setReplyTo($addresses, $name = null) |
|
262 | + { |
|
263 | + if (!\is_array($addresses) && isset($name)) { |
|
264 | + $addresses = [$addresses => $name]; |
|
265 | + } |
|
266 | + |
|
267 | + if (!$this->setHeaderFieldModel('Reply-To', (array) $addresses)) { |
|
268 | + $this->getHeaders()->addMailboxHeader('Reply-To', (array) $addresses); |
|
269 | + } |
|
270 | + |
|
271 | + return $this; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Get the reply-to address of this message. |
|
276 | + * |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function getReplyTo() |
|
280 | + { |
|
281 | + return $this->getHeaderFieldModel('Reply-To'); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Add a To: address to this message. |
|
286 | + * |
|
287 | + * If $name is passed this name will be associated with the address. |
|
288 | + * |
|
289 | + * @param string $address |
|
290 | + * @param string $name optional |
|
291 | + * |
|
292 | + * @return $this |
|
293 | + */ |
|
294 | + public function addTo($address, $name = null) |
|
295 | + { |
|
296 | + $current = $this->getTo(); |
|
297 | + $current[$address] = $name; |
|
298 | + |
|
299 | + return $this->setTo($current); |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Set the to addresses of this message. |
|
304 | + * |
|
305 | + * If multiple recipients will receive the message an array should be used. |
|
306 | + * Example: array('[email protected]', '[email protected]' => 'A name') |
|
307 | + * |
|
308 | + * If $name is passed and the first parameter is a string, this name will be |
|
309 | + * associated with the address. |
|
310 | + * |
|
311 | + * @param mixed $addresses |
|
312 | + * @param string $name optional |
|
313 | + * |
|
314 | + * @return $this |
|
315 | + */ |
|
316 | + public function setTo($addresses, $name = null) |
|
317 | + { |
|
318 | + if (!\is_array($addresses) && isset($name)) { |
|
319 | + $addresses = [$addresses => $name]; |
|
320 | + } |
|
321 | + |
|
322 | + if (!$this->setHeaderFieldModel('To', (array) $addresses)) { |
|
323 | + $this->getHeaders()->addMailboxHeader('To', (array) $addresses); |
|
324 | + } |
|
325 | + |
|
326 | + return $this; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Get the To addresses of this message. |
|
331 | + * |
|
332 | + * @return array |
|
333 | + */ |
|
334 | + public function getTo() |
|
335 | + { |
|
336 | + return $this->getHeaderFieldModel('To'); |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Add a Cc: address to this message. |
|
341 | + * |
|
342 | + * If $name is passed this name will be associated with the address. |
|
343 | + * |
|
344 | + * @param string $address |
|
345 | + * @param string $name optional |
|
346 | + * |
|
347 | + * @return $this |
|
348 | + */ |
|
349 | + public function addCc($address, $name = null) |
|
350 | + { |
|
351 | + $current = $this->getCc(); |
|
352 | + $current[$address] = $name; |
|
353 | + |
|
354 | + return $this->setCc($current); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set the Cc addresses of this message. |
|
359 | + * |
|
360 | + * If $name is passed and the first parameter is a string, this name will be |
|
361 | + * associated with the address. |
|
362 | + * |
|
363 | + * @param mixed $addresses |
|
364 | + * @param string $name optional |
|
365 | + * |
|
366 | + * @return $this |
|
367 | + */ |
|
368 | + public function setCc($addresses, $name = null) |
|
369 | + { |
|
370 | + if (!\is_array($addresses) && isset($name)) { |
|
371 | + $addresses = [$addresses => $name]; |
|
372 | + } |
|
373 | + |
|
374 | + if (!$this->setHeaderFieldModel('Cc', (array) $addresses)) { |
|
375 | + $this->getHeaders()->addMailboxHeader('Cc', (array) $addresses); |
|
376 | + } |
|
377 | + |
|
378 | + return $this; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Get the Cc address of this message. |
|
383 | + * |
|
384 | + * @return array |
|
385 | + */ |
|
386 | + public function getCc() |
|
387 | + { |
|
388 | + return $this->getHeaderFieldModel('Cc'); |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Add a Bcc: address to this message. |
|
393 | + * |
|
394 | + * If $name is passed this name will be associated with the address. |
|
395 | + * |
|
396 | + * @param string $address |
|
397 | + * @param string $name optional |
|
398 | + * |
|
399 | + * @return $this |
|
400 | + */ |
|
401 | + public function addBcc($address, $name = null) |
|
402 | + { |
|
403 | + $current = $this->getBcc(); |
|
404 | + $current[$address] = $name; |
|
405 | + |
|
406 | + return $this->setBcc($current); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Set the Bcc addresses of this message. |
|
411 | + * |
|
412 | + * If $name is passed and the first parameter is a string, this name will be |
|
413 | + * associated with the address. |
|
414 | + * |
|
415 | + * @param mixed $addresses |
|
416 | + * @param string $name optional |
|
417 | + * |
|
418 | + * @return $this |
|
419 | + */ |
|
420 | + public function setBcc($addresses, $name = null) |
|
421 | + { |
|
422 | + if (!\is_array($addresses) && isset($name)) { |
|
423 | + $addresses = [$addresses => $name]; |
|
424 | + } |
|
425 | + |
|
426 | + if (!$this->setHeaderFieldModel('Bcc', (array) $addresses)) { |
|
427 | + $this->getHeaders()->addMailboxHeader('Bcc', (array) $addresses); |
|
428 | + } |
|
429 | + |
|
430 | + return $this; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Get the Bcc addresses of this message. |
|
435 | + * |
|
436 | + * @return array |
|
437 | + */ |
|
438 | + public function getBcc() |
|
439 | + { |
|
440 | + return $this->getHeaderFieldModel('Bcc'); |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Set the priority of this message. |
|
445 | + * |
|
446 | + * The value is an integer where 1 is the highest priority and 5 is the lowest. |
|
447 | + * |
|
448 | + * @param int $priority |
|
449 | + * |
|
450 | + * @return $this |
|
451 | + */ |
|
452 | + public function setPriority($priority) |
|
453 | + { |
|
454 | + $priorityMap = [ |
|
455 | + self::PRIORITY_HIGHEST => 'Highest', |
|
456 | + self::PRIORITY_HIGH => 'High', |
|
457 | + self::PRIORITY_NORMAL => 'Normal', |
|
458 | + self::PRIORITY_LOW => 'Low', |
|
459 | + self::PRIORITY_LOWEST => 'Lowest', |
|
460 | + ]; |
|
461 | + $pMapKeys = array_keys($priorityMap); |
|
462 | + if ($priority > max($pMapKeys)) { |
|
463 | + $priority = max($pMapKeys); |
|
464 | + } elseif ($priority < min($pMapKeys)) { |
|
465 | + $priority = min($pMapKeys); |
|
466 | + } |
|
467 | + if (!$this->setHeaderFieldModel('X-Priority', |
|
468 | + sprintf('%d (%s)', $priority, $priorityMap[$priority]))) { |
|
469 | + $this->getHeaders()->addTextHeader('X-Priority', |
|
470 | + sprintf('%d (%s)', $priority, $priorityMap[$priority])); |
|
471 | + } |
|
472 | + |
|
473 | + return $this; |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Get the priority of this message. |
|
478 | + * |
|
479 | + * The returned value is an integer where 1 is the highest priority and 5 |
|
480 | + * is the lowest. |
|
481 | + * |
|
482 | + * @return int |
|
483 | + */ |
|
484 | + public function getPriority() |
|
485 | + { |
|
486 | + list($priority) = sscanf($this->getHeaderFieldModel('X-Priority'), |
|
487 | + '%[1-5]' |
|
488 | + ); |
|
489 | + |
|
490 | + return $priority ?? 3; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Ask for a delivery receipt from the recipient to be sent to $addresses. |
|
495 | + * |
|
496 | + * @param array $addresses |
|
497 | + * |
|
498 | + * @return $this |
|
499 | + */ |
|
500 | + public function setReadReceiptTo($addresses) |
|
501 | + { |
|
502 | + if (!$this->setHeaderFieldModel('Disposition-Notification-To', $addresses)) { |
|
503 | + $this->getHeaders() |
|
504 | + ->addMailboxHeader('Disposition-Notification-To', $addresses); |
|
505 | + } |
|
506 | + |
|
507 | + return $this; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Get the addresses to which a read-receipt will be sent. |
|
512 | + * |
|
513 | + * @return string |
|
514 | + */ |
|
515 | + public function getReadReceiptTo() |
|
516 | + { |
|
517 | + return $this->getHeaderFieldModel('Disposition-Notification-To'); |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Attach a {@link Swift_Mime_SimpleMimeEntity} such as an Attachment or MimePart. |
|
522 | + * |
|
523 | + * @return $this |
|
524 | + */ |
|
525 | + public function attach(Swift_Mime_SimpleMimeEntity $entity) |
|
526 | + { |
|
527 | + $this->setChildren(array_merge($this->getChildren(), [$entity])); |
|
528 | + |
|
529 | + return $this; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Remove an already attached entity. |
|
534 | + * |
|
535 | + * @return $this |
|
536 | + */ |
|
537 | + public function detach(Swift_Mime_SimpleMimeEntity $entity) |
|
538 | + { |
|
539 | + $newChildren = []; |
|
540 | + foreach ($this->getChildren() as $child) { |
|
541 | + if ($entity !== $child) { |
|
542 | + $newChildren[] = $child; |
|
543 | + } |
|
544 | + } |
|
545 | + $this->setChildren($newChildren); |
|
546 | + |
|
547 | + return $this; |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * Attach a {@link Swift_Mime_SimpleMimeEntity} and return it's CID source. |
|
552 | + * |
|
553 | + * This method should be used when embedding images or other data in a message. |
|
554 | + * |
|
555 | + * @return string |
|
556 | + */ |
|
557 | + public function embed(Swift_Mime_SimpleMimeEntity $entity) |
|
558 | + { |
|
559 | + $this->attach($entity); |
|
560 | + |
|
561 | + return 'cid:'.$entity->getId(); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Get this message as a complete string. |
|
566 | + * |
|
567 | + * @return string |
|
568 | + */ |
|
569 | + public function toString() |
|
570 | + { |
|
571 | + if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { |
|
572 | + $this->setChildren(array_merge([$this->becomeMimePart()], $children)); |
|
573 | + $string = parent::toString(); |
|
574 | + $this->setChildren($children); |
|
575 | + } else { |
|
576 | + $string = parent::toString(); |
|
577 | + } |
|
578 | + |
|
579 | + return $string; |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Returns a string representation of this object. |
|
584 | + * |
|
585 | + * @see toString() |
|
586 | + * |
|
587 | + * @return string |
|
588 | + */ |
|
589 | + public function __toString() |
|
590 | + { |
|
591 | + return $this->toString(); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Write this message to a {@link Swift_InputByteStream}. |
|
596 | + */ |
|
597 | + public function toByteStream(Swift_InputByteStream $is) |
|
598 | + { |
|
599 | + if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { |
|
600 | + $this->setChildren(array_merge([$this->becomeMimePart()], $children)); |
|
601 | + parent::toByteStream($is); |
|
602 | + $this->setChildren($children); |
|
603 | + } else { |
|
604 | + parent::toByteStream($is); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + /** @see Swift_Mime_SimpleMimeEntity::getIdField() */ |
|
609 | + protected function getIdField() |
|
610 | + { |
|
611 | + return 'Message-ID'; |
|
612 | + } |
|
613 | + |
|
614 | + /** Turn the body of this message into a child of itself if needed */ |
|
615 | + protected function becomeMimePart() |
|
616 | + { |
|
617 | + $part = new parent($this->getHeaders()->newInstance(), $this->getEncoder(), |
|
618 | + $this->getCache(), $this->getIdGenerator(), $this->userCharset |
|
619 | + ); |
|
620 | + $part->setContentType($this->userContentType); |
|
621 | + $part->setBody($this->getBody()); |
|
622 | + $part->setFormat($this->userFormat); |
|
623 | + $part->setDelSp($this->userDelSp); |
|
624 | + $part->setNestingLevel($this->getTopNestingLevel()); |
|
625 | + |
|
626 | + return $part; |
|
627 | + } |
|
628 | + |
|
629 | + /** Get the highest nesting level nested inside this message */ |
|
630 | + private function getTopNestingLevel() |
|
631 | + { |
|
632 | + $highestLevel = $this->getNestingLevel(); |
|
633 | + foreach ($this->getChildren() as $child) { |
|
634 | + $childLevel = $child->getNestingLevel(); |
|
635 | + if ($highestLevel < $childLevel) { |
|
636 | + $highestLevel = $childLevel; |
|
637 | + } |
|
638 | + } |
|
639 | + |
|
640 | + return $highestLevel; |
|
641 | + } |
|
642 | 642 | } |
@@ -15,41 +15,41 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder |
17 | 17 | { |
18 | - /** |
|
19 | - * Get the name of this encoding scheme. |
|
20 | - * Returns the string 'B'. |
|
21 | - * |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function getName() |
|
25 | - { |
|
26 | - return 'B'; |
|
27 | - } |
|
18 | + /** |
|
19 | + * Get the name of this encoding scheme. |
|
20 | + * Returns the string 'B'. |
|
21 | + * |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function getName() |
|
25 | + { |
|
26 | + return 'B'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Takes an unencoded string and produces a Base64 encoded string from it. |
|
31 | - * |
|
32 | - * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of |
|
33 | - * default encodeString, otherwise pass to the parent method. |
|
34 | - * |
|
35 | - * @param string $string string to encode |
|
36 | - * @param int $firstLineOffset |
|
37 | - * @param int $maxLineLength optional, 0 indicates the default of 76 bytes |
|
38 | - * @param string $charset |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') |
|
43 | - { |
|
44 | - if ('iso-2022-jp' === strtolower($charset ?? '')) { |
|
45 | - $old = mb_internal_encoding(); |
|
46 | - mb_internal_encoding('utf-8'); |
|
47 | - $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); |
|
48 | - mb_internal_encoding($old); |
|
29 | + /** |
|
30 | + * Takes an unencoded string and produces a Base64 encoded string from it. |
|
31 | + * |
|
32 | + * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of |
|
33 | + * default encodeString, otherwise pass to the parent method. |
|
34 | + * |
|
35 | + * @param string $string string to encode |
|
36 | + * @param int $firstLineOffset |
|
37 | + * @param int $maxLineLength optional, 0 indicates the default of 76 bytes |
|
38 | + * @param string $charset |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') |
|
43 | + { |
|
44 | + if ('iso-2022-jp' === strtolower($charset ?? '')) { |
|
45 | + $old = mb_internal_encoding(); |
|
46 | + mb_internal_encoding('utf-8'); |
|
47 | + $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); |
|
48 | + mb_internal_encoding($old); |
|
49 | 49 | |
50 | - return $newstring; |
|
51 | - } |
|
50 | + return $newstring; |
|
51 | + } |
|
52 | 52 | |
53 | - return parent::encodeString($string, $firstLineOffset, $maxLineLength); |
|
54 | - } |
|
53 | + return parent::encodeString($string, $firstLineOffset, $maxLineLength); |
|
54 | + } |
|
55 | 55 | } |