Rfc822Header.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. /**
  3. * Rfc822Header.class.php
  4. *
  5. * Copyright (c) 2003-2004 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This contains functions needed to handle mime messages.
  9. *
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /**
  14. * input: header_string or array
  15. * @package squirrelmail
  16. */
  17. class Rfc822Header {
  18. var $date = -1,
  19. $subject = '',
  20. $from = array(),
  21. $sender = '',
  22. $reply_to = array(),
  23. $mail_followup_to = array(),
  24. $to = array(),
  25. $cc = array(),
  26. $bcc = array(),
  27. $in_reply_to = '',
  28. $message_id = '',
  29. $references = '',
  30. $mime = false,
  31. $content_type = '',
  32. $disposition = '',
  33. $xmailer = '',
  34. $priority = 3,
  35. $dnt = '',
  36. $encoding = '',
  37. $content_id = '',
  38. $content_desc = '',
  39. $mlist = array(),
  40. $more_headers = array(); /* only needed for constructing headers
  41. in smtp.php */
  42. function parseHeader($hdr) {
  43. if (is_array($hdr)) {
  44. $hdr = implode('', $hdr);
  45. }
  46. /* First we replace \r\n by \n and unfold the header */
  47. $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $hdr));
  48. /* Now we can make a new header array with */
  49. /* each element representing a headerline */
  50. $hdr = explode("\n" , $hdr);
  51. foreach ($hdr as $line) {
  52. $pos = strpos($line, ':');
  53. if ($pos > 0) {
  54. $field = substr($line, 0, $pos);
  55. if (!strstr($field,' ')) { /* valid field */
  56. $value = trim(substr($line, $pos+1));
  57. $this->parseField($field, $value);
  58. }
  59. }
  60. }
  61. if ($this->content_type == '') {
  62. $this->parseContentType('text/plain; charset=us-ascii');
  63. }
  64. }
  65. function stripComments($value) {
  66. $result = '';
  67. $cnt = strlen($value);
  68. for ($i = 0; $i < $cnt; ++$i) {
  69. switch ($value{$i}) {
  70. case '"':
  71. $result .= '"';
  72. while ((++$i < $cnt) && ($value{$i} != '"')) {
  73. if ($value{$i} == '\\') {
  74. $result .= '\\';
  75. ++$i;
  76. }
  77. $result .= $value{$i};
  78. }
  79. $result .= $value{$i};
  80. break;
  81. case '(':
  82. $depth = 1;
  83. while (($depth > 0) && (++$i < $cnt)) {
  84. switch($value{$i}) {
  85. case '\\':
  86. ++$i;
  87. break;
  88. case '(':
  89. ++$depth;
  90. break;
  91. case ')':
  92. --$depth;
  93. break;
  94. default:
  95. break;
  96. }
  97. }
  98. break;
  99. default:
  100. $result .= $value{$i};
  101. break;
  102. }
  103. }
  104. return $result;
  105. }
  106. function parseField($field, $value) {
  107. $field = strtolower($field);
  108. switch($field) {
  109. case 'date':
  110. $value = $this->stripComments($value);
  111. $d = strtr($value, array(' ' => ' '));
  112. $d = explode(' ', $d);
  113. $this->date = getTimeStamp($d);
  114. break;
  115. case 'subject':
  116. $this->subject = $value;
  117. break;
  118. case 'from':
  119. $this->from = $this->parseAddress($value,true);
  120. break;
  121. case 'sender':
  122. $this->sender = $this->parseAddress($value);
  123. break;
  124. case 'reply-to':
  125. $this->reply_to = $this->parseAddress($value, true);
  126. break;
  127. case 'mail-followup-to':
  128. $this->mail_followup_to = $this->parseAddress($value, true);
  129. break;
  130. case 'to':
  131. $this->to = $this->parseAddress($value, true);
  132. break;
  133. case 'cc':
  134. $this->cc = $this->parseAddress($value, true);
  135. break;
  136. case 'bcc':
  137. $this->bcc = $this->parseAddress($value, true);
  138. break;
  139. case 'in-reply-to':
  140. $this->in_reply_to = $value;
  141. break;
  142. case 'message-id':
  143. $value = $this->stripComments($value);
  144. $this->message_id = $value;
  145. break;
  146. case 'references':
  147. $value = $this->stripComments($value);
  148. $this->references = $value;
  149. break;
  150. case 'x-confirm-reading-to':
  151. case 'return-receipt-to':
  152. case 'disposition-notification-to':
  153. $value = $this->stripComments($value);
  154. $this->dnt = $this->parseAddress($value);
  155. break;
  156. case 'mime-version':
  157. $value = $this->stripComments($value);
  158. $value = str_replace(' ', '', $value);
  159. $this->mime = ($value == '1.0' ? true : $this->mime);
  160. break;
  161. case 'content-type':
  162. $value = $this->stripComments($value);
  163. $this->parseContentType($value);
  164. break;
  165. case 'content-disposition':
  166. $value = $this->stripComments($value);
  167. $this->parseDisposition($value);
  168. break;
  169. case 'content-transfer-encoding':
  170. $this->encoding = $value;
  171. break;
  172. case 'content-description':
  173. $this->content_desc = $value;
  174. break;
  175. case 'content-id':
  176. $value = $this->stripComments($value);
  177. $this->content_id = $value;
  178. break;
  179. case 'user-agent':
  180. case 'x-mailer':
  181. $this->xmailer = $value;
  182. break;
  183. case 'x-priority':
  184. $this->priority = $value;
  185. break;
  186. case 'list-post':
  187. $value = $this->stripComments($value);
  188. $this->mlist('post', $value);
  189. break;
  190. case 'list-reply':
  191. $value = $this->stripComments($value);
  192. $this->mlist('reply', $value);
  193. break;
  194. case 'list-subscribe':
  195. $value = $this->stripComments($value);
  196. $this->mlist('subscribe', $value);
  197. break;
  198. case 'list-unsubscribe':
  199. $value = $this->stripComments($value);
  200. $this->mlist('unsubscribe', $value);
  201. break;
  202. case 'list-archive':
  203. $value = $this->stripComments($value);
  204. $this->mlist('archive', $value);
  205. break;
  206. case 'list-owner':
  207. $value = $this->stripComments($value);
  208. $this->mlist('owner', $value);
  209. break;
  210. case 'list-help':
  211. $value = $this->stripComments($value);
  212. $this->mlist('help', $value);
  213. break;
  214. case 'list-id':
  215. $value = $this->stripComments($value);
  216. $this->mlist('id', $value);
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. function getAddressTokens($address) {
  223. $aTokens = array();
  224. $aAddress = array();
  225. $aSpecials = array('(' ,'<' ,',' ,';' ,':');
  226. $aReplace = array(' (',' <',' ,',' ;',' :');
  227. $address = str_replace($aSpecials,$aReplace,$address);
  228. $iCnt = strlen($address);
  229. $i = 0;
  230. while ($i < $iCnt) {
  231. $cChar = $address{$i};
  232. switch($cChar)
  233. {
  234. case '<':
  235. $iEnd = strpos($address,'>',$i+1);
  236. if (!$iEnd) {
  237. $sToken = substr($address,$i);
  238. $i = $iCnt;
  239. } else {
  240. $sToken = substr($address,$i,$iEnd - $i +1);
  241. $i = $iEnd;
  242. }
  243. $sToken = str_replace($aReplace, $aSpecials,$sToken);
  244. if ($sToken) $aTokens[] = $sToken;
  245. break;
  246. case '"':
  247. $iEnd = strpos($address,$cChar,$i+1);
  248. if ($iEnd) {
  249. // skip escaped quotes
  250. $prev_char = $address{$iEnd-1};
  251. while ($prev_char === '\\' && substr($address,$iEnd-2,2) !== '\\\\') {
  252. $iEnd = strpos($address,$cChar,$iEnd+1);
  253. if ($iEnd) {
  254. $prev_char = $address{$iEnd-1};
  255. } else {
  256. $prev_char = false;
  257. }
  258. }
  259. }
  260. if (!$iEnd) {
  261. $sToken = substr($address,$i);
  262. $i = $iCnt;
  263. } else {
  264. // also remove the surrounding quotes
  265. $sToken = substr($address,$i+1,$iEnd - $i -1);
  266. $i = $iEnd;
  267. }
  268. $sToken = str_replace($aReplace, $aSpecials,$sToken);
  269. if ($sToken) $aTokens[] = $sToken;
  270. break;
  271. case '(':
  272. array_pop($aTokens); //remove inserted space
  273. $iEnd = strpos($address,')',$i);
  274. if (!$iEnd) {
  275. $sToken = substr($address,$i);
  276. $i = $iCnt;
  277. } else {
  278. $iDepth = 1;
  279. $iComment = $i;
  280. while (($iDepth > 0) && (++$iComment < $iCnt)) {
  281. $cCharComment = $address{$iComment};
  282. switch($cCharComment) {
  283. case '\\':
  284. ++$iComment;
  285. break;
  286. case '(':
  287. ++$iDepth;
  288. break;
  289. case ')':
  290. --$iDepth;
  291. break;
  292. default:
  293. break;
  294. }
  295. }
  296. if ($iDepth == 0) {
  297. $sToken = substr($address,$i,$iComment - $i +1);
  298. $i = $iComment;
  299. } else {
  300. $sToken = substr($address,$i,$iEnd - $i + 1);
  301. $i = $iEnd;
  302. }
  303. }
  304. // check the next token in case comments appear in the middle of email addresses
  305. $prevToken = end($aTokens);
  306. if (!in_array($prevToken,$aSpecials,true)) {
  307. if ($i+1<strlen($address) && !in_array($address{$i+1},$aSpecials,true)) {
  308. $iEnd = strpos($address,' ',$i+1);
  309. if ($iEnd) {
  310. $sNextToken = trim(substr($address,$i+1,$iEnd - $i -1));
  311. $i = $iEnd-1;
  312. } else {
  313. $sNextToken = trim(substr($address,$i+1));
  314. $i = $iCnt;
  315. }
  316. // remove the token
  317. array_pop($aTokens);
  318. // create token and add it again
  319. $sNewToken = $prevToken . $sNextToken;
  320. if($sNewToken) $aTokens[] = $sNewToken;
  321. }
  322. }
  323. $sToken = str_replace($aReplace, $aSpecials,$sToken);
  324. if ($sToken) $aTokens[] = $sToken;
  325. break;
  326. case ',':
  327. case ':':
  328. case ';':
  329. case ' ':
  330. $aTokens[] = $cChar;
  331. break;
  332. default:
  333. $iEnd = strpos($address,' ',$i+1);
  334. if ($iEnd) {
  335. $sToken = trim(substr($address,$i,$iEnd - $i));
  336. $i = $iEnd-1;
  337. } else {
  338. $sToken = trim(substr($address,$i));
  339. $i = $iCnt;
  340. }
  341. if ($sToken) $aTokens[] = $sToken;
  342. }
  343. ++$i;
  344. }
  345. return $aTokens;
  346. }
  347. function createAddressObject(&$aStack,&$aComment,&$sEmail,$sGroup='') {
  348. //$aStack=explode(' ',implode('',$aStack));
  349. if (!$sEmail) {
  350. while (count($aStack) && !$sEmail) {
  351. $sEmail = trim(array_pop($aStack));
  352. }
  353. }
  354. if (count($aStack)) {
  355. $sPersonal = trim(implode('',$aStack));
  356. } else {
  357. $sPersonal = '';
  358. }
  359. if (!$sPersonal && count($aComment)) {
  360. $sComment = trim(implode(' ',$aComment));
  361. $sPersonal .= $sComment;
  362. }
  363. $oAddr =& new AddressStructure();
  364. if ($sPersonal && substr($sPersonal,0,2) == '=?') {
  365. $oAddr->personal = encodeHeader($sPersonal);
  366. } else {
  367. $oAddr->personal = $sPersonal;
  368. }
  369. // $oAddr->group = $sGroup;
  370. $iPosAt = strpos($sEmail,'@');
  371. if ($iPosAt) {
  372. $oAddr->mailbox = substr($sEmail, 0, $iPosAt);
  373. $oAddr->host = substr($sEmail, $iPosAt+1);
  374. } else {
  375. $oAddr->mailbox = $sEmail;
  376. $oAddr->host = false;
  377. }
  378. $sEmail = '';
  379. $aStack = $aComment = array();
  380. return $oAddr;
  381. }
  382. /*
  383. * parseAddress: recursive function for parsing address strings and store
  384. * them in an address stucture object.
  385. * input: $address = string
  386. * $ar = boolean (return array instead of only the
  387. * first element)
  388. * $addr_ar = array with parsed addresses // obsolete
  389. * $group = string // obsolete
  390. * $host = string (default domainname in case of
  391. * addresses without a domainname)
  392. * $lookup = callback function (for lookup address
  393. * strings which are probably nicks
  394. * (without @ ) )
  395. * output: array with addressstructure objects or only one
  396. * address_structure object.
  397. * personal name: encoded: =?charset?Q|B?string?=
  398. * quoted: "string"
  399. * normal: string
  400. * email : <mailbox@host>
  401. * : mailbox@host
  402. * This function is also used for validating addresses returned from compose
  403. * That's also the reason that the function became a little bit huge
  404. */
  405. function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false) {
  406. $aTokens = $this->getAddressTokens($address);
  407. $sPersonal = $sEmail = $sComment = $sGroup = '';
  408. $aStack = $aComment = array();
  409. foreach ($aTokens as $sToken) {
  410. $cChar = $sToken{0};
  411. switch ($cChar)
  412. {
  413. case '=':
  414. case '"':
  415. case ' ':
  416. $aStack[] = $sToken;
  417. break;
  418. case '(':
  419. $aComment[] = substr($sToken,1,-1);
  420. break;
  421. case ';':
  422. if ($sGroup) {
  423. $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup);
  424. $oAddr = end($aAddress);
  425. if(!$oAddr || ((isset($oAddr)) && !$oAddr->mailbox && !$oAddr->personal)) {
  426. $sEmail = $sGroup . ':;';
  427. }
  428. $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup);
  429. $sGroup = '';
  430. $aStack = $aComment = array();
  431. break;
  432. }
  433. case ',':
  434. $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup);
  435. break;
  436. case ':':
  437. $sGroup = trim(implode(' ',$aStack));
  438. $sGroup = preg_replace('/\s+/',' ',$sGroup);
  439. $aStack = array();
  440. break;
  441. case '<':
  442. $sEmail = trim(substr($sToken,1,-1));
  443. break;
  444. case '>':
  445. /* skip */
  446. break;
  447. default: $aStack[] = $sToken; break;
  448. }
  449. }
  450. /* now do the action again for the last address */
  451. $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail);
  452. /* try to lookup the addresses in case of invalid email addresses */
  453. $aProcessedAddress = array();
  454. foreach ($aAddress as $oAddr) {
  455. $aAddrBookAddress = array();
  456. if (!$oAddr->host) {
  457. $grouplookup = false;
  458. if ($lookup) {
  459. $aAddr = call_user_func_array($lookup,array($oAddr->mailbox));
  460. if (isset($aAddr['email'])) {
  461. if (strpos($aAddr['email'],',')) {
  462. $grouplookup = true;
  463. $aAddrBookAddress = $this->parseAddress($aAddr['email'],true);
  464. } else {
  465. $iPosAt = strpos($aAddr['email'], '@');
  466. $oAddr->mailbox = substr($aAddr['email'], 0, $iPosAt);
  467. $oAddr->host = substr($aAddr['email'], $iPosAt+1);
  468. if (isset($aAddr['name'])) {
  469. $oAddr->personal = $aAddr['name'];
  470. } else {
  471. $oAddr->personal = encodeHeader($sPersonal);
  472. }
  473. }
  474. }
  475. }
  476. if (!$grouplookup && !$oAddr->mailbox) {
  477. $oAddr->mailbox = trim($sEmail);
  478. if ($sHost && $oAddr->mailbox) {
  479. $oAddr->host = $sHost;
  480. }
  481. } else if (!$grouplookup && !$oAddr->host) {
  482. if ($sHost && $oAddr->mailbox) {
  483. $oAddr->host = $sHost;
  484. }
  485. }
  486. }
  487. if (!$aAddrBookAddress && $oAddr->mailbox) {
  488. $aProcessedAddress[] = $oAddr;
  489. } else {
  490. $aProcessedAddress = array_merge($aProcessedAddress,$aAddrBookAddress);
  491. }
  492. }
  493. if ($ar) {
  494. return $aProcessedAddress;
  495. } else {
  496. return $aProcessedAddress[0];
  497. }
  498. }
  499. function parseContentType($value) {
  500. $pos = strpos($value, ';');
  501. $props = '';
  502. if ($pos > 0) {
  503. $type = trim(substr($value, 0, $pos));
  504. $props = trim(substr($value, $pos+1));
  505. } else {
  506. $type = $value;
  507. }
  508. $content_type = new ContentType($type);
  509. if ($props) {
  510. $properties = $this->parseProperties($props);
  511. if (!isset($properties['charset'])) {
  512. $properties['charset'] = 'us-ascii';
  513. }
  514. $content_type->properties = $this->parseProperties($props);
  515. }
  516. $this->content_type = $content_type;
  517. }
  518. /* RFC2184 */
  519. function processParameters($aParameters) {
  520. $aResults = array();
  521. $aCharset = array();
  522. // handle multiline parameters
  523. foreach($aParameters as $key => $value) {
  524. if ($iPos = strpos($key,'*')) {
  525. $sKey = substr($key,0,$iPos);
  526. if (!isset($aResults[$sKey])) {
  527. $aResults[$sKey] = $value;
  528. if (substr($key,-1) == '*') { // parameter contains language/charset info
  529. $aCharset[] = $sKey;
  530. }
  531. } else {
  532. $aResults[$sKey] .= $value;
  533. }
  534. } else {
  535. $aResults[$key] = $value;
  536. }
  537. }
  538. foreach ($aCharset as $key) {
  539. $value = $aResults[$key];
  540. // extract the charset & language
  541. $charset = substr($value,0,strpos($value,"'"));
  542. $value = substr($value,strlen($charset)+1);
  543. $language = substr($value,0,strpos($value,"'"));
  544. $value = substr($value,strlen($charset)+1);
  545. // FIX ME What's the status of charset decode with language information ????
  546. $value = charset_decode($charset,$value);
  547. $aResults[$key] = $value;
  548. }
  549. return $aResults;
  550. }
  551. function parseProperties($value) {
  552. $propArray = explode(';', $value);
  553. $propResultArray = array();
  554. foreach ($propArray as $prop) {
  555. $prop = trim($prop);
  556. $pos = strpos($prop, '=');
  557. if ($pos > 0) {
  558. $key = trim(substr($prop, 0, $pos));
  559. $val = trim(substr($prop, $pos+1));
  560. if ($val{0} == '"') {
  561. $val = substr($val, 1, -1);
  562. }
  563. $propResultArray[$key] = $val;
  564. }
  565. }
  566. return $this->processParameters($propResultArray);
  567. }
  568. function parseDisposition($value) {
  569. $pos = strpos($value, ';');
  570. $props = '';
  571. if ($pos > 0) {
  572. $name = trim(substr($value, 0, $pos));
  573. $props = trim(substr($value, $pos+1));
  574. } else {
  575. $name = $value;
  576. }
  577. $props_a = $this->parseProperties($props);
  578. $disp = new Disposition($name);
  579. $disp->properties = $props_a;
  580. $this->disposition = $disp;
  581. }
  582. function mlist($field, $value) {
  583. $res_a = array();
  584. $value_a = explode(',', $value);
  585. foreach ($value_a as $val) {
  586. $val = trim($val);
  587. if ($val{0} == '<') {
  588. $val = substr($val, 1, -1);
  589. }
  590. if (substr($val, 0, 7) == 'mailto:') {
  591. $res_a['mailto'] = substr($val, 7);
  592. } else {
  593. $res_a['href'] = $val;
  594. }
  595. }
  596. $this->mlist[$field] = $res_a;
  597. }
  598. /*
  599. * function to get the addres strings out of the header.
  600. * Arguments: string or array of strings !
  601. * example1: header->getAddr_s('to').
  602. * example2: header->getAddr_s(array('to', 'cc', 'bcc'))
  603. */
  604. function getAddr_s($arr, $separator = ',',$encoded=false) {
  605. $s = '';
  606. if (is_array($arr)) {
  607. foreach($arr as $arg) {
  608. if ($this->getAddr_s($arg, $separator, $encoded)) {
  609. $s .= $separator . $result;
  610. }
  611. }
  612. $s = ($s ? substr($s, 2) : $s);
  613. } else {
  614. $addr = $this->{$arr};
  615. if (is_array($addr)) {
  616. foreach ($addr as $addr_o) {
  617. if (is_object($addr_o)) {
  618. if ($encoded) {
  619. $s .= $addr_o->getEncodedAddress() . $separator;
  620. } else {
  621. $s .= $addr_o->getAddress() . $separator;
  622. }
  623. }
  624. }
  625. $s = substr($s, 0, -strlen($separator));
  626. } else {
  627. if (is_object($addr)) {
  628. if ($encoded) {
  629. $s .= $addr->getEncodedAddress();
  630. } else {
  631. $s .= $addr->getAddress();
  632. }
  633. }
  634. }
  635. }
  636. return $s;
  637. }
  638. function getAddr_a($arg, $excl_arr = array(), $arr = array()) {
  639. if (is_array($arg)) {
  640. foreach($arg as $argument) {
  641. $arr = $this->getAddr_a($argument, $excl_arr, $arr);
  642. }
  643. } else {
  644. $addr = $this->{$arg};
  645. if (is_array($addr)) {
  646. foreach ($addr as $next_addr) {
  647. if (is_object($next_addr)) {
  648. if (isset($next_addr->host) && ($next_addr->host != '')) {
  649. $email = $next_addr->mailbox . '@' . $next_addr->host;
  650. } else {
  651. $email = $next_addr->mailbox;
  652. }
  653. $email = strtolower($email);
  654. if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
  655. $arr[$email] = $next_addr->personal;
  656. }
  657. }
  658. }
  659. } else {
  660. if (is_object($addr)) {
  661. $email = $addr->mailbox;
  662. $email .= (isset($addr->host) ? '@' . $addr->host : '');
  663. $email = strtolower($email);
  664. if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
  665. $arr[$email] = $addr->personal;
  666. }
  667. }
  668. }
  669. }
  670. return $arr;
  671. }
  672. function findAddress($address, $recurs = false) {
  673. $result = false;
  674. if (is_array($address)) {
  675. $i=0;
  676. foreach($address as $argument) {
  677. $match = $this->findAddress($argument, true);
  678. $last = end($match);
  679. if ($match[1]) {
  680. return $i;
  681. } else {
  682. if (count($match[0]) && !$result) {
  683. $result = $i;
  684. }
  685. }
  686. ++$i;
  687. }
  688. } else {
  689. if (!is_array($this->cc)) $this->cc = array();
  690. $srch_addr = $this->parseAddress($address);
  691. $results = array();
  692. foreach ($this->to as $to) {
  693. if ($to->host == $srch_addr->host) {
  694. if ($to->mailbox == $srch_addr->mailbox) {
  695. $results[] = $srch_addr;
  696. if ($to->personal == $srch_addr->personal) {
  697. if ($recurs) {
  698. return array($results, true);
  699. } else {
  700. return true;
  701. }
  702. }
  703. }
  704. }
  705. }
  706. foreach ($this->cc as $cc) {
  707. if ($cc->host == $srch_addr->host) {
  708. if ($cc->mailbox == $srch_addr->mailbox) {
  709. $results[] = $srch_addr;
  710. if ($cc->personal == $srch_addr->personal) {
  711. if ($recurs) {
  712. return array($results, true);
  713. } else {
  714. return true;
  715. }
  716. }
  717. }
  718. }
  719. }
  720. if ($recurs) {
  721. return array($results, false);
  722. } elseif (count($result)) {
  723. return true;
  724. } else {
  725. return false;
  726. }
  727. }
  728. //exit;
  729. return $result;
  730. }
  731. function getContentType($type0, $type1) {
  732. $type0 = $this->content_type->type0;
  733. $type1 = $this->content_type->type1;
  734. return $this->content_type->properties;
  735. }
  736. }
  737. ?>