28 if (is_array($string)) {
30 foreach ($string as $idx => $value) {
40 $pos = strpos($string,
'=?');
47 $result .= substr($string, 0, $pos);
48 $string = substr($string, $pos);
50 $pos0 = strpos($string,
'?=');
51 if ($pos0 === FALSE) {
56 $pos1 = strpos($string,
' ');
57 if ($pos1 !== FALSE AND $pos1 < $pos0) {
58 $result .= substr($string, 0, 2);
59 $string = substr($string, 2);
62 $pos1 = strpos($string,
"\t");
63 if ($pos1 !== FALSE AND $pos1 < $pos0) {
64 $result .= substr($string, 0, 2);
65 $string = substr($string, 2);
68 $pos1 = strpos($string,
'?', 2);
71 $result .= substr($string, 0, 2);
72 $string = substr($string, 2);
75 $charset = substr($string, 2, $pos1-2);
76 $pos2 = strpos($string,
'?', $pos1+1);
79 $result .= substr($string, 0, 2);
80 $string = substr($string, 2);
83 $encoding = substr($string, $pos1+1, $pos2 - $pos1 - 1);
84 $text = substr($string, $pos2+1, $pos0 - $pos2 -1);
85 $string = substr($string, $pos0+2);
86 switch (strtolower($encoding)) {
88 $text = base64_decode($text);
91 $text = quoted_printable_decode($text);
95 $text =
'=?' . $charset .
'?' . $encoding .
'?=';
98 $text = iconv($charset,
'UTF-8', $text);
122 $this->header = $str;
131 static $atext =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-/=?^_`{}|~";
145 while ($this->header[0] ==
'.') {
157 static $ttext =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&'*+-^_`{}|~.";
168 if ($this->header[0] ==
'"') {
171 while (($char = $this->
get_char()) !=
'"' && $char !== FALSE) {
191 while (!empty($this->header) && strpos($chars, $this->header[0]) !== FALSE) {
202 while (ctype_space($this->header[0])) {
203 $this->header = substr($this->header, 1);
213 while (ctype_space($char = $this->header[0]) || $char ==
'(') {
229 while (($char = $this->
get_char()) !=
')') {
233 elseif ($char ==
'(') {
245 if (!empty($this->header)) {
246 $char = $this->header[0];
247 $this->header = substr($this->header, 1);
291 if (isset($this->
headers[$name])) {
320 if (is_array($name)) {
322 foreach ($name as $key => $data) {
337 $header = $this->
header($name);
338 if (is_array($header)) {
339 foreach($header as $key => $data) {
353 if (is_array($header_value)) {
355 foreach ($header_value as $value) {
360 $header_value = trim($header_value);
362 if (isset($this->
headers[$header_name])) {
363 if (!is_array($this->
headers[$header_name])) {
364 $this->
headers[$header_name] = array($this->
headers[$header_name]);
366 $this->
headers[$header_name][] = $header_value;
369 $this->
headers[$header_name] = $header_value;
378 $this->
headers[$header_name] = $header_value;
403 if (is_string($msg)) {
404 $break = strpos($msg,
"\n\n");
405 $this->
headers = substr($msg, 0, $break+1);
406 $this->
body = substr($msg, $break+2);
429 $charset =
'ISO-8859-1';
438 if(!empty($charset)){
439 $this->
addHeader(
'XX-HeaderCharset', $charset);
442 $colon = strpos($header,
': ');
444 $header_name = substr($header, 0, $colon);
445 $header_value = substr($header, $colon+2);
447 switch ($header_name) {
449 $header_value = str_replace(
"\t",
" ", $header_value);
450 $header_value = str_replace(
'><',
'> <', $header_value);
451 $header_value = explode(
' ', $header_value);
459 while( FALSE !== ($posc = strpos($header_value,
',', $pos))){
460 $pos1 = strpos($header_value,
'(', $pos);
461 $pos2 = strpos($header_value,
'<', $pos);
462 $pos3 = strpos($header_value,
'\\', $pos);
463 $pos4 = strpos($header_value,
'"', $pos);
464 if($pos1 === FALSE) $pos1 = $posc;
465 if($pos2 === FALSE) $pos2 = $posc;
466 if($pos3 === FALSE) $pos3 = $posc;
467 if($pos4 === FALSE) $pos4 = $posc;
468 $pos1 = min($pos1, $pos2, $pos3, $pos4);
470 switch($header_value[$pos1]) {
472 $pos = strpos($header_value,
')', $pos1);
473 if(!$pos) $pos = $pos1+1;
476 $pos = strpos($header_value,
'>', $pos1);
477 if(!$pos) $pos = $pos1+1;
483 $pos = strpos($header_value,
'"', $pos1+1);
484 if(!$pos) $pos = $pos1+1;
487 $this->
logError(
'Error Processing Header: ' . $header_value);
493 $value = substr($header_value, 0, $posc);
496 $header_value = substr($header_value, $posc+1);
503 $this->
addHeader($header_name, $header_value);
527 if (isset($this->
headers[
'Content-Transfer-Encoding'])) {
529 $cte = $header->get_atom();
531 switch (strtolower($cte)) {
532 case 'quoted-printable':
533 $this->
body = quoted_printable_decode($this->
body);
536 $this->
body = base64_decode($this->
body);
539 $this->
logError(
'Unknown CTE "@cte"', array(
'@cte' => $cte));
551 if (isset($this->
headers[
'Content-Type'])) {
553 $ct = $header->get_atom();
554 $pos = strpos($ct,
'/');
556 $this->
logError(
'Bad Content-Type Format', $ct);
559 $type = substr($ct, 0, $pos);
560 $subtype = substr($ct, $pos+1);
564 while ($parm = $header->get_token()) {
565 $char = $header->get_char();
566 $value = $header->get_value();
567 $parms[$parm] = $value;
569 switch (strtolower($type)) {
571 $bodies = explode(
"--" . $parms[
'boundary'], $this->
body);
572 $this->
body = array();
573 foreach ($bodies as
$body) {
574 if (!empty($body) && $body[0] ==
"\n" && strlen($body) > 2) {
580 if ($subtype ==
'rfc822') {
587 if (isset($parms[
'charset'])) {
588 $charset = strtoupper($parms[
'charset']);
589 if ($charset ==
'US-ASCII') $charset =
'ASCII';
590 $encodings = mb_list_encodings();
591 $this->
body = mb_convert_encoding($this->
body,
'UTF-8', $charset);
596 $this->
logError(
'Unkown Content Type ' . $type .
' / ' . $subtype);
597 dpm(array($type, $subtype));
611 $pos = strpos($addr,
'<');
612 if ($pos !== FALSE) {
614 $pos1 = strpos($addr,
'>', $pos);
615 $email = substr($addr, $pos+1, $pos1-$pos-2);
617 $name = substr($addr, 0, $pos) . substr($addr, $pos1+1);
620 $name = substr($addr, $pos1+1);
624 $pos = strpos($addr,
'(');
625 if ($pos !== FALSE) {
626 $pos1 = strpos($addr,
')');
627 $name = substr($addr, $pos+1, $pos1-$pos-1);
629 $email = substr($addr, 0, $pos) . substr($addr, $pos1+1);
632 $email = substr($addr, $pos1+1);
641 return array(
'email' => trim($email),
'name' => trim($name));
645 while(FALSE !== ($pos = strpos($header,
'('))) {
646 $pos1 = strpos($header,
')', $pos);
648 $header = substr($header, 0, $pos) .
' ' . substr($header, $pos1+1);
652 $header = substr($header, 0, $pos);
664 dpm($str, NULL,
'error');
665 watchdog(
'MailinglistMessage', $str, $parms, WATCHDOG_ERROR);
689 if (is_string($msg)) {
691 $msg = str_replace(array(
"\n\r",
"\r\n",
"\r"),
"\n", $msg);
693 $rawmsg = @iconv(
'UTF-8//IGNORE',
'UTF-8', $msg);
695 if ($rawmsg != $msg) {
696 $rawmsg = iconv(
'ISO-8859-1//IGNORE',
'UTF-8', $msg);
697 $charset =
'ISO-8859-1';
699 $this->raw_message = $rawmsg;
700 parent::__construct($msg);
701 if(!empty($charset)){
702 $this->
setHeader(
'XX-RawCharset', $charset);
Interface MailinglistMessageInterface.
parseHeaders()
parseHeaders() Converts the headers member from a single text string with the contents of the part (o...
Class defining the contents of an e-mail message.
headerRaw($name)
headerRaw().
addHeader($header_name, $header_value)
Add a given header to the message, if header already exists, add as an array.
$headers
An array of the headers of the message part Header name is the index to the array.
$body
The body of the message, if it is a multi-part then it is an array of the various multi-parts...
body()
Return the body of the message.
setHeader($header_name, $header_value)
Set a header to a given value.
__construct($msg="")
__construct()
headerEmail($name)
Return header parsed as an email address into an array with indexes email and name.
parseBody()
parseBody()) converts text string in the body variable into a processed body For MIME type multipart...
mailinglist_message_rfc2047($string)
mailinglist_message_rfc2047()
headers()
Return array of all headers.
parseEmailAddr($addr)
Parse an Email address.
raw()
Get contents of raw message.
__construct($msg=NULL)
Build an message part.
logError($str, $parm=array())
logError()
MailinglistMessagePart A class to represent a piece of a email message.