e8b83734d81272e17c584f34ba7d6ea7677c758d
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.
19 * input: header_string or array
40 $optional_headers = array(); /* only needed for
41 constructing headers in smtp.php */
43 function parseHeader($hdr) {
45 $hdr = implode('',$hdr);
47 /* first we unfold the header */
48 $hdr = str_replace(array("\r\n\t","\r\n "),array('',''),$hdr);
50 * now we can make a new header array with each element representing
53 $hdr = explode("\r\n" , $hdr);
54 foreach ($hdr as $line) {
55 $pos = strpos($line,':');
57 $field = substr($line,0,$pos);
58 $value = trim(substr($line,$pos+
1));
59 $value = $this->stripComments($value);
60 $this->parseField($field,$value);
63 if ($this->content_type
== '') {
64 $this->parseContentType('text/plain; charset=us-ascii');
68 function stripComments($value) {
69 $cnt = strlen($value);
78 while ($value{$i} != '"') {
79 if ($value{$i} == '\\') {
89 while ($value{$i} != ')') {
90 if ($value{$i} == '\\') {
105 function parseField($field,$value)
107 $field = strtolower($field);
111 $d = strtr($value, array(' ' => ' '));
112 $d = explode(' ', $d);
113 $this->date
= getTimeStamp($d);
116 $this->subject
= $value;
119 $this->from
= $this->parseAddress($value,true);
122 $this->sender
= $this->parseAddress($value);
125 $this->reply_to
= $this->parseAddress($value, true);
128 $this->to
= $this->parseAddress($value, true);
131 $this->cc
= $this->parseAddress($value, true);
134 $this->bcc
= $this->parseAddress($value, true);
136 case ('in-reply-to'):
137 $this->in_reply_to
= $value;
140 $this->message_id
= $value;
142 case ('disposition-notification-to'):
143 $this->dnt
= $this->parseAddress($value);
145 case ('mime-Version'):
146 $value = str_replace(' ','',$value);
147 if ($value == '1.0') {
151 case ('content-type'):
152 $this->parseContentType($value);
154 case ('content-disposition'):
155 $this->parseDisposition($value);
158 $this->xmailer
= $value;
161 $this->priority
= $value;
164 $this->mlist('post',$value);
167 $this->mlist('reply',$value);
169 case ('list-subscribe'):
170 $this->mlist('subscribe',$value);
172 case ('list-unsubscribe'):
173 $this->mlist('unsubscribe',$value);
175 case ('list-archive'):
176 $this->mlist('archive',$value);
179 $this->mlist('owner',$value);
182 $this->mlist('help',$value);
185 $this->mlist('id',$value);
192 function parseAddress($address, $ar=false, $addr_ar = array(), $group = '')
195 $j = strlen( $address );
198 while ( $pos < $j ) {
199 switch ($address{$pos})
201 case ('"'): /* get the personal name */
203 if ($address{$pos} == '"') {
206 while ( $pos < $j && $address{$pos} != '"') {
207 if (substr($address, $pos, 2) == '\\"') {
208 $name .= $address{$pos};
210 } elseif (substr($address, $pos, 2) == '\\\\') {
211 $name .= $address{$pos};
214 $name .= $address{$pos};
220 case ('<'): /* get email address */
223 while ( $pos < $j && $address{$pos} != '>' ) {
224 $addr .= $address{$pos};
229 case ('('): /* rip off comments */
232 while ( $pos < $j && $address{$pos} != ')' ) {
233 $addr .= $address{$pos};
236 $address_start = substr($address,0,$addr_start);
237 $address_end = substr($address,$pos+
1);
238 $address = $address_start . $address_end;
239 $j = strlen( $address );
243 case (','): /* we reached a delimiter */
245 $addr = substr($address,0,$pos);
246 } elseif ($name == '') {
247 $name = substr($address,0,$addr_start);
250 $at = strpos($addr, '@');
251 $addr_structure = new address_structure();
252 $addr_structure->personal
= $name;
253 $addr_structure->group
= $group;
255 $addr_structure->mailbox
= substr($addr,0,$at);
256 $addr_structure->host
= substr($addr,$at+
1);
258 $addr_structure->mailbox
= $addr;
260 $address = trim(substr($address,$pos+
1));
261 $j = strlen( $address );
265 $addr_ar[] = $addr_structure;
267 case (':'): /* process the group addresses */
269 $group = substr($address,0,$pos);
270 $address = substr($address,$pos+
1);
271 $result = $this->parseAddress($address, $ar, $addr_ar, $group);
272 $addr_ar = $result[0];
274 $address = substr($address,$pos);
275 $j = strlen( $address );
281 $address = substr($address, 0, $pos-1);
292 $addr = substr($address,0,$pos);
293 } elseif ($name == '') {
294 $name = substr($address,0,$addr_start);
296 $at = strpos($addr, '@');
297 $addr_structure = new address_structure();
298 $addr_structure->group
= $group;
300 $addr_structure->mailbox
= trim(substr($addr,0,$at));
301 $addr_structure->host
= trim(substr($addr,$at+
1));
303 $addr_structure->mailbox
= trim($addr);
305 if ($group && $addr == '') { /* no addresses found in group */
306 $name = "$group: Undisclosed recipients;";
307 $addr_structure->personal
= $name;
308 $addr_ar[] = $addr_structure;
309 return (array($addr_ar,$pos+
1));
311 $addr_structure->personal
= $name;
312 if ($name ||
$addr) {
313 $addr_ar[] = $addr_structure;
319 return ($addr_ar[0]);
323 function parseContentType($value) {
324 $pos = strpos($value,';');
327 $type = trim(substr($value,0,$pos));
328 $props = trim(substr($type,$pos+
1));
332 $content_type = new content_type($type);
334 $properties = $this->parseProperties($props);
335 if (!isset($properties['charset'])) {
336 $properties['charset'] = 'us-ascii';
338 $content_type->properties
= $this->parseProperties($props);
340 $this->content_type
= $content_type;
343 function parseProperties($value) {
344 $propArray = explode(';',$value);
345 $propResultArray = array();
346 foreach ($propArray as $prop) {
348 $pos = strpos($prop,'=');
350 $key = trim(substr($prop,0,$pos));
351 $val = trim(substr($prop,$pos+
1));
352 if ($val{0} == '"') {
353 $val = substr($val,1,-1);
355 $propResultArray[$key] = $val;
358 return $propResultArray;
361 function parseDisposition($value) {
362 $pos = strpos($value,';');
365 $name = trim(substr($value,0,$pos));
366 $props = trim(substr($type,$pos+
1));
370 $props_a = $this->parseProperties($props);
371 $disp = new disposition($name);
372 $disp->properties
= $props_a;
373 $this->disposition
= $disp;
376 function mlist($field, $value) {
378 $value_a = explode(',',$value);
379 foreach ($value_a as $val) {
381 if ($val{0} == '<') {
382 $val = substr($val,1,-1);
384 if (substr($val,0,7) == 'mailto:') {
385 $res_a['mailto'] = substr($val,7);
387 $res_a['href'] = $val;
390 $this->mlist
[$field] = $res_a;
394 * function to get the addres strings out of the header.
395 * Arguments: string or array of strings !
396 * example1: header->getAddr_s('to').
397 * example2: header->getAddr_s(array('to','cc','bcc'))
399 function getAddr_s($arr, $separator=', ') {
400 if (is_array($arr)) {
402 foreach($arr as $arg ) {
403 $result = $this->getAddr_s($arg);
405 $s .= $separator . $result;
408 if ($s) $s = substr($s,2);
412 eval('$addr = $this->'.$arr.';') ;
413 if (is_array($addr)) {
414 foreach ($addr as $addr_o) {
415 if (is_object($addr_o)) {
416 $s .= $addr_o->getAddress() . $separator;
419 $s = substr($s,0,-strlen($separator));
421 if (is_object($addr)) {
422 $s .= $addr->getAddress();
429 function getAddr_a($arg, $excl_arr=array(), $arr = array()) {
430 if (is_array($arg)) {
431 foreach($arg as $argument ) {
432 $arr = $this->getAddr_a($argument, $excl_arr, $arr);
436 eval('$addr = $this->'.$arg.';') ;
437 if (is_array($addr)) {
438 foreach ($addr as $addr_o) {
439 if (is_object($addr_o)) {
440 if (isset($addr_o->host
) && $addr_o->host
!='') {
441 $email = $addr_o->mailbox
.'@'.$addr_o->host
;
443 $email = $addr_o->mailbox
;
445 $email = strtolower($email);
446 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
447 $arr[$email] = $addr_o->personal
;
452 if (is_object($addr)) {
453 if (isset($addr->host
)) {
454 $email = $addr->mailbox
.'@'.$addr->host
;
456 $email = $addr->mailbox
;
458 $email = strtolower($email);
459 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
460 $arr[$email] = $addr->personal
;
468 function getContentType($type0, $type1) {
469 $type0 = $this->content_type
->type0
;
470 $type1 = $this->content_type
->type1
;
471 return $this->content_type
->properties
;
476 /** msg_header contains all variables available in a bodystructure **/
477 /** entity like described in rfc2060 **/
481 $parameters = array(),
491 * returns addres_list of supplied argument
492 * arguments: array('to', 'from', ...) or just a string like 'to'.
493 * result: string: address1, addres2, ....
496 function setVar($var, $value) {
497 $this->{$var} = $value;
500 function getParameter($par) {
501 $value = strtolower($par);
502 if (isset($this->parameters
[$par])) {
503 return $this->parameters
[$par];
508 function setParameter($parameter, $value) {
509 $this->parameters
[strtolower($parameter)] = $value;
515 class address_structure
{
516 var $personal = '', $adl = '', $mailbox = '', $host = '', $group = '';
518 function getAddress($full=true) {
519 if (is_object($this)) {
520 if (isset($this->host
) && $this->host
!='') {
521 $email = $this->mailbox
.'@'.$this->host
;
523 $email = $this->mailbox
;
525 if (trim($this->personal
) !='') {
527 $addr = '"' . $this->personal
. '" <' .$email.'>';
529 $addr = $this->personal
;
531 $best_dpl = $this->personal
;
546 /** message is the object that contains messages. It is a recursive
547 object in that through the $entities variable, it can contain
548 more objects of type message. See documentation in mime.txt for
549 a better description of how this works.
551 var $rfc822_header = '',
557 $parent_ent, $entity,
558 $parent = '', $decoded_body='',
559 $is_seen = 0, $is_answered = 0, $is_deleted = 0, $is_flagged = 0,
563 function setEnt($ent) {
564 $this->entity_id
= $ent;
567 function addEntity ($msg) {
568 $msg->parent
= &$this;
569 $this->entities
[] = $msg;
572 function addRFC822Header($read) {
573 $header = new msg_header();
574 $this->header
= sqimap_parse_RFC822Header($read,$header);
577 function getEntity($ent) {
579 $cur_ent = $this->entity_id
;
581 if ($cur_ent == '' ||
$cur_ent == '0') {
582 $cur_ent_a = array();
584 $cur_ent_a = explode('.',$this->entity_id
);
586 $ent_a = explode('.',$ent);
588 $cnt = count($ent_a);
590 for ($i=0;$i<$cnt -1;$i++
) {
591 if (isset($cur_ent_a[$i]) && $cur_ent_a[$i] != $ent_a[$i]) {
593 $cur_ent_a = explode('.',$msg->entity_id
);
595 } else if (!isset($cur_ent_a[$i])) {
596 if (isset($msg->entities
[($ent_a[$i]-1)])) {
597 $msg = $msg->entities
[($ent_a[$i]-1)];
599 $msg = $msg->entities
[0];
602 if ($msg->type0
== 'message' && $msg->type1
== 'rfc822') {
603 /*this is a header for a message/rfc822 entity */
604 $msg = $msg->entities
[0];
608 if ($msg->type0
== 'message' && $msg->type1
== 'rfc822') {
609 /*this is a header for a message/rfc822 entity */
610 $msg = $msg->entities
[0];
613 if (isset($msg->entities
[($ent_a[$cnt-1])-1])) {
614 $msg = $msg->entities
[($ent_a[$cnt-1]-1)];
620 function setBody($s) {
621 $this->body_part
= $s;
624 function clean_up() {
626 $msg->body_part
= '';
628 while ( isset($msg->entities
[$i])) {
629 $msg->entities
[$i]->clean_up();
634 function getMailbox() {
636 while (is_object($msg->parent
)) {
639 return $msg->mailbox
;
643 * Bodystructure parser, a recursive function for generating the
644 * entity-tree with all the mime-parts.
646 * It follows RFC2060 and stores all the described fields in the
651 * Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net.
654 function &parseStructure($read, $i=0, $message = false) {
657 $cnt = strlen($read);
659 $char = strtoupper($read{$i});
664 $msg = new message();
665 $hdr = new msg_header();
666 $hdr->type0
= 'text';
667 $hdr->type1
= 'plain';
668 $hdr->encoding
= 'us-ascii';
670 if ($this->type0
== 'message' && $this->type1
== 'rfc822') {
671 $msg->entity_id
= $this->entity_id
.'.0'; /* header of message/rfc822 */
672 } else if (isset($this->entity_id
) && $this->entity_id
!='') {
673 $ent_no = count($this->entities
)+
1;
674 $par_ent = substr($this->entity_id
,-2);
675 if ($par_ent{0} == '.') {
676 $par_ent = $par_ent{1};
678 if ($par_ent == '0') {
679 $ent_no = count($this->entities
)+
1;
681 $ent = substr($this->entity_id
,0,strrpos($this->entity_id
,'.'));
683 $ent = $ent . ".$ent_no";
687 $msg->entity_id
= $ent;
689 $msg->entity_id
= $ent_no;
692 $ent = $this->entity_id
. ".$ent_no";
693 $msg->entity_id
= $ent;
696 $msg->entity_id
= '0';
699 $msg->header
->type0
= 'multipart';
700 $msg->type0
= 'multipart';
701 while ($read{$i} == '(') {
702 $msg->addEntity($msg->parseStructure($read,&$i));
709 /* multipart properties */
711 $arg_a[] = $this->parseProperties($read,&$i);
715 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
717 $arg_a[]= $msg->parseDisposition($read,&$i);
718 } else { /* properties */
720 $arg_a[] = $msg->parseProperties($read,&$i);
725 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
727 $arg_a[]= $msg->parseLanguage($read,&$i);
730 if ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822') {
732 $msg->header
->type0
= $arg_a[0];
733 $msg->type0
= $arg_a[0];
735 $msg->header
->type1
= $arg_a[1];
736 $msg->type1
= $arg_a[1];
737 $rfc822_hdr = new rfc822_header();
738 $msg->parseEnvelope($read,&$i,&$rfc822_hdr);
739 $msg->rfc822_header
= $rfc822_hdr;
741 while ($i < $cnt && $read{$i} != '(') {
744 $msg->addEntity($msg->parseStructure($read,&$i));
749 $arg_a[] = $msg->parseDisposition($read,&$i);
753 if ($arg_a[0] == 'text' ||
754 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
756 $arg_a[] = $msg->parseDisposition($read,&$i);
759 $arg_a[] = $msg->parseLanguage($read,&$i);
764 if ($arg_a[0] == 'text' ||
765 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
767 $arg_a[] = $msg->parseLanguage($read,&$i);
769 $msg->parseParenthesis($read,&$i);
770 $arg_a[] = ''; /* not yet desribed in rfc2060 */
775 /* unknown argument, skip this part */
776 $msg->parseParenthesis($read,&$i);
784 /* inside an entity -> start processing */
785 $debug = substr($read,$i,20);
786 $arg_s = $msg->parseQuote($read,&$i);
788 if ($arg_no < 3) $arg_s = strtolower($arg_s); /* type0 and type1 */
793 /* probably NIL argument */
794 if (strtoupper(substr($read,$i,4)) == 'NIL ' ||
795 strtoupper(substr($read,$i,4)) == 'NIL)') {
802 /* process the literal value */
803 $arg_a[] = $msg->parseLiteral($read,&$i);
806 case (is_numeric($read{$i}) ):
807 /* process integers */
808 if ($read{$i} == ' ') break;
811 while (preg_match('/^[0-9]{1}$/',$read{$i})) {
819 if (isset($msg->type0
) && $msg->type0
== 'multipart') {
825 if ($arg_a[0] == 'text' ||
826 ($arg_a[0] == 'message' && $arg_a[1] == 'rfc822')) {
827 $shifted_args = true;
829 $shifted_args = false;
831 $hdr->type0
= $arg_a[0];
832 $hdr->type1
= $arg_a[1];
834 $msg->type0
= $arg_a[0];
835 $msg->type1
= $arg_a[1];
838 if (is_array($arr)) {
839 $hdr->parameters
= $arg_a[2];
841 $hdr->id
= str_replace( '<', '', str_replace( '>', '', $arg_a[3] ) );
842 $hdr->description
= $arg_a[4];
843 $hdr->encoding
= strtolower($arg_a[5]);
844 $hdr->entity_id
= $msg->entity_id
;
845 $hdr->size
= $arg_a[6];
847 $hdr->lines
= $arg_a[7];
848 if (isset($arg_a[8])) {
849 $hdr->md5
= $arg_a[8];
851 if (isset($arg_a[9])) {
852 $hdr->disposition
= $arg_a[9];
854 if (isset($arg_a[10])) {
855 $hdr->language
= $arg_a[10];
858 if (isset($arg_a[7])) {
859 $hdr->md5
= $arg_a[7];
861 if (isset($arg_a[8])) {
862 $hdr->disposition
= $arg_a[8];
864 if (isset($arg_a[9])) {
865 $hdr->language
= $arg_a[9];
871 if (substr($msg->entity_id
,-2) == '.0' && $msg->type0
!='multipart') {
876 $hdr->type0
= 'multipart';
877 $hdr->type1
= $arg_a[0];
879 $msg->type0
= 'multipart';
880 $msg->type1
= $arg_a[0];
881 if (is_array($arg_a[1])) {
882 $hdr->parameters
= $arg_a[1];
884 if (isset($arg_a[2])) {
885 $hdr->disposition
= $arg_a[2];
887 if (isset($arg_a[3])) {
888 $hdr->language
= $arg_a[3];
898 } /* parsestructure */
900 function parseProperties($read, $i) {
901 $properties = array();
904 while ($read{$i} != ')') {
905 if ($read{$i} == '"') {
906 $arg_s = $this->parseQuote($read,&$i);
907 } else if ($read{$i} == '{') {
908 $arg_s = $this->parseLiteral($read,&$i);
910 if ($prop_name == '' && $arg_s) {
911 $prop_name = strtolower($arg_s);
912 $properties[$prop_name] = '';
914 } elseif ($prop_name != '' && $arg_s != '') {
915 $properties[$prop_name] = $arg_s;
924 function parseEnvelope($read, $i, $hdr) {
927 $cnt = strlen($read);
928 while ($i< $cnt && $read{$i} != ')') {
930 $char = strtoupper($read{$i});
934 $arg_a[] = $this->parseQuote($read,&$i);
938 $arg_a[] = $this->parseLiteral($read,&$i);
942 /* probably NIL argument */
943 if (strtoupper(substr($read,$i,3)) == 'NIL') {
951 * With group support.
952 * Note: Group support is useless on SMTP connections
953 * because the protocol doesn't support it
958 while ($i < $cnt && $read{$i} != ')') {
959 if ($read{$i} == '(') {
960 $addr = $this->parseAddress($read,&$i);
961 if ($addr->host
== '' && $addr->mailbox
!= '') {
963 $group = $addr->mailbox
;
966 } elseif ($group && $addr->host
== '' && $addr->mailbox
== '') {
968 if ($a == $j+
1) { /* no group members */
969 $group_addr->group
= $group;
970 $group_addr->mailbox
= '';
971 $group_addr->personal
= "$group: Undisclosed recipients;";
972 $addr_a[] = $group_addr;
976 $addr->group
= $group;
990 if (count($arg_a) > 9) {
991 /* argument 1: date */
992 $d = strtr($arg_a[0], array(' ' => ' '));
993 $d = explode(' ', $d);
994 $hdr->date
= getTimeStamp($d);
995 /* argument 2: subject */
996 if (!trim($arg_a[1])) {
997 $arg_a[1]= _("(no subject)");
999 $hdr->subject
= $arg_a[1];
1000 /* argument 3: from */
1001 $hdr->from
= $arg_a[2][0];
1002 /* argument 4: sender */
1003 $hdr->sender
= $arg_a[3][0];
1004 /* argument 5: reply-to */
1005 $hdr->replyto
= $arg_a[4][0];
1006 /* argument 6: to */
1007 $hdr->to
= $arg_a[5];
1008 /* argument 7: cc */
1009 $hdr->cc
= $arg_a[6];
1010 /* argument 8: bcc */
1011 $hdr->bcc
= $arg_a[7];
1012 /* argument 9: in-reply-to */
1013 $hdr->inreplyto
= $arg_a[8];
1014 /* argument 10: message-id */
1015 $hdr->message_id
= $arg_a[9];
1019 function parseLiteral($read, $i) {
1022 while ($read{$i} != '}') {
1023 $lit_cnt .= $read{$i};
1026 $lit_cnt +
=2; /* add the { and } characters */
1028 for ($j = 0; $j < $lit_cnt; $j++
) {
1035 function parseQuote($read, $i) {
1038 while ($read{$i} != '"') {
1039 if ($read{$i} == '\\') {
1048 function parseAddress($read, $i) {
1050 while ($read{$i} != ')' ) { //&& $i < count($read)) {
1051 $char = strtoupper($read{$i});
1055 $arg_a[] = $this->parseQuote($read,&$i);
1058 $arg_a[] = $this->parseLiteral($read,&$i);
1062 if (strtoupper(substr($read,$i,3)) == 'NIL') {
1072 if (count($arg_a) == 4) {
1073 $adr = new address_structure();
1074 $adr->personal
= $arg_a[0];
1075 $adr->adl
= $arg_a[1];
1076 $adr->mailbox
= $arg_a[2];
1077 $adr->host
= $arg_a[3];
1084 function parseDisposition($read,&$i) {
1086 while ($read{$i} != ')') {
1090 $arg_a[] = $this->parseQuote($read,&$i);
1093 $arg_a[] = $this->parseLiteral($read,&$i);
1096 $arg_a[] = $this->parseProperties($read,&$i);
1103 if (isset($arg_a[0])) {
1104 $disp = new disposition($arg_a[0]);
1105 if (isset($arg_a[1])) {
1106 $disp->properties
= $arg_a[1];
1109 if (is_object($disp)) {
1114 function parseLanguage($read,&$i) {
1115 /* no idea how to process this one without examples */
1117 while ($read{$i} != ')') {
1121 $arg_a[] = $this->parseQuote($read,&$i);
1124 $arg_a[] = $this->parseLiteral($read,&$i);
1127 $arg_a[] = $this->parseProperties($read,&$i);
1134 if (isset($arg_a[0])) {
1135 $lang = new language($arg_a[0]);
1136 if (isset($arg_a[1])) {
1137 $lang->properties
= $arg_a[1];
1140 if (is_object($lang)) {
1147 function parseParenthesis($read,&$i) {
1148 while ($read{$i} != ')') {
1152 $this->parseQuote($read,&$i);
1155 $this->parseLiteral($read,&$i);
1158 $this->parseParenthesis($read,&$i);
1167 function findDisplayEntity ($entity = array(), $alt_order = array('text/plain','text/html')) {
1169 $type = $this->type0
.'/'.$this->type1
;
1170 if ( $type == 'multipart/alternative') {
1171 $msg = $this->findAlternativeEntity($alt_order);
1172 if (count($msg->entities
) == 0) {
1173 $entity[] = $msg->entity_id
;
1175 $msg->findDisplayEntity(&$entity, $alt_order);
1178 } else if ( $type == 'multipart/related') {
1179 $msgs = $this->findRelatedEntity();
1180 for ($i = 0; $i < count($msgs); $i++
) {
1182 if (count($msg->entities
) == 0) {
1183 $entity[] = $msg->entity_id
;
1185 $msg->findDisplayEntity(&$entity,$alt_order);
1189 } else if ( $this->type0
== 'text' &&
1190 ( $this->type1
== 'plain' ||
1191 $this->type1
== 'html' ||
1192 $this->type1
== 'message') &&
1193 isset($this->entity_id
) ) {
1194 if (count($this->entities
) == 0) {
1195 if (strtolower($this->header
->disposition
->name
) != 'attachment') {
1196 $entity[] = $this->entity_id
;
1201 while ( isset($this->entities
[$i]) && !$found &&
1202 (strtolower($this->entities
[$i]->header
->disposition
->name
)
1204 ($this->entities
[$i]->type0
!= 'message' &&
1205 $this->entities
[$i]->type1
!= 'rfc822' )
1208 $this->entities
[$i]->findDisplayEntity(&$entity, $alt_order);
1212 if ( !isset($entity[0]) ) {
1218 function findAlternativeEntity ($alt_order) {
1219 /* if we are dealing with alternative parts then we choose the best
1220 * viewable message supported by SM.
1225 for ($i = 0; $i < count($this->entities
); $i ++
) {
1226 $type = $this->entities
[$i]->header
->type0
.'/'.$this->entities
[$i]->header
->type1
;
1227 if ($type == 'multipart/related') {
1228 $type = $this->entities
[$i]->header
->getParameter('type');
1230 for ($j = $k; $j < count($alt_order); $j++
) {
1231 if ($alt_order[$j] == $type && $j > $best_view) {
1238 return $this->entities
[$ent_id];
1241 function findRelatedEntity () {
1243 for ($i = 0; $i < count($this->entities
); $i ++
) {
1244 $type = $this->entities
[$i]->header
->type0
.'/'.$this->entities
[$i]->header
->type1
;
1245 if ($this->header
->getParameter('type') == $type) {
1246 $msgs[] = $this->entities
[$i];
1252 function getAttachments($exclude_id=array(), $result = array()) {
1253 if ($this->type0
== 'message' && $this->type1
== 'rfc822') {
1254 $this = $this->entities
[0];
1256 if (count($this->entities
)) {
1257 foreach ($this->entities
as $entity) {
1259 foreach ($exclude_id as $excl) {
1260 if ($entity->entity_id
== $excl) {
1265 if ($entity->type0
== 'multipart' &&
1266 $entity->type1
!= 'related') {
1267 $result = $entity->getAttachments($exclude_id, $result);
1268 } else if ($entity->type0
!= 'multipart') {
1269 $result[] = $entity;
1275 foreach ($exclude_id as $excl) {
1276 if ($this->entity_id
== $excl) {
1290 function disposition($name) {
1291 $this->name
= $name;
1292 $this->properties
= array();
1297 function language($name) {
1298 $this->name
= $name;
1299 $this->properties
= array();
1303 class content_type
{
1307 function content_type($type) {
1308 $pos = strpos($type,'/');
1310 $this->type0
= substr($type,0,$pos);
1311 $this->type1
= substr($type,$pos+
1);
1313 $this->type0
= $type;
1315 $this->properties
= array();