6 * Copyright (c) 2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
10 * This contains functions needed to handle mime messages.
17 * input: header_string or array
38 $optional_headers = array(); /* only needed for
39 constructing headers in smtp.php */
41 function parseHeader($hdr) {
43 $hdr = implode('',$hdr);
45 /* first we unfold the header */
46 $hdr = str_replace(array("\r\n\t","\r\n\s"),array('',''),$hdr);
48 * now we can make a new header array with each element representing
51 $hdr = explode("\r\n" , $hdr);
52 foreach ($hdr as $line) {
53 $pos = strpos($line,':');
55 $field = substr($line,0,$pos);
56 $value = trim(substr($line,$pos+
1));
57 $value = $this->stripComments($value);
58 $this->parseField($field,$value);
61 if ($this->content_type
== '') {
62 $this->parseContentType('text/plain; charset=us-ascii');
66 function stripComments($value) {
67 $cnt = strlen($value);
76 while ($value{$i} != '"') {
77 if ($value{$i} == '\\') {
87 while ($value{$i} != ')') {
88 if ($value{$i} == '\\') {
103 function parseField($field,$value) {
104 $field = strtolower($field);
108 $d = strtr($value, array(' ' => ' '));
109 $d = explode(' ', $d);
110 $this->date
= getTimeStamp($d);
113 $this->subject
= $value;
116 $this->from
= $this->parseAddress($value,true);
119 $this->sender
= $this->parseAddress($value);
122 $this->reply_to
= $this->parseAddress($value, true);
125 $this->to
= $this->parseAddress($value, true);
128 $this->cc
= $this->parseAddress($value, true);
131 $this->bcc
= $this->parseAddress($value, true);
133 case ('in-reply-to'):
134 $this->in_reply_to
= $value;
137 $this->message_id
= $value;
139 case ('disposition-notification-to'):
140 $this->dnt
= $this->parseAddress($value);
142 case ('mime-Version'):
143 $value = str_replace(' ','',$value);
144 if ($value == '1.0') {
148 case ('content-type'):
149 $this->parseContentType($value);
151 case ('content-disposition'):
152 $this->parseDisposition($value);
155 $this->xmailer
= $value;
158 $this->priority
= $value;
161 $this->mlist('post',$value);
164 $this->mlist('reply',$value);
166 case ('list-subscribe'):
167 $this->mlist('subscribe',$value);
169 case ('list-unsubscribe'):
170 $this->mlist('unsubscribe',$value);
172 case ('list-archive'):
173 $this->mlist('archive',$value);
176 $this->mlist('owner',$value);
179 $this->mlist('help',$value);
182 $this->mlist('id',$value);
189 function parseAddress($address, $ar=false, $addr_ar = array(), $group = '') {
191 $j = strlen( $address );
194 while ( $pos < $j ) {
195 switch ($address{$pos})
197 case ('"'): /* get the personal name */
199 if ($address{$pos} == '"') {
202 while ( $pos < $j && $address{$pos} != '"') {
203 if (substr($address, $pos, 2) == '\\"') {
204 $name .= $address{$pos};
206 } elseif (substr($address, $pos, 2) == '\\\\') {
207 $name .= $address{$pos};
210 $name .= $address{$pos};
216 case ('<'): /* get email address */
219 while ( $pos < $j && $address{$pos} != '>' ) {
220 $addr .= $address{$pos};
225 case ('('): /* rip off comments */
228 while ( $pos < $j && $address{$pos} != ')' ) {
229 $addr .= $address{$pos};
232 $address_start = substr($address,0,$addr_start);
233 $address_end = substr($address,$pos+
1);
234 $address = $address_start . $address_end;
235 $j = strlen( $address );
239 case (','): /* we reached a delimiter */
241 $addr = substr($address,0,$pos);
242 } elseif ($name == '') {
243 $name = substr($address,0,$addr_start);
246 $at = strpos($addr, '@');
247 $addr_structure = new address_structure();
248 $addr_structure->personal
= $name;
249 $addr_structure->group
= $group;
251 $addr_structure->mailbox
= substr($addr,0,$at);
252 $addr_structure->host
= substr($addr,$at+
1);
254 $addr_structure->mailbox
= $addr;
256 $address = trim(substr($address,$pos+
1));
257 $j = strlen( $address );
261 $addr_ar[] = $addr_structure;
263 case (':'): /* process the group addresses */
265 $group = substr($address,0,$pos);
266 $address = substr($address,$pos+
1);
267 $result = $this->parseAddress($address, $ar, $addr_ar, $group);
268 $addr_ar = $result[0];
270 $address = substr($address,$pos);
271 $j = strlen( $address );
277 $address = substr($address, 0, $pos-1);
288 $addr = substr($address,0,$pos);
289 } elseif ($name == '') {
290 $name = substr($address,0,$addr_start);
292 $at = strpos($addr, '@');
293 $addr_structure = new address_structure();
294 $addr_structure->group
= $group;
296 $addr_structure->mailbox
= trim(substr($addr,0,$at));
297 $addr_structure->host
= trim(substr($addr,$at+
1));
299 $addr_structure->mailbox
= trim($addr);
301 if ($group && $addr == '') { /* no addresses found in group */
302 $name = "$group: Undisclosed recipients;";
303 $addr_structure->personal
= $name;
304 $addr_ar[] = $addr_structure;
305 return (array($addr_ar,$pos+
1));
307 $addr_structure->personal
= $name;
308 if ($name ||
$addr) {
309 $addr_ar[] = $addr_structure;
315 return ($addr_ar[0]);
319 function parseContentType($value) {
320 $pos = strpos($value,';');
323 $type = trim(substr($value,0,$pos));
324 $props = trim(substr($type,$pos+
1));
328 $content_type = new content_type($type);
330 $properties = $this->parseProperties($props);
331 if (!isset($properties['charset'])) {
332 $properties['charset'] = 'us-ascii';
334 $content_type->properties
= $this->parseProperties($props);
336 $this->content_type
= $content_type;
339 function parseProperties($value) {
340 $propArray = explode(';',$value);
341 $propResultArray = array();
342 foreach ($propArray as $prop) {
344 $pos = strpos($prop,'=');
346 $key = trim(substr($prop,0,$pos));
347 $val = trim(substr($prop,$pos+
1));
348 if ($val{0} == '"') {
349 $val = substr($val,1,-1);
351 $propResultArray[$key] = $val;
354 return $propResultArray;
357 function parseDisposition($value) {
358 $pos = strpos($value,';');
361 $name = trim(substr($value,0,$pos));
362 $props = trim(substr($type,$pos+
1));
366 $props_a = $this->parseProperties($props);
367 $disp = new disposition($name);
368 $disp->properties
= $props_a;
369 $this->disposition
= $disp;
372 function mlist($field, $value) {
374 $value_a = explode(',',$value);
375 foreach ($value_a as $val) {
377 if ($val{0} == '<') {
378 $val = substr($val,1,-1);
380 if (substr($val,0,7) == 'mailto:') {
381 $res_a['mailto'] = substr($val,7);
383 $res_a['href'] = $val;
386 $this->mlist
[$field] = $res_a;
390 * function to get the addres strings out of the header.
391 * Arguments: string or array of strings !
392 * example1: header->getAddr_s('to').
393 * example2: header->getAddr_s(array('to','cc','bcc'))
395 function getAddr_s($arr, $separator=', ') {
396 if (is_array($arr)) {
398 foreach($arr as $arg ) {
399 $result = $this->getAddr_s($arg);
401 $s .= $separator . $result;
404 if ($s) $s = substr($s,2);
408 eval('$addr = $this->'.$arr.';') ;
409 if (is_array($addr)) {
410 foreach ($addr as $addr_o) {
411 if (is_object($addr_o)) {
412 $s .= $addr_o->getAddress() . $separator;
415 $s = substr($s,0,-strlen($separator));
417 if (is_object($addr)) {
418 $s .= $addr->getAddress();
425 function getAddr_a($arg, $excl_arr=array(), $arr = array()) {
426 if (is_array($arg)) {
427 foreach($arg as $argument ) {
428 $arr = $this->getAddr_a($argument, $excl_arr, $arr);
432 eval('$addr = $this->'.$arg.';') ;
433 if (is_array($addr)) {
434 foreach ($addr as $addr_o) {
435 if (is_object($addr_o)) {
436 if (isset($addr_o->host
) && $addr_o->host
!='') {
437 $email = $addr_o->mailbox
.'@'.$addr_o->host
;
439 $email = $addr_o->mailbox
;
441 $email = strtolower($email);
442 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
443 $arr[$email] = $addr_o->personal
;
448 if (is_object($addr)) {
449 if (isset($addr->host
)) {
450 $email = $addr->mailbox
.'@'.$addr->host
;
452 $email = $addr->mailbox
;
454 $email = strtolower($email);
455 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
456 $arr[$email] = $addr->personal
;
464 function getContentType($type0, $type1) {
465 $type0 = $this->content_type
->type0
;
466 $type1 = $this->content_type
->type1
;
467 return $this->content_type
->properties
;
472 /** msg_header contains all variables available in a bodystructure **/
473 /** entity like described in rfc2060 **/
477 $parameters = array(),
487 * returns addres_list of supplied argument
488 * arguments: array('to', 'from', ...) or just a string like 'to'.
489 * result: string: address1, addres2, ....
492 function setVar($var, $value) {
493 $this->{$var} = $value;
496 function getParameter($par) {
497 $value = strtolower($par);
498 if (isset($this->parameters
[$par])) {
499 return $this->parameters
[$par];
504 function setParameter($parameter, $value) {
505 $this->parameters
[strtolower($parameter)] = $value;
511 class address_structure
{
512 var $personal = '', $adl = '', $mailbox = '', $host = '', $group = '';
514 function getAddress($full=true) {
515 if (is_object($this)) {
516 if (isset($this->host
) && $this->host
!='') {
517 $email = $this->mailbox
.'@'.$this->host
;
519 $email = $this->mailbox
;
521 if (trim($this->personal
) !='') {
523 $addr = '"' . $this->personal
. '" <' .$email.'>';
525 $addr = $this->personal
;
527 $best_dpl = $this->personal
;
542 /** message is the object that contains messages. It is a recursive
543 object in that through the $entities variable, it can contain
544 more objects of type message. See documentation in mime.txt for
545 a better description of how this works.
547 var $rfc822_header = '',
553 $parent_ent, $entity,
554 $parent = '', $decoded_body='',
555 $is_seen = 0, $is_answered = 0, $is_deleted = 0, $is_flagged = 0,
559 function setEnt($ent) {
560 $this->entity_id
= $ent;
563 function addEntity ($msg) {
564 $msg->parent
= &$this;
565 $this->entities
[] = $msg;
568 function addRFC822Header($read) {
569 $header = new msg_header();
570 $this->header
= sqimap_parse_RFC822Header($read,$header);
573 function getEntity($ent) {
575 $cur_ent = $this->entity_id
;
577 if ($cur_ent == '' ||
$cur_ent == '0') {
578 $cur_ent_a = array();
580 $cur_ent_a = explode('.',$this->entity_id
);
582 $ent_a = explode('.',$ent);
584 $cnt = count($ent_a);
586 for ($i=0;$i<$cnt -1;$i++
) {
587 if (isset($cur_ent_a[$i]) && $cur_ent_a[$i] != $ent_a[$i]) {
589 $cur_ent_a = explode('.',$msg->entity_id
);
591 } else if (!isset($cur_ent_a[$i])) {
592 if (isset($msg->entities
[($ent_a[$i]-1)])) {
593 $msg = $msg->entities
[($ent_a[$i]-1)];
595 $msg = $msg->entities
[0];
598 if ($msg->type0
== 'message' && $msg->type1
== 'rfc822') {
599 /*this is a header for a message/rfc822 entity */
600 $msg = $msg->entities
[0];
604 if ($msg->type0
== 'message' && $msg->type1
== 'rfc822') {
605 /*this is a header for a message/rfc822 entity */
606 $msg = $msg->entities
[0];
609 if (isset($msg->entities
[($ent_a[$cnt-1])-1])) {
610 $msg = $msg->entities
[($ent_a[$cnt-1]-1)];
616 function setBody($s) {
617 $this->body_part
= $s;
620 function clean_up() {
622 $msg->body_part
= '';
624 while ( isset($msg->entities
[$i])) {
625 $msg->entities
[$i]->clean_up();
630 function getMailbox() {
632 while (is_object($msg->parent
)) {
635 return $msg->mailbox
;
639 * Bodystructure parser, a recursive function for generating the
640 * entity-tree with all the mime-parts.
642 * It follows RFC2060 and stores all the described fields in the
647 * Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net.
650 function &parseStructure($read, $i=0, $message = false) {
653 $cnt = strlen($read);
655 $char = strtoupper($read{$i});
660 $msg = new message();
661 $hdr = new msg_header();
662 $hdr->type0
= 'text';
663 $hdr->type1
= 'plain';
664 $hdr->encoding
= 'us-ascii';
666 if ($this->type0
== 'message' && $this->type1
== 'rfc822') {
667 $msg->entity_id
= $this->entity_id
.'.0'; /* header of message/rfc822 */
668 } else if (isset($this->entity_id
) && $this->entity_id
!='') {
669 $ent_no = count($this->entities
)+
1;
670 $par_ent = substr($this->entity_id
,-2);
671 if ($par_ent{0} == '.') {
672 $par_ent = $par_ent{1};
674 if ($par_ent == '0') {
675 $ent_no = count($this->entities
)+
1;
677 $ent = substr($this->entity_id
,0,strrpos($this->entity_id
,'.'));
679 $ent = $ent . ".$ent_no";
683 $msg->entity_id
= $ent;
685 $msg->entity_id
= $ent_no;
688 $ent = $this->entity_id
. ".$ent_no";
689 $msg->entity_id
= $ent;
692 $msg->entity_id
= '0';
695 $msg->header
->type0
= 'multipart';
696 $msg->type0
= 'multipart';
697 while ($read{$i} == '(') {
698 $msg->addEntity($msg->parseStructure($read,&$i));
705 /* multipart properties */
707 $arg_a[] = $this->parseProperties($read,&$i);
711 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
713 $arg_a[]= $msg->parseDisposition($read,&$i);
714 } else { /* properties */
716 $arg_a[] = $msg->parseProperties($read,&$i);
721 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
723 $arg_a[]= $msg->parseLanguage($read,&$i);
726 if ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822') {
728 $msg->header
->type0
= $arg_a[0];
729 $msg->type0
= $arg_a[0];
731 $msg->header
->type1
= $arg_a[1];
732 $msg->type1
= $arg_a[1];
733 $rfc822_hdr = new rfc822_header();
734 $msg->parseEnvelope($read,&$i,&$rfc822_hdr);
735 $msg->rfc822_header
= $rfc822_hdr;
737 while ($i < $cnt && $read{$i} != '(') {
740 $msg->addEntity($msg->parseStructure($read,&$i));
745 $arg_a[] = $msg->parseDisposition($read,&$i);
749 if ($arg_a[0] == 'text' ||
750 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
752 $arg_a[] = $msg->parseDisposition($read,&$i);
755 $arg_a[] = $msg->parseLanguage($read,&$i);
760 if ($arg_a[0] == 'text' ||
761 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
763 $arg_a[] = $msg->parseLanguage($read,&$i);
765 $msg->parseParenthesis($read,&$i);
766 $arg_a[] = ''; /* not yet desribed in rfc2060 */
771 /* unknown argument, skip this part */
772 $msg->parseParenthesis($read,&$i);
780 /* inside an entity -> start processing */
781 $debug = substr($read,$i,20);
782 $arg_s = $msg->parseQuote($read,&$i);
784 if ($arg_no < 3) $arg_s = strtolower($arg_s); /* type0 and type1 */
789 /* probably NIL argument */
790 if (strtoupper(substr($read,$i,4)) == 'NIL ' ||
791 strtoupper(substr($read,$i,4)) == 'NIL)') {
798 /* process the literal value */
799 $arg_a[] = $msg->parseLiteral($read,&$i);
802 case (is_numeric($read{$i}) ):
803 /* process integers */
804 if ($read{$i} == ' ') break;
807 while (preg_match('/^[0-9]{1}$/',$read{$i})) {
815 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
821 if ($arg_a[0] == 'text' ||
822 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
823 $shifted_args = true;
825 $shifted_args = false;
827 $hdr->type0
= $arg_a[0];
828 $hdr->type1
= $arg_a[1];
830 $msg->type0
= $arg_a[0];
831 $msg->type1
= $arg_a[1];
834 if (is_array($arr)) {
835 $hdr->parameters
= $arg_a[2];
837 $hdr->id
= str_replace( '<', '', str_replace( '>', '', $arg_a[3] ) );
838 $hdr->description
= $arg_a[4];
839 $hdr->encoding
= strtolower($arg_a[5]);
840 $hdr->entity_id
= $msg->entity_id
;
841 $hdr->size
= $arg_a[6];
843 $hdr->lines
= $arg_a[7];
844 if (isset($arg_a[8])) {
845 $hdr->md5
= $arg_a[8];
847 if (isset($arg_a[9])) {
848 $hdr->disposition
= $arg_a[9];
850 if (isset($arg_a[10])) {
851 $hdr->language
= $arg_a[10];
854 if (isset($arg_a[7])) {
855 $hdr->md5
= $arg_a[7];
857 if (isset($arg_a[8])) {
858 $hdr->disposition
= $arg_a[8];
860 if (isset($arg_a[9])) {
861 $hdr->language
= $arg_a[9];
867 if (substr($msg->entity_id
,-2) == '.0' && $msg->type0
!='multipart') {
872 $hdr->type0
= 'multipart';
873 $hdr->type1
= $arg_a[0];
875 $msg->type0
= 'multipart';
876 $msg->type1
= $arg_a[0];
877 if (is_array($arg_a[1])) {
878 $hdr->parameters
= $arg_a[1];
880 if (isset($arg_a[2])) {
881 $hdr->disposition
= $arg_a[2];
883 if (isset($arg_a[3])) {
884 $hdr->language
= $arg_a[3];
894 } /* parsestructure */
896 function parseProperties($read, $i) {
897 $properties = array();
900 while ($read{$i} != ')') {
901 if ($read{$i} == '"') {
902 $arg_s = $this->parseQuote($read,&$i);
903 } else if ($read{$i} == '{') {
904 $arg_s = $this->parseLiteral($read,&$i);
906 if ($prop_name == '' && $arg_s) {
907 $prop_name = strtolower($arg_s);
908 $properties[$prop_name] = '';
910 } elseif ($prop_name != '' && $arg_s != '') {
911 $properties[$prop_name] = $arg_s;
920 function parseEnvelope($read, $i, $hdr) {
923 $cnt = strlen($read);
924 while ($i< $cnt && $read{$i} != ')') {
926 $char = strtoupper($read{$i});
930 $arg_a[] = $this->parseQuote($read,&$i);
934 $arg_a[] = $this->parseLiteral($read,&$i);
938 /* probably NIL argument */
939 if (strtoupper(substr($read,$i,3)) == 'NIL') {
947 * With group support.
948 * Note: Group support is useless on SMTP connections
949 * because the protocol doesn't support it
954 while ($i < $cnt && $read{$i} != ')') {
955 if ($read{$i} == '(') {
956 $addr = $this->parseAddress($read,&$i);
957 if ($addr->host
== '' && $addr->mailbox
!= '') {
959 $group = $addr->mailbox
;
962 } elseif ($group && $addr->host
== '' && $addr->mailbox
== '') {
964 if ($a == $j+
1) { /* no group members */
965 $group_addr->group
= $group;
966 $group_addr->mailbox
= '';
967 $group_addr->personal
= "$group: Undisclosed recipients;";
968 $addr_a[] = $group_addr;
972 $addr->group
= $group;
986 if (count($arg_a) > 9) {
987 /* argument 1: date */
988 $d = strtr($arg_a[0], array(' ' => ' '));
989 $d = explode(' ', $d);
990 $hdr->date
= getTimeStamp($d);
991 /* argument 2: subject */
992 if (!trim($arg_a[1])) {
993 $arg_a[1]= _("(no subject)");
995 $hdr->subject
= $arg_a[1];
996 /* argument 3: from */
997 $hdr->from
= $arg_a[2][0];
998 /* argument 4: sender */
999 $hdr->sender
= $arg_a[3][0];
1000 /* argument 5: reply-to */
1001 $hdr->replyto
= $arg_a[4][0];
1002 /* argument 6: to */
1003 $hdr->to
= $arg_a[5];
1004 /* argument 7: cc */
1005 $hdr->cc
= $arg_a[6];
1006 /* argument 8: bcc */
1007 $hdr->bcc
= $arg_a[7];
1008 /* argument 9: in-reply-to */
1009 $hdr->inreplyto
= $arg_a[8];
1010 /* argument 10: message-id */
1011 $hdr->message_id
= $arg_a[9];
1015 function parseLiteral($read, $i) {
1018 while ($read{$i} != '}') {
1019 $lit_cnt .= $read{$i};
1022 $lit_cnt +
=2; /* add the { and } characters */
1024 for ($j = 0; $j < $lit_cnt; $j++
) {
1031 function parseQuote($read, $i) {
1034 while ($read{$i} != '"') {
1035 if ($read{$i} == '\\') {
1044 function parseAddress($read, $i) {
1046 while ($read{$i} != ')' ) { //&& $i < count($read)) {
1047 $char = strtoupper($read{$i});
1051 $arg_a[] = $this->parseQuote($read,&$i);
1054 $arg_a[] = $this->parseLiteral($read,&$i);
1058 if (strtoupper(substr($read,$i,3)) == 'NIL') {
1068 if (count($arg_a) == 4) {
1069 $adr = new address_structure();
1070 $adr->personal
= $arg_a[0];
1071 $adr->adl
= $arg_a[1];
1072 $adr->mailbox
= $arg_a[2];
1073 $adr->host
= $arg_a[3];
1080 function parseDisposition($read,&$i) {
1082 while ($read{$i} != ')') {
1086 $arg_a[] = $this->parseQuote($read,&$i);
1089 $arg_a[] = $this->parseLiteral($read,&$i);
1092 $arg_a[] = $this->parseProperties($read,&$i);
1099 if (isset($arg_a[0])) {
1100 $disp = new disposition($arg_a[0]);
1101 if (isset($arg_a[1])) {
1102 $disp->properties
= $arg_a[1];
1105 if (is_object($disp)) {
1110 function parseLanguage($read,&$i) {
1111 /* no idea how to process this one without examples */
1113 while ($read{$i} != ')') {
1117 $arg_a[] = $this->parseQuote($read,&$i);
1120 $arg_a[] = $this->parseLiteral($read,&$i);
1123 $arg_a[] = $this->parseProperties($read,&$i);
1130 if (isset($arg_a[0])) {
1131 $lang = new language($arg_a[0]);
1132 if (isset($arg_a[1])) {
1133 $lang->properties
= $arg_a[1];
1136 if (is_object($lang)) {
1143 function parseParenthesis($read,&$i) {
1144 while ($read{$i} != ')') {
1148 $this->parseQuote($read,&$i);
1151 $this->parseLiteral($read,&$i);
1154 $this->parseParenthesis($read,&$i);
1163 function findDisplayEntity ($entity = array(), $alt_order = array('text/plain','text/html')) {
1165 $type = $this->type0
.'/'.$this->type1
;
1166 if ( $type == 'multipart/alternative') {
1167 $msg = $this->findAlternativeEntity($alt_order);
1168 if (count($msg->entities
) == 0) {
1169 $entity[] = $msg->entity_id
;
1171 $msg->findDisplayEntity(&$entity, $alt_order);
1174 } else if ( $type == 'multipart/related') {
1175 $msgs = $this->findRelatedEntity();
1176 for ($i = 0; $i < count($msgs); $i++
) {
1178 if (count($msg->entities
) == 0) {
1179 $entity[] = $msg->entity_id
;
1181 $msg->findDisplayEntity(&$entity,$alt_order);
1185 } else if ( $this->type0
== 'text' &&
1186 ( $this->type1
== 'plain' ||
1187 $this->type1
== 'html' ||
1188 $this->type1
== 'message') &&
1189 isset($this->entity_id
) ) {
1190 if (count($this->entities
) == 0) {
1191 if (strtolower($this->header
->disposition
->name
) != 'attachment') {
1192 $entity[] = $this->entity_id
;
1197 while ( isset($this->entities
[$i]) && !$found &&
1198 (strtolower($this->entities
[$i]->header
->disposition
->name
)
1200 ($this->entities
[$i]->type0
!= 'message' &&
1201 $this->entities
[$i]->type1
!= 'rfc822' )
1204 $this->entities
[$i]->findDisplayEntity(&$entity, $alt_order);
1208 if ( !isset($entity[0]) ) {
1214 function findAlternativeEntity ($alt_order) {
1215 /* if we are dealing with alternative parts then we choose the best
1216 * viewable message supported by SM.
1221 for ($i = 0; $i < count($this->entities
); $i ++
) {
1222 $type = $this->entities
[$i]->header
->type0
.'/'.$this->entities
[$i]->header
->type1
;
1223 if ($type == 'multipart/related') {
1224 $type = $this->entities
[$i]->header
->getParameter('type');
1226 for ($j = $k; $j < count($alt_order); $j++
) {
1227 if ($alt_order[$j] == $type && $j > $best_view) {
1234 return $this->entities
[$ent_id];
1237 function findRelatedEntity () {
1239 for ($i = 0; $i < count($this->entities
); $i ++
) {
1240 $type = $this->entities
[$i]->header
->type0
.'/'.$this->entities
[$i]->header
->type1
;
1241 if ($this->header
->getParameter('type') == $type) {
1242 $msgs[] = $this->entities
[$i];
1248 function getAttachments($exclude_id=array(), $result = array()) {
1249 if ($this->type0
== 'message' && $this->type1
== 'rfc822') {
1250 $this = $this->entities
[0];
1252 if (count($this->entities
)) {
1253 foreach ($this->entities
as $entity) {
1255 foreach ($exclude_id as $excl) {
1256 if ($entity->entity_id
== $excl) {
1261 if ($entity->type0
== 'multipart' &&
1262 $entity->type1
!= 'related') {
1263 $result = $entity->getAttachments($exclude_id, $result);
1264 } else if ($entity->type0
!= 'multipart') {
1265 $result[] = $entity;
1271 foreach ($exclude_id as $excl) {
1272 if ($this->entity_id
== $excl) {
1286 function disposition($name) {
1287 $this->name
= $name;
1288 $this->properties
= array();
1293 function language($name) {
1294 $this->name
= $name;
1295 $this->properties
= array();
1299 class content_type
{
1303 function content_type($type) {
1304 $pos = strpos($type,'/');
1306 $this->type0
= substr($type,0,$pos);
1307 $this->type1
= substr($type,$pos+
1);
1309 $this->type0
= $type;
1311 $this->properties
= array();