37 private $debug =
false;
39 private $state = self::ST_lookingForStartOfMail;
41 private $encoding =
'UTF-8';
64 $this->lax = ($lax ===
true);
75 $this->debug = ($debug ===
true);
86 $this->encoding = $encoding;
93 private function eos()
95 return ($this->p >= mb_strlen($this->s, $this->encoding));
102 private function eosNext()
104 return (($this->p + 1) >= mb_strlen($this->s, $this->encoding));
111 private function peek()
113 return mb_substr($this->s, $this->p, 1, $this->encoding);
118 private function next()
128 private function isSpace(
$c)
130 return preg_match(
'/^\s*$/u',
$c);
143 $this->state = self::ST_lookingForStartOfMail;
145 $addresses = array();
152 while (!$this->eos()) {
155 error_log(__METHOD__ .
" " . sprintf(
"(p=%s, state=%s) char='%s' {'%s', '%s'}%s", $this->p, $this->state,
$c, $mail, $name, ($this->esc) ?
' (ESC)' :
''));
164 switch ($this->state) {
165 case self::ST_lookingForStartOfMail:
171 $this->state = self::ST_end;
173 $this->state = self::ST_inMail;
175 } elseif ($this->isSpace(
$c) ||
$c ==
",") {
178 $this->state = self::ST_end;
183 $this->state = self::ST_inMail;
187 case self::ST_lookingForSeparator:
190 } elseif ($this->isSpace(
$c)) {
193 } elseif (
$c ==
",") {
194 $this->state = self::ST_lookingForStartOfMail;
206 $this->state = self::ST_end;
210 case self::ST_inMail:
214 } elseif (
$c ==
'"') {
215 $this->state = self::ST_inQuotedDisplayName;
216 } elseif (
$c ==
'<') {
217 $this->state = self::ST_inAngleMail;
218 } elseif (
$c ==
',' || $this->eosNext()) {
225 error_log(__METHOD__ .
" " . sprintf(
"Got {'%s'}", $mail));
227 $addresses[] =
new Address($mail);
230 if ($this->eosNext()) {
231 $this->state = self::ST_end;
233 $this->state = self::ST_lookingForStartOfMail;
241 case self::ST_inQuotedDisplayName:
245 } elseif (
$c ==
'"') {
246 $this->state = self::ST_inMail;
253 case self::ST_lookingForAngleMail:
256 } elseif ($this->isSpace(
$c)) {
259 } elseif (
$c ==
'<') {
260 $this->state = self::ST_inAngleMail;
266 $this->state = self::ST_lookingForSeparator;
274 case self::ST_inAngleMail:
279 error_log(__METHOD__ .
" " . sprintf(
"Got {'%s', '%s'}", $mail, $name));
281 $addresses[] =
new Address($mail, $name);
284 if ($this->eosNext()) {
285 $this->state = self::ST_end;
287 $this->state = self::ST_lookingForSeparator;
289 } elseif (
$c ==
'<') {
294 $this->state = self::ST_lookingForSeparator;
311 if (!$this->lax && $this->state != self::ST_end) {
const ST_inQuotedDisplayName
Exception class use exceptionCode to identifiy correctly exception.
const ST_lookingForStartOfMail
const ST_lookingForSeparator
setEncoding($encoding= 'UTF-8')
const ST_lookingForAngleMail