@@ -15,187 +15,187 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener |
17 | 17 | { |
18 | - /** |
|
19 | - * The recipient who will receive all messages. |
|
20 | - * |
|
21 | - * @var mixed |
|
22 | - */ |
|
23 | - private $recipient; |
|
24 | - |
|
25 | - /** |
|
26 | - * List of regular expression for recipient whitelisting. |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $whitelist = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * Create a new RedirectingPlugin. |
|
34 | - * |
|
35 | - * @param mixed $recipient |
|
36 | - */ |
|
37 | - public function __construct($recipient, array $whitelist = []) |
|
38 | - { |
|
39 | - $this->recipient = $recipient; |
|
40 | - $this->whitelist = $whitelist; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Set the recipient of all messages. |
|
45 | - * |
|
46 | - * @param mixed $recipient |
|
47 | - */ |
|
48 | - public function setRecipient($recipient) |
|
49 | - { |
|
50 | - $this->recipient = $recipient; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get the recipient of all messages. |
|
55 | - * |
|
56 | - * @return mixed |
|
57 | - */ |
|
58 | - public function getRecipient() |
|
59 | - { |
|
60 | - return $this->recipient; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Set a list of regular expressions to whitelist certain recipients. |
|
65 | - */ |
|
66 | - public function setWhitelist(array $whitelist) |
|
67 | - { |
|
68 | - $this->whitelist = $whitelist; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Get the whitelist. |
|
73 | - * |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - public function getWhitelist() |
|
77 | - { |
|
78 | - return $this->whitelist; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Invoked immediately before the Message is sent. |
|
83 | - */ |
|
84 | - public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
85 | - { |
|
86 | - $message = $evt->getMessage(); |
|
87 | - $headers = $message->getHeaders(); |
|
88 | - |
|
89 | - // conditionally save current recipients |
|
90 | - |
|
91 | - if ($headers->has('to')) { |
|
92 | - $headers->addMailboxHeader('X-Swift-To', $message->getTo()); |
|
93 | - } |
|
94 | - |
|
95 | - if ($headers->has('cc')) { |
|
96 | - $headers->addMailboxHeader('X-Swift-Cc', $message->getCc()); |
|
97 | - } |
|
98 | - |
|
99 | - if ($headers->has('bcc')) { |
|
100 | - $headers->addMailboxHeader('X-Swift-Bcc', $message->getBcc()); |
|
101 | - } |
|
102 | - |
|
103 | - // Filter remaining headers against whitelist |
|
104 | - $this->filterHeaderSet($headers, 'To'); |
|
105 | - $this->filterHeaderSet($headers, 'Cc'); |
|
106 | - $this->filterHeaderSet($headers, 'Bcc'); |
|
107 | - |
|
108 | - // Add each hard coded recipient |
|
109 | - $to = $message->getTo(); |
|
110 | - if (null === $to) { |
|
111 | - $to = []; |
|
112 | - } |
|
113 | - |
|
114 | - foreach ((array) $this->recipient as $recipient) { |
|
115 | - if (!\array_key_exists($recipient, $to)) { |
|
116 | - $message->addTo($recipient); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Filter header set against a whitelist of regular expressions. |
|
123 | - * |
|
124 | - * @param string $type |
|
125 | - */ |
|
126 | - private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type) |
|
127 | - { |
|
128 | - foreach ($headerSet->getAll($type) as $headers) { |
|
129 | - $headers->setNameAddresses($this->filterNameAddresses($headers->getNameAddresses())); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Filtered list of addresses => name pairs. |
|
135 | - * |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - private function filterNameAddresses(array $recipients) |
|
139 | - { |
|
140 | - $filtered = []; |
|
141 | - |
|
142 | - foreach ($recipients as $address => $name) { |
|
143 | - if ($this->isWhitelisted($address)) { |
|
144 | - $filtered[$address] = $name; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return $filtered; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Matches address against whitelist of regular expressions. |
|
153 | - * |
|
154 | - * @return bool |
|
155 | - */ |
|
156 | - protected function isWhitelisted($recipient) |
|
157 | - { |
|
158 | - if (\in_array($recipient, (array) $this->recipient)) { |
|
159 | - return true; |
|
160 | - } |
|
161 | - |
|
162 | - foreach ($this->whitelist as $pattern) { |
|
163 | - if (preg_match($pattern, $recipient)) { |
|
164 | - return true; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - return false; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Invoked immediately after the Message is sent. |
|
173 | - */ |
|
174 | - public function sendPerformed(Swift_Events_SendEvent $evt) |
|
175 | - { |
|
176 | - $this->restoreMessage($evt->getMessage()); |
|
177 | - } |
|
178 | - |
|
179 | - private function restoreMessage(Swift_Mime_SimpleMessage $message) |
|
180 | - { |
|
181 | - // restore original headers |
|
182 | - $headers = $message->getHeaders(); |
|
183 | - |
|
184 | - if ($headers->has('X-Swift-To')) { |
|
185 | - $message->setTo($headers->get('X-Swift-To')->getNameAddresses()); |
|
186 | - $headers->removeAll('X-Swift-To'); |
|
187 | - } else { |
|
188 | - $message->setTo(null); |
|
189 | - } |
|
190 | - |
|
191 | - if ($headers->has('X-Swift-Cc')) { |
|
192 | - $message->setCc($headers->get('X-Swift-Cc')->getNameAddresses()); |
|
193 | - $headers->removeAll('X-Swift-Cc'); |
|
194 | - } |
|
195 | - |
|
196 | - if ($headers->has('X-Swift-Bcc')) { |
|
197 | - $message->setBcc($headers->get('X-Swift-Bcc')->getNameAddresses()); |
|
198 | - $headers->removeAll('X-Swift-Bcc'); |
|
199 | - } |
|
200 | - } |
|
18 | + /** |
|
19 | + * The recipient who will receive all messages. |
|
20 | + * |
|
21 | + * @var mixed |
|
22 | + */ |
|
23 | + private $recipient; |
|
24 | + |
|
25 | + /** |
|
26 | + * List of regular expression for recipient whitelisting. |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $whitelist = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * Create a new RedirectingPlugin. |
|
34 | + * |
|
35 | + * @param mixed $recipient |
|
36 | + */ |
|
37 | + public function __construct($recipient, array $whitelist = []) |
|
38 | + { |
|
39 | + $this->recipient = $recipient; |
|
40 | + $this->whitelist = $whitelist; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Set the recipient of all messages. |
|
45 | + * |
|
46 | + * @param mixed $recipient |
|
47 | + */ |
|
48 | + public function setRecipient($recipient) |
|
49 | + { |
|
50 | + $this->recipient = $recipient; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get the recipient of all messages. |
|
55 | + * |
|
56 | + * @return mixed |
|
57 | + */ |
|
58 | + public function getRecipient() |
|
59 | + { |
|
60 | + return $this->recipient; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Set a list of regular expressions to whitelist certain recipients. |
|
65 | + */ |
|
66 | + public function setWhitelist(array $whitelist) |
|
67 | + { |
|
68 | + $this->whitelist = $whitelist; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Get the whitelist. |
|
73 | + * |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + public function getWhitelist() |
|
77 | + { |
|
78 | + return $this->whitelist; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Invoked immediately before the Message is sent. |
|
83 | + */ |
|
84 | + public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
85 | + { |
|
86 | + $message = $evt->getMessage(); |
|
87 | + $headers = $message->getHeaders(); |
|
88 | + |
|
89 | + // conditionally save current recipients |
|
90 | + |
|
91 | + if ($headers->has('to')) { |
|
92 | + $headers->addMailboxHeader('X-Swift-To', $message->getTo()); |
|
93 | + } |
|
94 | + |
|
95 | + if ($headers->has('cc')) { |
|
96 | + $headers->addMailboxHeader('X-Swift-Cc', $message->getCc()); |
|
97 | + } |
|
98 | + |
|
99 | + if ($headers->has('bcc')) { |
|
100 | + $headers->addMailboxHeader('X-Swift-Bcc', $message->getBcc()); |
|
101 | + } |
|
102 | + |
|
103 | + // Filter remaining headers against whitelist |
|
104 | + $this->filterHeaderSet($headers, 'To'); |
|
105 | + $this->filterHeaderSet($headers, 'Cc'); |
|
106 | + $this->filterHeaderSet($headers, 'Bcc'); |
|
107 | + |
|
108 | + // Add each hard coded recipient |
|
109 | + $to = $message->getTo(); |
|
110 | + if (null === $to) { |
|
111 | + $to = []; |
|
112 | + } |
|
113 | + |
|
114 | + foreach ((array) $this->recipient as $recipient) { |
|
115 | + if (!\array_key_exists($recipient, $to)) { |
|
116 | + $message->addTo($recipient); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Filter header set against a whitelist of regular expressions. |
|
123 | + * |
|
124 | + * @param string $type |
|
125 | + */ |
|
126 | + private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type) |
|
127 | + { |
|
128 | + foreach ($headerSet->getAll($type) as $headers) { |
|
129 | + $headers->setNameAddresses($this->filterNameAddresses($headers->getNameAddresses())); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Filtered list of addresses => name pairs. |
|
135 | + * |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + private function filterNameAddresses(array $recipients) |
|
139 | + { |
|
140 | + $filtered = []; |
|
141 | + |
|
142 | + foreach ($recipients as $address => $name) { |
|
143 | + if ($this->isWhitelisted($address)) { |
|
144 | + $filtered[$address] = $name; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return $filtered; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Matches address against whitelist of regular expressions. |
|
153 | + * |
|
154 | + * @return bool |
|
155 | + */ |
|
156 | + protected function isWhitelisted($recipient) |
|
157 | + { |
|
158 | + if (\in_array($recipient, (array) $this->recipient)) { |
|
159 | + return true; |
|
160 | + } |
|
161 | + |
|
162 | + foreach ($this->whitelist as $pattern) { |
|
163 | + if (preg_match($pattern, $recipient)) { |
|
164 | + return true; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + return false; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Invoked immediately after the Message is sent. |
|
173 | + */ |
|
174 | + public function sendPerformed(Swift_Events_SendEvent $evt) |
|
175 | + { |
|
176 | + $this->restoreMessage($evt->getMessage()); |
|
177 | + } |
|
178 | + |
|
179 | + private function restoreMessage(Swift_Mime_SimpleMessage $message) |
|
180 | + { |
|
181 | + // restore original headers |
|
182 | + $headers = $message->getHeaders(); |
|
183 | + |
|
184 | + if ($headers->has('X-Swift-To')) { |
|
185 | + $message->setTo($headers->get('X-Swift-To')->getNameAddresses()); |
|
186 | + $headers->removeAll('X-Swift-To'); |
|
187 | + } else { |
|
188 | + $message->setTo(null); |
|
189 | + } |
|
190 | + |
|
191 | + if ($headers->has('X-Swift-Cc')) { |
|
192 | + $message->setCc($headers->get('X-Swift-Cc')->getNameAddresses()); |
|
193 | + $headers->removeAll('X-Swift-Cc'); |
|
194 | + } |
|
195 | + |
|
196 | + if ($headers->has('X-Swift-Bcc')) { |
|
197 | + $message->setBcc($headers->get('X-Swift-Bcc')->getNameAddresses()); |
|
198 | + $headers->removeAll('X-Swift-Bcc'); |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -15,123 +15,123 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_Plugins_Sleeper |
17 | 17 | { |
18 | - /** |
|
19 | - * The number of emails to send before restarting Transport. |
|
20 | - * |
|
21 | - * @var int |
|
22 | - */ |
|
23 | - private $threshold; |
|
18 | + /** |
|
19 | + * The number of emails to send before restarting Transport. |
|
20 | + * |
|
21 | + * @var int |
|
22 | + */ |
|
23 | + private $threshold; |
|
24 | 24 | |
25 | - /** |
|
26 | - * The number of seconds to sleep for during a restart. |
|
27 | - * |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - private $sleep; |
|
25 | + /** |
|
26 | + * The number of seconds to sleep for during a restart. |
|
27 | + * |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + private $sleep; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The internal counter. |
|
34 | - * |
|
35 | - * @var int |
|
36 | - */ |
|
37 | - private $counter = 0; |
|
32 | + /** |
|
33 | + * The internal counter. |
|
34 | + * |
|
35 | + * @var int |
|
36 | + */ |
|
37 | + private $counter = 0; |
|
38 | 38 | |
39 | - /** |
|
40 | - * The Sleeper instance for sleeping. |
|
41 | - * |
|
42 | - * @var Swift_Plugins_Sleeper |
|
43 | - */ |
|
44 | - private $sleeper; |
|
39 | + /** |
|
40 | + * The Sleeper instance for sleeping. |
|
41 | + * |
|
42 | + * @var Swift_Plugins_Sleeper |
|
43 | + */ |
|
44 | + private $sleeper; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Create a new AntiFloodPlugin with $threshold and $sleep time. |
|
48 | - * |
|
49 | - * @param int $threshold |
|
50 | - * @param int $sleep time |
|
51 | - * @param Swift_Plugins_Sleeper $sleeper (not needed really) |
|
52 | - */ |
|
53 | - public function __construct($threshold = 99, $sleep = 0, Swift_Plugins_Sleeper $sleeper = null) |
|
54 | - { |
|
55 | - $this->setThreshold($threshold); |
|
56 | - $this->setSleepTime($sleep); |
|
57 | - $this->sleeper = $sleeper; |
|
58 | - } |
|
46 | + /** |
|
47 | + * Create a new AntiFloodPlugin with $threshold and $sleep time. |
|
48 | + * |
|
49 | + * @param int $threshold |
|
50 | + * @param int $sleep time |
|
51 | + * @param Swift_Plugins_Sleeper $sleeper (not needed really) |
|
52 | + */ |
|
53 | + public function __construct($threshold = 99, $sleep = 0, Swift_Plugins_Sleeper $sleeper = null) |
|
54 | + { |
|
55 | + $this->setThreshold($threshold); |
|
56 | + $this->setSleepTime($sleep); |
|
57 | + $this->sleeper = $sleeper; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Set the number of emails to send before restarting. |
|
62 | - * |
|
63 | - * @param int $threshold |
|
64 | - */ |
|
65 | - public function setThreshold($threshold) |
|
66 | - { |
|
67 | - $this->threshold = $threshold; |
|
68 | - } |
|
60 | + /** |
|
61 | + * Set the number of emails to send before restarting. |
|
62 | + * |
|
63 | + * @param int $threshold |
|
64 | + */ |
|
65 | + public function setThreshold($threshold) |
|
66 | + { |
|
67 | + $this->threshold = $threshold; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get the number of emails to send before restarting. |
|
72 | - * |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - public function getThreshold() |
|
76 | - { |
|
77 | - return $this->threshold; |
|
78 | - } |
|
70 | + /** |
|
71 | + * Get the number of emails to send before restarting. |
|
72 | + * |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + public function getThreshold() |
|
76 | + { |
|
77 | + return $this->threshold; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Set the number of seconds to sleep for during a restart. |
|
82 | - * |
|
83 | - * @param int $sleep time |
|
84 | - */ |
|
85 | - public function setSleepTime($sleep) |
|
86 | - { |
|
87 | - $this->sleep = $sleep; |
|
88 | - } |
|
80 | + /** |
|
81 | + * Set the number of seconds to sleep for during a restart. |
|
82 | + * |
|
83 | + * @param int $sleep time |
|
84 | + */ |
|
85 | + public function setSleepTime($sleep) |
|
86 | + { |
|
87 | + $this->sleep = $sleep; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get the number of seconds to sleep for during a restart. |
|
92 | - * |
|
93 | - * @return int |
|
94 | - */ |
|
95 | - public function getSleepTime() |
|
96 | - { |
|
97 | - return $this->sleep; |
|
98 | - } |
|
90 | + /** |
|
91 | + * Get the number of seconds to sleep for during a restart. |
|
92 | + * |
|
93 | + * @return int |
|
94 | + */ |
|
95 | + public function getSleepTime() |
|
96 | + { |
|
97 | + return $this->sleep; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Invoked immediately before the Message is sent. |
|
102 | - */ |
|
103 | - public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
104 | - { |
|
105 | - } |
|
100 | + /** |
|
101 | + * Invoked immediately before the Message is sent. |
|
102 | + */ |
|
103 | + public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
104 | + { |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Invoked immediately after the Message is sent. |
|
109 | - */ |
|
110 | - public function sendPerformed(Swift_Events_SendEvent $evt) |
|
111 | - { |
|
112 | - ++$this->counter; |
|
113 | - if ($this->counter >= $this->threshold) { |
|
114 | - $transport = $evt->getTransport(); |
|
115 | - $transport->stop(); |
|
116 | - if ($this->sleep) { |
|
117 | - $this->sleep($this->sleep); |
|
118 | - } |
|
119 | - $transport->start(); |
|
120 | - $this->counter = 0; |
|
121 | - } |
|
122 | - } |
|
107 | + /** |
|
108 | + * Invoked immediately after the Message is sent. |
|
109 | + */ |
|
110 | + public function sendPerformed(Swift_Events_SendEvent $evt) |
|
111 | + { |
|
112 | + ++$this->counter; |
|
113 | + if ($this->counter >= $this->threshold) { |
|
114 | + $transport = $evt->getTransport(); |
|
115 | + $transport->stop(); |
|
116 | + if ($this->sleep) { |
|
117 | + $this->sleep($this->sleep); |
|
118 | + } |
|
119 | + $transport->start(); |
|
120 | + $this->counter = 0; |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Sleep for $seconds. |
|
126 | - * |
|
127 | - * @param int $seconds |
|
128 | - */ |
|
129 | - public function sleep($seconds) |
|
130 | - { |
|
131 | - if (isset($this->sleeper)) { |
|
132 | - $this->sleeper->sleep($seconds); |
|
133 | - } else { |
|
134 | - sleep($seconds); |
|
135 | - } |
|
136 | - } |
|
124 | + /** |
|
125 | + * Sleep for $seconds. |
|
126 | + * |
|
127 | + * @param int $seconds |
|
128 | + */ |
|
129 | + public function sleep($seconds) |
|
130 | + { |
|
131 | + if (isset($this->sleeper)) { |
|
132 | + $this->sleeper->sleep($seconds); |
|
133 | + } else { |
|
134 | + sleep($seconds); |
|
135 | + } |
|
136 | + } |
|
137 | 137 | } |
@@ -15,228 +15,228 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeListener, Swift_Plugins_Pop_Pop3Connection |
17 | 17 | { |
18 | - /** A delegate connection to use (mostly a test hook) */ |
|
19 | - private $connection; |
|
20 | - |
|
21 | - /** Hostname of the POP3 server */ |
|
22 | - private $host; |
|
23 | - |
|
24 | - /** Port number to connect on */ |
|
25 | - private $port; |
|
26 | - |
|
27 | - /** Encryption type to use (if any) */ |
|
28 | - private $crypto; |
|
29 | - |
|
30 | - /** Username to use (if any) */ |
|
31 | - private $username; |
|
32 | - |
|
33 | - /** Password to use (if any) */ |
|
34 | - private $password; |
|
35 | - |
|
36 | - /** Established connection via TCP socket */ |
|
37 | - private $socket; |
|
38 | - |
|
39 | - /** Connect timeout in seconds */ |
|
40 | - private $timeout = 10; |
|
41 | - |
|
42 | - /** SMTP Transport to bind to */ |
|
43 | - private $transport; |
|
44 | - |
|
45 | - /** |
|
46 | - * Create a new PopBeforeSmtpPlugin for $host and $port. |
|
47 | - * |
|
48 | - * @param string $host Hostname or IP. Literal IPv6 addresses should be |
|
49 | - * wrapped in square brackets. |
|
50 | - * @param int $port |
|
51 | - * @param string $crypto as "tls" or "ssl" |
|
52 | - */ |
|
53 | - public function __construct($host, $port = 110, $crypto = null) |
|
54 | - { |
|
55 | - $this->host = $host; |
|
56 | - $this->port = $port; |
|
57 | - $this->crypto = $crypto; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Set a Pop3Connection to delegate to instead of connecting directly. |
|
62 | - * |
|
63 | - * @return $this |
|
64 | - */ |
|
65 | - public function setConnection(Swift_Plugins_Pop_Pop3Connection $connection) |
|
66 | - { |
|
67 | - $this->connection = $connection; |
|
68 | - |
|
69 | - return $this; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Bind this plugin to a specific SMTP transport instance. |
|
74 | - */ |
|
75 | - public function bindSmtp(Swift_Transport $smtp) |
|
76 | - { |
|
77 | - $this->transport = $smtp; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Set the connection timeout in seconds (default 10). |
|
82 | - * |
|
83 | - * @param int $timeout |
|
84 | - * |
|
85 | - * @return $this |
|
86 | - */ |
|
87 | - public function setTimeout($timeout) |
|
88 | - { |
|
89 | - $this->timeout = (int) $timeout; |
|
90 | - |
|
91 | - return $this; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the username to use when connecting (if needed). |
|
96 | - * |
|
97 | - * @param string $username |
|
98 | - * |
|
99 | - * @return $this |
|
100 | - */ |
|
101 | - public function setUsername($username) |
|
102 | - { |
|
103 | - $this->username = $username; |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Set the password to use when connecting (if needed). |
|
110 | - * |
|
111 | - * @param string $password |
|
112 | - * |
|
113 | - * @return $this |
|
114 | - */ |
|
115 | - public function setPassword($password) |
|
116 | - { |
|
117 | - $this->password = $password; |
|
118 | - |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Connect to the POP3 host and authenticate. |
|
124 | - * |
|
125 | - * @throws Swift_Plugins_Pop_Pop3Exception if connection fails |
|
126 | - */ |
|
127 | - public function connect() |
|
128 | - { |
|
129 | - if (isset($this->connection)) { |
|
130 | - $this->connection->connect(); |
|
131 | - } else { |
|
132 | - if (!isset($this->socket)) { |
|
133 | - if (!$socket = fsockopen( |
|
134 | - $this->getHostString(), $this->port, $errno, $errstr, $this->timeout)) { |
|
135 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]: %s', $this->host, $errstr)); |
|
136 | - } |
|
137 | - $this->socket = $socket; |
|
138 | - |
|
139 | - if (false === $greeting = fgets($this->socket)) { |
|
140 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]', trim($greeting ?? ''))); |
|
141 | - } |
|
142 | - |
|
143 | - $this->assertOk($greeting); |
|
144 | - |
|
145 | - if ($this->username) { |
|
146 | - $this->command(sprintf("USER %s\r\n", $this->username)); |
|
147 | - $this->command(sprintf("PASS %s\r\n", $this->password)); |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Disconnect from the POP3 host. |
|
155 | - */ |
|
156 | - public function disconnect() |
|
157 | - { |
|
158 | - if (isset($this->connection)) { |
|
159 | - $this->connection->disconnect(); |
|
160 | - } else { |
|
161 | - $this->command("QUIT\r\n"); |
|
162 | - if (!fclose($this->socket)) { |
|
163 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 host [%s] connection could not be stopped', $this->host)); |
|
164 | - } |
|
165 | - $this->socket = null; |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Invoked just before a Transport is started. |
|
171 | - */ |
|
172 | - public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) |
|
173 | - { |
|
174 | - if (isset($this->transport)) { |
|
175 | - if ($this->transport !== $evt->getTransport()) { |
|
176 | - return; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $this->connect(); |
|
181 | - $this->disconnect(); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Not used. |
|
186 | - */ |
|
187 | - public function transportStarted(Swift_Events_TransportChangeEvent $evt) |
|
188 | - { |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Not used. |
|
193 | - */ |
|
194 | - public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) |
|
195 | - { |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Not used. |
|
200 | - */ |
|
201 | - public function transportStopped(Swift_Events_TransportChangeEvent $evt) |
|
202 | - { |
|
203 | - } |
|
204 | - |
|
205 | - private function command($command) |
|
206 | - { |
|
207 | - if (!fwrite($this->socket, $command)) { |
|
208 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to write command [%s] to POP3 host', trim($command ?? ''))); |
|
209 | - } |
|
210 | - |
|
211 | - if (false === $response = fgets($this->socket)) { |
|
212 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to read from POP3 host after command [%s]', trim($command ?? ''))); |
|
213 | - } |
|
214 | - |
|
215 | - $this->assertOk($response); |
|
216 | - |
|
217 | - return $response; |
|
218 | - } |
|
219 | - |
|
220 | - private function assertOk($response) |
|
221 | - { |
|
222 | - if ('+OK' != substr($response, 0, 3)) { |
|
223 | - throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 command failed [%s]', trim($response ?? ''))); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - private function getHostString() |
|
228 | - { |
|
229 | - $host = $this->host; |
|
230 | - switch (strtolower($this->crypto ?? '')) { |
|
231 | - case 'ssl': |
|
232 | - $host = 'ssl://'.$host; |
|
233 | - break; |
|
234 | - |
|
235 | - case 'tls': |
|
236 | - $host = 'tls://'.$host; |
|
237 | - break; |
|
238 | - } |
|
239 | - |
|
240 | - return $host; |
|
241 | - } |
|
18 | + /** A delegate connection to use (mostly a test hook) */ |
|
19 | + private $connection; |
|
20 | + |
|
21 | + /** Hostname of the POP3 server */ |
|
22 | + private $host; |
|
23 | + |
|
24 | + /** Port number to connect on */ |
|
25 | + private $port; |
|
26 | + |
|
27 | + /** Encryption type to use (if any) */ |
|
28 | + private $crypto; |
|
29 | + |
|
30 | + /** Username to use (if any) */ |
|
31 | + private $username; |
|
32 | + |
|
33 | + /** Password to use (if any) */ |
|
34 | + private $password; |
|
35 | + |
|
36 | + /** Established connection via TCP socket */ |
|
37 | + private $socket; |
|
38 | + |
|
39 | + /** Connect timeout in seconds */ |
|
40 | + private $timeout = 10; |
|
41 | + |
|
42 | + /** SMTP Transport to bind to */ |
|
43 | + private $transport; |
|
44 | + |
|
45 | + /** |
|
46 | + * Create a new PopBeforeSmtpPlugin for $host and $port. |
|
47 | + * |
|
48 | + * @param string $host Hostname or IP. Literal IPv6 addresses should be |
|
49 | + * wrapped in square brackets. |
|
50 | + * @param int $port |
|
51 | + * @param string $crypto as "tls" or "ssl" |
|
52 | + */ |
|
53 | + public function __construct($host, $port = 110, $crypto = null) |
|
54 | + { |
|
55 | + $this->host = $host; |
|
56 | + $this->port = $port; |
|
57 | + $this->crypto = $crypto; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Set a Pop3Connection to delegate to instead of connecting directly. |
|
62 | + * |
|
63 | + * @return $this |
|
64 | + */ |
|
65 | + public function setConnection(Swift_Plugins_Pop_Pop3Connection $connection) |
|
66 | + { |
|
67 | + $this->connection = $connection; |
|
68 | + |
|
69 | + return $this; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Bind this plugin to a specific SMTP transport instance. |
|
74 | + */ |
|
75 | + public function bindSmtp(Swift_Transport $smtp) |
|
76 | + { |
|
77 | + $this->transport = $smtp; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Set the connection timeout in seconds (default 10). |
|
82 | + * |
|
83 | + * @param int $timeout |
|
84 | + * |
|
85 | + * @return $this |
|
86 | + */ |
|
87 | + public function setTimeout($timeout) |
|
88 | + { |
|
89 | + $this->timeout = (int) $timeout; |
|
90 | + |
|
91 | + return $this; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the username to use when connecting (if needed). |
|
96 | + * |
|
97 | + * @param string $username |
|
98 | + * |
|
99 | + * @return $this |
|
100 | + */ |
|
101 | + public function setUsername($username) |
|
102 | + { |
|
103 | + $this->username = $username; |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Set the password to use when connecting (if needed). |
|
110 | + * |
|
111 | + * @param string $password |
|
112 | + * |
|
113 | + * @return $this |
|
114 | + */ |
|
115 | + public function setPassword($password) |
|
116 | + { |
|
117 | + $this->password = $password; |
|
118 | + |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Connect to the POP3 host and authenticate. |
|
124 | + * |
|
125 | + * @throws Swift_Plugins_Pop_Pop3Exception if connection fails |
|
126 | + */ |
|
127 | + public function connect() |
|
128 | + { |
|
129 | + if (isset($this->connection)) { |
|
130 | + $this->connection->connect(); |
|
131 | + } else { |
|
132 | + if (!isset($this->socket)) { |
|
133 | + if (!$socket = fsockopen( |
|
134 | + $this->getHostString(), $this->port, $errno, $errstr, $this->timeout)) { |
|
135 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]: %s', $this->host, $errstr)); |
|
136 | + } |
|
137 | + $this->socket = $socket; |
|
138 | + |
|
139 | + if (false === $greeting = fgets($this->socket)) { |
|
140 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]', trim($greeting ?? ''))); |
|
141 | + } |
|
142 | + |
|
143 | + $this->assertOk($greeting); |
|
144 | + |
|
145 | + if ($this->username) { |
|
146 | + $this->command(sprintf("USER %s\r\n", $this->username)); |
|
147 | + $this->command(sprintf("PASS %s\r\n", $this->password)); |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Disconnect from the POP3 host. |
|
155 | + */ |
|
156 | + public function disconnect() |
|
157 | + { |
|
158 | + if (isset($this->connection)) { |
|
159 | + $this->connection->disconnect(); |
|
160 | + } else { |
|
161 | + $this->command("QUIT\r\n"); |
|
162 | + if (!fclose($this->socket)) { |
|
163 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 host [%s] connection could not be stopped', $this->host)); |
|
164 | + } |
|
165 | + $this->socket = null; |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Invoked just before a Transport is started. |
|
171 | + */ |
|
172 | + public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) |
|
173 | + { |
|
174 | + if (isset($this->transport)) { |
|
175 | + if ($this->transport !== $evt->getTransport()) { |
|
176 | + return; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $this->connect(); |
|
181 | + $this->disconnect(); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Not used. |
|
186 | + */ |
|
187 | + public function transportStarted(Swift_Events_TransportChangeEvent $evt) |
|
188 | + { |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Not used. |
|
193 | + */ |
|
194 | + public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) |
|
195 | + { |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Not used. |
|
200 | + */ |
|
201 | + public function transportStopped(Swift_Events_TransportChangeEvent $evt) |
|
202 | + { |
|
203 | + } |
|
204 | + |
|
205 | + private function command($command) |
|
206 | + { |
|
207 | + if (!fwrite($this->socket, $command)) { |
|
208 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to write command [%s] to POP3 host', trim($command ?? ''))); |
|
209 | + } |
|
210 | + |
|
211 | + if (false === $response = fgets($this->socket)) { |
|
212 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to read from POP3 host after command [%s]', trim($command ?? ''))); |
|
213 | + } |
|
214 | + |
|
215 | + $this->assertOk($response); |
|
216 | + |
|
217 | + return $response; |
|
218 | + } |
|
219 | + |
|
220 | + private function assertOk($response) |
|
221 | + { |
|
222 | + if ('+OK' != substr($response, 0, 3)) { |
|
223 | + throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 command failed [%s]', trim($response ?? ''))); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + private function getHostString() |
|
228 | + { |
|
229 | + $host = $this->host; |
|
230 | + switch (strtolower($this->crypto ?? '')) { |
|
231 | + case 'ssl': |
|
232 | + $host = 'ssl://'.$host; |
|
233 | + break; |
|
234 | + |
|
235 | + case 'tls': |
|
236 | + $host = 'tls://'.$host; |
|
237 | + break; |
|
238 | + } |
|
239 | + |
|
240 | + return $host; |
|
241 | + } |
|
242 | 242 | } |
@@ -15,17 +15,17 @@ |
||
15 | 15 | */ |
16 | 16 | interface Swift_Plugins_Reporter |
17 | 17 | { |
18 | - /** The recipient was accepted for delivery */ |
|
19 | - const RESULT_PASS = 0x01; |
|
18 | + /** The recipient was accepted for delivery */ |
|
19 | + const RESULT_PASS = 0x01; |
|
20 | 20 | |
21 | - /** The recipient could not be accepted */ |
|
22 | - const RESULT_FAIL = 0x10; |
|
21 | + /** The recipient could not be accepted */ |
|
22 | + const RESULT_FAIL = 0x10; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Notifies this ReportNotifier that $address failed or succeeded. |
|
26 | - * |
|
27 | - * @param string $address |
|
28 | - * @param int $result from {@link RESULT_PASS, RESULT_FAIL} |
|
29 | - */ |
|
30 | - public function notify(Swift_Mime_SimpleMessage $message, $address, $result); |
|
24 | + /** |
|
25 | + * Notifies this ReportNotifier that $address failed or succeeded. |
|
26 | + * |
|
27 | + * @param string $address |
|
28 | + * @param int $result from {@link RESULT_PASS, RESULT_FAIL} |
|
29 | + */ |
|
30 | + public function notify(Swift_Mime_SimpleMessage $message, $address, $result); |
|
31 | 31 | } |
@@ -15,13 +15,13 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_DependencyException extends Swift_SwiftException |
17 | 17 | { |
18 | - /** |
|
19 | - * Create a new DependencyException with $message. |
|
20 | - * |
|
21 | - * @param string $message |
|
22 | - */ |
|
23 | - public function __construct($message) |
|
24 | - { |
|
25 | - parent::__construct($message); |
|
26 | - } |
|
18 | + /** |
|
19 | + * Create a new DependencyException with $message. |
|
20 | + * |
|
21 | + * @param string $message |
|
22 | + */ |
|
23 | + public function __construct($message) |
|
24 | + { |
|
25 | + parent::__construct($message); |
|
26 | + } |
|
27 | 27 | } |
@@ -15,110 +15,110 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift_CharacterReaderFactory |
17 | 17 | { |
18 | - /** |
|
19 | - * A map of charset patterns to their implementation classes. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - private static $map = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * Factories which have already been loaded. |
|
27 | - * |
|
28 | - * @var Swift_CharacterReaderFactory[] |
|
29 | - */ |
|
30 | - private static $loaded = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * Creates a new CharacterReaderFactory. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->init(); |
|
38 | - } |
|
39 | - |
|
40 | - public function __wakeup() |
|
41 | - { |
|
42 | - $this->init(); |
|
43 | - } |
|
44 | - |
|
45 | - public function init() |
|
46 | - { |
|
47 | - if (\count(self::$map) > 0) { |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - $prefix = 'Swift_CharacterReader_'; |
|
52 | - |
|
53 | - $singleByte = [ |
|
54 | - 'class' => $prefix.'GenericFixedWidthReader', |
|
55 | - 'constructor' => [1], |
|
56 | - ]; |
|
57 | - |
|
58 | - $doubleByte = [ |
|
59 | - 'class' => $prefix.'GenericFixedWidthReader', |
|
60 | - 'constructor' => [2], |
|
61 | - ]; |
|
62 | - |
|
63 | - $fourBytes = [ |
|
64 | - 'class' => $prefix.'GenericFixedWidthReader', |
|
65 | - 'constructor' => [4], |
|
66 | - ]; |
|
67 | - |
|
68 | - // Utf-8 |
|
69 | - self::$map['utf-?8'] = [ |
|
70 | - 'class' => $prefix.'Utf8Reader', |
|
71 | - 'constructor' => [], |
|
72 | - ]; |
|
73 | - |
|
74 | - //7-8 bit charsets |
|
75 | - self::$map['(us-)?ascii'] = $singleByte; |
|
76 | - self::$map['(iso|iec)-?8859-?[0-9]+'] = $singleByte; |
|
77 | - self::$map['windows-?125[0-9]'] = $singleByte; |
|
78 | - self::$map['cp-?[0-9]+'] = $singleByte; |
|
79 | - self::$map['ansi'] = $singleByte; |
|
80 | - self::$map['macintosh'] = $singleByte; |
|
81 | - self::$map['koi-?7'] = $singleByte; |
|
82 | - self::$map['koi-?8-?.+'] = $singleByte; |
|
83 | - self::$map['mik'] = $singleByte; |
|
84 | - self::$map['(cork|t1)'] = $singleByte; |
|
85 | - self::$map['v?iscii'] = $singleByte; |
|
86 | - |
|
87 | - //16 bits |
|
88 | - self::$map['(ucs-?2|utf-?16)'] = $doubleByte; |
|
89 | - |
|
90 | - //32 bits |
|
91 | - self::$map['(ucs-?4|utf-?32)'] = $fourBytes; |
|
92 | - |
|
93 | - // Fallback |
|
94 | - self::$map['.*'] = $singleByte; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns a CharacterReader suitable for the charset applied. |
|
99 | - * |
|
100 | - * @param string $charset |
|
101 | - * |
|
102 | - * @return Swift_CharacterReader |
|
103 | - */ |
|
104 | - public function getReaderFor($charset) |
|
105 | - { |
|
106 | - $charset = strtolower(trim($charset ?? '')); |
|
107 | - foreach (self::$map as $pattern => $spec) { |
|
108 | - $re = '/^'.$pattern.'$/D'; |
|
109 | - if (preg_match($re, $charset)) { |
|
110 | - if (!\array_key_exists($pattern, self::$loaded)) { |
|
111 | - $reflector = new ReflectionClass($spec['class']); |
|
112 | - if ($reflector->getConstructor()) { |
|
113 | - $reader = $reflector->newInstanceArgs($spec['constructor']); |
|
114 | - } else { |
|
115 | - $reader = $reflector->newInstance(); |
|
116 | - } |
|
117 | - self::$loaded[$pattern] = $reader; |
|
118 | - } |
|
119 | - |
|
120 | - return self::$loaded[$pattern]; |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
18 | + /** |
|
19 | + * A map of charset patterns to their implementation classes. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + private static $map = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * Factories which have already been loaded. |
|
27 | + * |
|
28 | + * @var Swift_CharacterReaderFactory[] |
|
29 | + */ |
|
30 | + private static $loaded = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * Creates a new CharacterReaderFactory. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->init(); |
|
38 | + } |
|
39 | + |
|
40 | + public function __wakeup() |
|
41 | + { |
|
42 | + $this->init(); |
|
43 | + } |
|
44 | + |
|
45 | + public function init() |
|
46 | + { |
|
47 | + if (\count(self::$map) > 0) { |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + $prefix = 'Swift_CharacterReader_'; |
|
52 | + |
|
53 | + $singleByte = [ |
|
54 | + 'class' => $prefix.'GenericFixedWidthReader', |
|
55 | + 'constructor' => [1], |
|
56 | + ]; |
|
57 | + |
|
58 | + $doubleByte = [ |
|
59 | + 'class' => $prefix.'GenericFixedWidthReader', |
|
60 | + 'constructor' => [2], |
|
61 | + ]; |
|
62 | + |
|
63 | + $fourBytes = [ |
|
64 | + 'class' => $prefix.'GenericFixedWidthReader', |
|
65 | + 'constructor' => [4], |
|
66 | + ]; |
|
67 | + |
|
68 | + // Utf-8 |
|
69 | + self::$map['utf-?8'] = [ |
|
70 | + 'class' => $prefix.'Utf8Reader', |
|
71 | + 'constructor' => [], |
|
72 | + ]; |
|
73 | + |
|
74 | + //7-8 bit charsets |
|
75 | + self::$map['(us-)?ascii'] = $singleByte; |
|
76 | + self::$map['(iso|iec)-?8859-?[0-9]+'] = $singleByte; |
|
77 | + self::$map['windows-?125[0-9]'] = $singleByte; |
|
78 | + self::$map['cp-?[0-9]+'] = $singleByte; |
|
79 | + self::$map['ansi'] = $singleByte; |
|
80 | + self::$map['macintosh'] = $singleByte; |
|
81 | + self::$map['koi-?7'] = $singleByte; |
|
82 | + self::$map['koi-?8-?.+'] = $singleByte; |
|
83 | + self::$map['mik'] = $singleByte; |
|
84 | + self::$map['(cork|t1)'] = $singleByte; |
|
85 | + self::$map['v?iscii'] = $singleByte; |
|
86 | + |
|
87 | + //16 bits |
|
88 | + self::$map['(ucs-?2|utf-?16)'] = $doubleByte; |
|
89 | + |
|
90 | + //32 bits |
|
91 | + self::$map['(ucs-?4|utf-?32)'] = $fourBytes; |
|
92 | + |
|
93 | + // Fallback |
|
94 | + self::$map['.*'] = $singleByte; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns a CharacterReader suitable for the charset applied. |
|
99 | + * |
|
100 | + * @param string $charset |
|
101 | + * |
|
102 | + * @return Swift_CharacterReader |
|
103 | + */ |
|
104 | + public function getReaderFor($charset) |
|
105 | + { |
|
106 | + $charset = strtolower(trim($charset ?? '')); |
|
107 | + foreach (self::$map as $pattern => $spec) { |
|
108 | + $re = '/^'.$pattern.'$/D'; |
|
109 | + if (preg_match($re, $charset)) { |
|
110 | + if (!\array_key_exists($pattern, self::$loaded)) { |
|
111 | + $reflector = new ReflectionClass($spec['class']); |
|
112 | + if ($reflector->getConstructor()) { |
|
113 | + $reader = $reflector->newInstanceArgs($spec['constructor']); |
|
114 | + } else { |
|
115 | + $reader = $reflector->newInstance(); |
|
116 | + } |
|
117 | + self::$loaded[$pattern] = $reader; |
|
118 | + } |
|
119 | + |
|
120 | + return self::$loaded[$pattern]; |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | 124 | } |
@@ -15,62 +15,62 @@ |
||
15 | 15 | */ |
16 | 16 | interface Swift_Transport |
17 | 17 | { |
18 | - /** |
|
19 | - * Test if this Transport mechanism has started. |
|
20 | - * |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - public function isStarted(); |
|
18 | + /** |
|
19 | + * Test if this Transport mechanism has started. |
|
20 | + * |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + public function isStarted(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Start this Transport mechanism. |
|
27 | - */ |
|
28 | - public function start(); |
|
25 | + /** |
|
26 | + * Start this Transport mechanism. |
|
27 | + */ |
|
28 | + public function start(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Stop this Transport mechanism. |
|
32 | - */ |
|
33 | - public function stop(); |
|
30 | + /** |
|
31 | + * Stop this Transport mechanism. |
|
32 | + */ |
|
33 | + public function stop(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Check if this Transport mechanism is alive. |
|
37 | - * |
|
38 | - * If a Transport mechanism session is no longer functional, the method |
|
39 | - * returns FALSE. It is the responsibility of the developer to handle this |
|
40 | - * case and restart the Transport mechanism manually. |
|
41 | - * |
|
42 | - * @example |
|
43 | - * |
|
44 | - * if (!$transport->ping()) { |
|
45 | - * $transport->stop(); |
|
46 | - * $transport->start(); |
|
47 | - * } |
|
48 | - * |
|
49 | - * The Transport mechanism will be started, if it is not already. |
|
50 | - * |
|
51 | - * It is undefined if the Transport mechanism attempts to restart as long as |
|
52 | - * the return value reflects whether the mechanism is now functional. |
|
53 | - * |
|
54 | - * @return bool TRUE if the transport is alive |
|
55 | - */ |
|
56 | - public function ping(); |
|
35 | + /** |
|
36 | + * Check if this Transport mechanism is alive. |
|
37 | + * |
|
38 | + * If a Transport mechanism session is no longer functional, the method |
|
39 | + * returns FALSE. It is the responsibility of the developer to handle this |
|
40 | + * case and restart the Transport mechanism manually. |
|
41 | + * |
|
42 | + * @example |
|
43 | + * |
|
44 | + * if (!$transport->ping()) { |
|
45 | + * $transport->stop(); |
|
46 | + * $transport->start(); |
|
47 | + * } |
|
48 | + * |
|
49 | + * The Transport mechanism will be started, if it is not already. |
|
50 | + * |
|
51 | + * It is undefined if the Transport mechanism attempts to restart as long as |
|
52 | + * the return value reflects whether the mechanism is now functional. |
|
53 | + * |
|
54 | + * @return bool TRUE if the transport is alive |
|
55 | + */ |
|
56 | + public function ping(); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Send the given Message. |
|
60 | - * |
|
61 | - * Recipient/sender data will be retrieved from the Message API. |
|
62 | - * The return value is the number of recipients who were accepted for delivery. |
|
63 | - * |
|
64 | - * This is the responsibility of the send method to start the transport if needed. |
|
65 | - * |
|
66 | - * @param string[] $failedRecipients An array of failures by-reference |
|
67 | - * |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null); |
|
58 | + /** |
|
59 | + * Send the given Message. |
|
60 | + * |
|
61 | + * Recipient/sender data will be retrieved from the Message API. |
|
62 | + * The return value is the number of recipients who were accepted for delivery. |
|
63 | + * |
|
64 | + * This is the responsibility of the send method to start the transport if needed. |
|
65 | + * |
|
66 | + * @param string[] $failedRecipients An array of failures by-reference |
|
67 | + * |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Register a plugin in the Transport. |
|
74 | - */ |
|
75 | - public function registerPlugin(Swift_Events_EventListener $plugin); |
|
72 | + /** |
|
73 | + * Register a plugin in the Transport. |
|
74 | + */ |
|
75 | + public function registerPlugin(Swift_Events_EventListener $plugin); |
|
76 | 76 | } |
@@ -15,49 +15,49 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class Swift_ConfigurableSpool implements Swift_Spool |
17 | 17 | { |
18 | - /** The maximum number of messages to send per flush */ |
|
19 | - private $message_limit; |
|
18 | + /** The maximum number of messages to send per flush */ |
|
19 | + private $message_limit; |
|
20 | 20 | |
21 | - /** The time limit per flush */ |
|
22 | - private $time_limit; |
|
21 | + /** The time limit per flush */ |
|
22 | + private $time_limit; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Sets the maximum number of messages to send per flush. |
|
26 | - * |
|
27 | - * @param int $limit |
|
28 | - */ |
|
29 | - public function setMessageLimit($limit) |
|
30 | - { |
|
31 | - $this->message_limit = (int) $limit; |
|
32 | - } |
|
24 | + /** |
|
25 | + * Sets the maximum number of messages to send per flush. |
|
26 | + * |
|
27 | + * @param int $limit |
|
28 | + */ |
|
29 | + public function setMessageLimit($limit) |
|
30 | + { |
|
31 | + $this->message_limit = (int) $limit; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Gets the maximum number of messages to send per flush. |
|
36 | - * |
|
37 | - * @return int The limit |
|
38 | - */ |
|
39 | - public function getMessageLimit() |
|
40 | - { |
|
41 | - return $this->message_limit; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Gets the maximum number of messages to send per flush. |
|
36 | + * |
|
37 | + * @return int The limit |
|
38 | + */ |
|
39 | + public function getMessageLimit() |
|
40 | + { |
|
41 | + return $this->message_limit; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Sets the time limit (in seconds) per flush. |
|
46 | - * |
|
47 | - * @param int $limit The limit |
|
48 | - */ |
|
49 | - public function setTimeLimit($limit) |
|
50 | - { |
|
51 | - $this->time_limit = (int) $limit; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Sets the time limit (in seconds) per flush. |
|
46 | + * |
|
47 | + * @param int $limit The limit |
|
48 | + */ |
|
49 | + public function setTimeLimit($limit) |
|
50 | + { |
|
51 | + $this->time_limit = (int) $limit; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Gets the time limit (in seconds) per flush. |
|
56 | - * |
|
57 | - * @return int The limit |
|
58 | - */ |
|
59 | - public function getTimeLimit() |
|
60 | - { |
|
61 | - return $this->time_limit; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Gets the time limit (in seconds) per flush. |
|
56 | + * |
|
57 | + * @return int The limit |
|
58 | + */ |
|
59 | + public function getTimeLimit() |
|
60 | + { |
|
61 | + return $this->time_limit; |
|
62 | + } |
|
63 | 63 | } |
@@ -15,50 +15,50 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Events_CommandEvent extends Swift_Events_EventObject |
17 | 17 | { |
18 | - /** |
|
19 | - * The command sent to the server. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $command; |
|
18 | + /** |
|
19 | + * The command sent to the server. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $command; |
|
24 | 24 | |
25 | - /** |
|
26 | - * An array of codes which a successful response will contain. |
|
27 | - * |
|
28 | - * @var int[] |
|
29 | - */ |
|
30 | - private $successCodes = []; |
|
25 | + /** |
|
26 | + * An array of codes which a successful response will contain. |
|
27 | + * |
|
28 | + * @var int[] |
|
29 | + */ |
|
30 | + private $successCodes = []; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Create a new CommandEvent for $source with $command. |
|
34 | - * |
|
35 | - * @param string $command |
|
36 | - * @param array $successCodes |
|
37 | - */ |
|
38 | - public function __construct(Swift_Transport $source, $command, $successCodes = []) |
|
39 | - { |
|
40 | - parent::__construct($source); |
|
41 | - $this->command = $command; |
|
42 | - $this->successCodes = $successCodes; |
|
43 | - } |
|
32 | + /** |
|
33 | + * Create a new CommandEvent for $source with $command. |
|
34 | + * |
|
35 | + * @param string $command |
|
36 | + * @param array $successCodes |
|
37 | + */ |
|
38 | + public function __construct(Swift_Transport $source, $command, $successCodes = []) |
|
39 | + { |
|
40 | + parent::__construct($source); |
|
41 | + $this->command = $command; |
|
42 | + $this->successCodes = $successCodes; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the command which was sent to the server. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getCommand() |
|
51 | - { |
|
52 | - return $this->command; |
|
53 | - } |
|
45 | + /** |
|
46 | + * Get the command which was sent to the server. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getCommand() |
|
51 | + { |
|
52 | + return $this->command; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the numeric response codes which indicate success for this command. |
|
57 | - * |
|
58 | - * @return int[] |
|
59 | - */ |
|
60 | - public function getSuccessCodes() |
|
61 | - { |
|
62 | - return $this->successCodes; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get the numeric response codes which indicate success for this command. |
|
57 | + * |
|
58 | + * @return int[] |
|
59 | + */ |
|
60 | + public function getSuccessCodes() |
|
61 | + { |
|
62 | + return $this->successCodes; |
|
63 | + } |
|
64 | 64 | } |