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