correctly detect \Noselect in LSUB responses, and set $mbx->is_noselect
[squirrelmail.git] / class / mime.class.php
CommitLineData
8f6b86cc 1<?php
2
3/**
1a09384c 4 * mime.class
8f6b86cc 5 *
6 * Copyright (c) 2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
8f6b86cc 9 * This contains functions needed to handle mime messages.
10 *
11 * $Id$
12 */
13
e219fb97 14/*
e8bedb2d 15 * rdc822_header class
16 * input: header_string or array
17 */
b65ca362 18class rfc822_header {
e8bedb2d 19 var $date = '',
20 $subject = '',
b65ca362 21 $from = array(),
22 $sender = '',
23 $reply_to = array(),
24 $to = array(),
25 $cc = array(),
26 $bcc = array(),
27 $in_reply_to = '',
28 $message_id = '',
29 $mime = false,
30 $content_type = '',
31 $disposition = '',
32 $xmailer = '',
33 $priority = 3,
34 $dnt = '',
35 $mlist = array(),
e219fb97 36 $more_headers = array(); /* only needed for constructing headers
b65ca362 37 in smtp.php */
38 function parseHeader($hdr) {
39 if (is_array($hdr)) {
40 $hdr = implode('', $hdr);
1d9392e4 41 }
b65ca362 42
43 /* First we unfold the header */
44 $hdr = trim(str_replace(array("\r\n\t", "\r\n "),array('', ''), $hdr));
45
46 /* Now we can make a new header array with */
47 /* each element representing a headerline */
e219fb97 48 $hdr = explode("\r\n" , $hdr);
b65ca362 49 foreach ($hdr as $line) {
50 $pos = strpos($line, ':');
51 if ($pos > 0) {
52 $field = substr($line, 0, $pos);
53 $value = trim(substr($line, $pos+1));
54 if(!preg_match('/^X.*/i', $field) &&
4b8699db 55 !preg_match('/^Subject/i', $field)) {
1d9392e4 56 $value = $this->stripComments($value);
57 }
b65ca362 58 $this->parseField($field, $value);
1d9392e4 59 }
60 }
b65ca362 61 if ($this->content_type == '') {
1d9392e4 62 $this->parseContentType('text/plain; charset=us-ascii');
63 }
e8bedb2d 64 }
e219fb97 65
b65ca362 66 function stripComments($value) {
67 $result = '';
d625cff3 68 for ($i = 0, $cnt = strlen($value); $i < $cnt; $i++) {
e219fb97 69 switch ($value{$i}) {
70 case '"':
71 $result .= '"';
20760c79 72 while ((++$i < $cnt) && ($value{$i} != '"')) {
e219fb97 73 if ($value{$i} == '\\') {
74 $result .= '\\';
20760c79 75 $i++;
e219fb97 76 }
77 $result .= $value{$i};
e219fb97 78 }
79 $result .= $value{$i};
80 break;
81 case '(':
20760c79 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 }
e219fb97 97 }
98 break;
99 default:
100 $result .= $value{$i};
101 break;
102 }
103 }
104 return $result;
4b8699db 105 }
e219fb97 106
b65ca362 107 function parseField($field, $value) {
e8bedb2d 108 $field = strtolower($field);
b65ca362 109 switch($field) {
110 case 'date':
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 'to':
128 $this->to = $this->parseAddress($value, true);
129 break;
130 case 'cc':
131 $this->cc = $this->parseAddress($value, true);
132 break;
133 case 'bcc':
134 $this->bcc = $this->parseAddress($value, true);
135 break;
136 case 'in-reply-to':
137 $this->in_reply_to = $value;
138 break;
e219fb97 139 case 'message-id':
b65ca362 140 $this->message_id = $value;
141 break;
142 case 'disposition-notification-to':
143 $this->dnt = $this->parseAddress($value);
144 break;
e219fb97 145 case 'mime-version':
b65ca362 146 $value = str_replace(' ', '', $value);
147 $this->mime = ($value == '1.0' ? true : $this->mime);
148 break;
149 case 'content-type':
150 $this->parseContentType($value);
151 break;
152 case 'content-disposition':
153 $this->parseDisposition($value);
e219fb97 154 break;
b65ca362 155 case 'user-agent':
156 case 'x-mailer':
157 $this->xmailer = $value;
158 break;
159 case 'x-priority':
160 $this->priority = $value;
161 break;
162 case 'list-post':
163 $this->mlist('post', $value);
164 break;
165 case 'list-reply':
e219fb97 166 $this->mlist('reply', $value);
b65ca362 167 break;
168 case 'list-subscribe':
169 $this->mlist('subscribe', $value);
170 break;
171 case 'list-unsubscribe':
172 $this->mlist('unsubscribe', $value);
173 break;
174 case 'list-archive':
175 $this->mlist('archive', $value);
176 break;
177 case 'list-owner':
178 $this->mlist('owner', $value);
179 break;
180 case 'list-help':
181 $this->mlist('help', $value);
182 break;
183 case 'list-id':
184 $this->mlist('id', $value);
185 break;
186 default:
187 break;
188 }
e219fb97 189 }
e8bedb2d 190
b65ca362 191 function parseAddress
192 ($address, $ar=false, $addr_ar = array(), $group = '') {
e8bedb2d 193 $pos = 0;
b65ca362 194 $j = strlen($address);
e8bedb2d 195 $name = '';
196 $addr = '';
b65ca362 197 while ($pos < $j) {
198 switch ($address{$pos}) {
199 case '"': /* get the personal name */
200 if ($address{++$pos} == '"') {
201 ++$pos;
202 } else {
203 while ($pos < $j && $address{$pos} != '"') {
204 if ((substr($address, $pos, 2) == '\\"') ||
205 (substr($address, $pos, 2) == '\\\\')) {
206 $name .= $address{$pos++};
207 }
208 $name .= $address{$pos++};
209 }
210 }
211 ++$pos;
212 break;
213 case '<': /* get email address */
214 $addr_start = $pos++;
215 while ($pos < $j && $address{$pos} != '>') {
216 $addr .= $address{$pos++};
217 }
218 ++$pos;
219 break;
220 case '(': /* rip off comments */
221 $addr_start = $pos;
222 for (++$pos; $pos < $j && $address{$pos} != ')'; ++$pos) {
e219fb97 223 $addr .= $address{$pos};
b65ca362 224 }
225 $address_start = substr($address, 0, $addr_start);
226 $address_end = substr($address, $pos + 1);
e219fb97 227 $address = $address_start . $address_end;
b65ca362 228 $j = strlen($address);
229 $pos = $addr_start + 1;
230 break;
231 case ',': /* we reached a delimiter */
232 if ($addr == '') {
233 $addr = substr($address, 0, $pos);
234 } else if ($name == '') {
235 $name = trim(substr($address, 0, $addr_start));
236 }
237
238 $at = strpos($addr, '@');
239 $addr_structure = new address_structure();
240 $addr_structure->personal = $name;
241 $addr_structure->group = $group;
242 if ($at) {
243 $addr_structure->mailbox = substr($addr, 0, $at);
244 $addr_structure->host = substr($addr, $at+1);
245 } else {
246 $addr_structure->mailbox = $addr;
247 }
248 $address = trim(substr($address, $pos+1));
249 $j = strlen($address);
250 $pos = 0;
251 $name = '';
252 $addr = '';
253 $addr_ar[] = $addr_structure;
254 break;
255 case ':': /* process the group addresses */
256 /* group marker */
257 $group = substr($address, 0, $pos);
258 $address = substr($address, $pos+1);
259 $result = $this->parseAddress($address, $ar, $addr_ar, $group);
260 $addr_ar = $result[0];
261 $pos = $result[1];
262 $address = substr($address, $pos++);
e219fb97 263 $j = strlen($address);
b65ca362 264 $group = '';
265 break;
266 case ';':
267 if ($group) {
268 $address = substr($address, 0, $pos - 1);
269 }
270 ++$pos;
271 break;
272 default:
273 ++$pos;
274 break;
275 }
e8bedb2d 276 }
b65ca362 277 if ($addr == '') {
278 $addr = substr($address, 0, $pos);
279 } else if ($name == '') {
280 $name = trim(substr($address, 0, $addr_start));
e8bedb2d 281 }
282 $at = strpos($addr, '@');
283 $addr_structure = new address_structure();
284 $addr_structure->group = $group;
b65ca362 285 if ($at) {
286 $addr_structure->mailbox = trim(substr($addr, 0, $at));
287 $addr_structure->host = trim(substr($addr, $at+1));
288 } else {
289 $addr_structure->mailbox = trim($addr);
e8bedb2d 290 }
b65ca362 291 if ($group && $addr == '') { /* no addresses found in group */
292 $name = "$group: Undisclosed recipients;";
293 $addr_structure->personal = $name;
e219fb97 294 $addr_ar[] = $addr_structure;
295 return (array($addr_ar, $pos+1));
b65ca362 296 } else {
297 $addr_structure->personal = $name;
298 if ($name || $addr) {
299 $addr_ar[] = $addr_structure;
e219fb97 300 }
e8bedb2d 301 }
b65ca362 302 if ($ar) {
303 return ($addr_ar);
304 }
b65ca362 305 return ($addr_ar[0]);
8f6b86cc 306 }
e219fb97 307
b65ca362 308 function parseContentType($value) {
309 $pos = strpos($value, ';');
310 $props = '';
311 if ($pos > 0) {
312 $type = trim(substr($value, 0, $pos));
313 $props = trim(substr($type, $pos+1));
314 } else {
315 $type = $value;
316 }
317 $content_type = new content_type($type);
318 if ($props) {
319 $properties = $this->parseProperties($props);
320 if (!isset($properties['charset'])) {
321 $properties['charset'] = 'us-ascii';
322 }
323 $content_type->properties = $this->parseProperties($props);
324 }
325 $this->content_type = $content_type;
326 }
e219fb97 327
b65ca362 328 function parseProperties($value) {
329 $propArray = explode(';', $value);
330 $propResultArray = array();
331 foreach ($propArray as $prop) {
332 $prop = trim($prop);
333 $pos = strpos($prop, '=');
334 if ($pos > 0) {
335 $key = trim(substr($prop, 0, $pos));
336 $val = trim(substr($prop, $pos+1));
337 if ($val{0} == '"') {
338 $val = substr($val, 1, -1);
339 }
340 $propResultArray[$key] = $val;
341 }
342 }
343 return $propResultArray;
344 }
e219fb97 345
b65ca362 346 function parseDisposition($value) {
347 $pos = strpos($value, ';');
348 $props = '';
349 if ($pos > 0) {
350 $name = trim(substr($value, 0, $pos));
351 $props = trim(substr($type, $pos+1));
352 } else {
353 $name = $value;
354 }
355 $props_a = $this->parseProperties($props);
356 $disp = new disposition($name);
357 $disp->properties = $props_a;
358 $this->disposition = $disp;
359 }
e219fb97 360
b65ca362 361 function mlist($field, $value) {
362 $res_a = array();
363 $value_a = explode(',', $value);
364 foreach ($value_a as $val) {
365 $val = trim($val);
366 if ($val{0} == '<') {
367 $val = substr($val, 1, -1);
368 }
369 if (substr($val, 0, 7) == 'mailto:') {
370 $res_a['mailto'] = substr($val, 7);
371 } else {
372 $res_a['href'] = $val;
373 }
374 }
375 $this->mlist[$field] = $res_a;
376 }
e8bedb2d 377
e219fb97 378 /*
b65ca362 379 * function to get the addres strings out of the header.
380 * Arguments: string or array of strings !
381 * example1: header->getAddr_s('to').
382 * example2: header->getAddr_s(array('to', 'cc', 'bcc'))
383 */
384 function getAddr_s($arr, $separator = ',') {
385 $s = '';
386
387 if (is_array($arr)) {
388 foreach($arr as $arg) {
389 if ($this->getAddr_s($arg)) {
390 $s .= $separator . $result;
391 }
392 }
393 $s = ($s ? substr($s, 2) : $s);
394 } else {
395 eval('$addr = $this->' . $arr . ';') ;
396 if (is_array($addr)) {
397 foreach ($addr as $addr_o) {
398 if (is_object($addr_o)) {
399 $s .= $addr_o->getAddress() . $separator;
400 }
401 }
402 $s = substr($s, 0, -strlen($separator));
403 } else {
404 if (is_object($addr)) {
405 $s .= $addr->getAddress();
406 }
407 }
408 }
b65ca362 409 return $s;
8f6b86cc 410 }
e219fb97 411
b65ca362 412 function getAddr_a($arg, $excl_arr = array(), $arr = array()) {
413 if (is_array($arg)) {
414 foreach($arg as $argument) {
415 $arr = $this->getAddr_a($argument, $excl_arr, $arr);
416 }
417 } else {
418 eval('$addr = $this->' . $arg . ';') ;
419 if (is_array($addr)) {
420 foreach ($addr as $next_addr) {
421 if (is_object($next_addr)) {
422 if (isset($next_addr->host) && ($next_addr->host != '')) {
423 $email = $next_addr->mailbox . '@' . $next_addr->host;
424 } else {
425 $email = $next_addr->mailbox;
426 }
427 $email = strtolower($email);
428 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
429 $arr[$email] = $next_addr->personal;
430 }
431 }
432 }
433 } else {
434 if (is_object($addr)) {
435 $email = $addr->mailbox;
436 $email .= (isset($addr->host) ? '@' . $addr->host : '');
e219fb97 437 $email = strtolower($email);
b65ca362 438 if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) {
439 $arr[$email] = $addr->personal;
440 }
441 }
442 }
443 }
e219fb97 444 return $arr;
8f6b86cc 445 }
e219fb97 446
b65ca362 447 function getContentType($type0, $type1) {
e8bedb2d 448 $type0 = $this->content_type->type0;
b65ca362 449 $type1 = $this->content_type->type1;
e219fb97 450 return $this->content_type->properties;
e8bedb2d 451 }
8f6b86cc 452}
453
b65ca362 454class msg_header {
e8bedb2d 455 /** msg_header contains all variables available in a bodystructure **/
456 /** entity like described in rfc2060 **/
457
e219fb97 458 var $type0 = '',
459 $type1 = '',
b65ca362 460 $parameters = array(),
e219fb97 461 $id = 0,
462 $description = '',
463 $encoding='',
b65ca362 464 $size = 0,
e219fb97 465 $md5='',
466 $disposition = '',
b65ca362 467 $language='';
e219fb97 468
469 /*
e8bedb2d 470 * returns addres_list of supplied argument
471 * arguments: array('to', 'from', ...) or just a string like 'to'.
472 * result: string: address1, addres2, ....
e219fb97 473 */
474
b65ca362 475 function setVar($var, $value) {
e8bedb2d 476 $this->{$var} = $value;
477 }
e219fb97 478
b65ca362 479 function getParameter($p) {
480 $value = strtolower($p);
481 return (isset($this->parameters[$p]) ? $this->parameters[$p] : '');
e8bedb2d 482 }
e219fb97 483
b65ca362 484 function setParameter($parameter, $value) {
e8bedb2d 485 $this->parameters[strtolower($parameter)] = $value;
486 }
487}
488
489
490
b65ca362 491class address_structure {
492 var $personal = '',
493 $adl = '',
494 $mailbox = '',
495 $host = '',
496 $group = '';
8f6b86cc 497
b65ca362 498 function getAddress($full = true) {
499 $result = '';
500
501 if (is_object($this)) {
20760c79 502 if (isset($this->host) && ($this->host != '')) {
b65ca362 503 $email = $this->mailbox.'@'.$this->host;
504 } else {
505 $email = $this->mailbox;
506 }
507 if (trim($this->personal) != '') {
508 if ($email) {
509 $addr = '"' . $this->personal . '" <' .$email.'>';
510 } else {
511 $addr = $this->personal;
512 }
513 $best_dpl = $this->personal;
514 } else {
515 $addr = $email;
516 $best_dpl = $email;
517 }
518 $result = ($full ? $addr : $best_dpl);
319cf0d2 519 }
e219fb97 520 return $result;
b65ca362 521 }
8f6b86cc 522}
523
b65ca362 524class message {
8f6b86cc 525 /** message is the object that contains messages. It is a recursive
b65ca362 526 object in that through the $entities variable, it can contain
527 more objects of type message. See documentation in mime.txt for
528 a better description of how this works.
8f6b86cc 529 **/
e219fb97 530 var $rfc822_header = '',
e8bedb2d 531 $mime_header = '',
b65ca362 532 $flags = '',
e8bedb2d 533 $type0='',
e219fb97 534 $type1='',
535 $entities = array(),
536 $parent_ent, $entity,
b65ca362 537 $parent = '', $decoded_body='',
538 $is_seen = 0, $is_answered = 0, $is_deleted = 0, $is_flagged = 0,
539 $is_mdnsent = 0,
540 $body_part = '',
541 $offset = 0, /* for fetching body parts out of raw messages */
cf20a40a 542 $length = 0, /* for fetching body parts out of raw messages */
543 $att_local_name = ''; /* location where the tempory attachment
544 is stored. For future usage in smtp.php */
b65ca362 545
546 function setEnt($ent) {
8f6b86cc 547 $this->entity_id= $ent;
548 }
e219fb97 549
b65ca362 550 function addEntity ($msg) {
8f6b86cc 551 $msg->parent = &$this;
552 $this->entities[] = $msg;
553 }
554
b65ca362 555 function getFilename() {
556 $filename = '';
62cfbd1d 557 $filename = $this->header->getParameter('filename');
6479ed81 558 if (!$filename) {
559 $filename = $this->header->getParameter('name');
b65ca362 560 }
6479ed81 561
b65ca362 562 if (!$filename) {
563 $filename = 'untitled-'.$this->entity_id;
564 }
b65ca362 565 return $filename;
812843b7 566 }
567
568
b65ca362 569 function addRFC822Header($read) {
570 $header = new rfc822_header();
571 $this->rfc822_header = $header->parseHeader($read);
8f6b86cc 572 }
573
b65ca362 574 function getEntity($ent) {
8f6b86cc 575 $cur_ent = $this->entity_id;
b65ca362 576 $msg = $this;
20760c79 577 if (($cur_ent == '') || ($cur_ent == '0')) {
b65ca362 578 $cur_ent_a = array();
579 } else {
580 $cur_ent_a = explode('.', $this->entity_id);
581 }
582 $ent_a = explode('.', $ent);
e219fb97 583
62cfbd1d 584 for ($i = 0, $cnt = count($ent_a)-1; $i < $cnt; ++$i) {
b65ca362 585 if (isset($cur_ent_a[$i]) && ($cur_ent_a[$i] != $ent_a[$i])) {
586 $msg = $msg->parent;
587 $cur_ent_a = explode('.', $msg->entity_id);
588 --$i;
589 } else if (!isset($cur_ent_a[$i])) {
590 if (isset($msg->entities[($ent_a[$i]-1)])) {
591 $msg = $msg->entities[($ent_a[$i]-1)];
592 } else {
593 $msg = $msg->entities[0];
594 }
595 }
596 if (($msg->type0 == 'message') && ($msg->type1 == 'rfc822')) {
597 /*this is a header for a message/rfc822 entity */
598 $msg = $msg->entities[0];
599 }
600 }
601
602 if (($msg->type0 == 'message') && ($msg->type1 == 'rfc822')) {
603 /*this is a header for a message/rfc822 entity */
604 $msg = $msg->entities[0];
605 }
606
62cfbd1d 607 if (isset($msg->entities[($ent_a[$cnt])-1])) {
608 if (is_object($msg->entities[($ent_a[$cnt])-1])) {
609 $msg = $msg->entities[($ent_a[$cnt]-1)];
b65ca362 610 }
611 }
08c18186 612
319cf0d2 613 return $msg;
8f6b86cc 614 }
e8bedb2d 615
b65ca362 616 function setBody($s) {
e8bedb2d 617 $this->body_part = $s;
618 }
e219fb97 619
b65ca362 620 function clean_up() {
e8bedb2d 621 $msg = $this;
b65ca362 622 $msg->body_part = '';
623
20760c79 624 foreach ($msg->entities as $m) {
625 $m->clean_up();
b65ca362 626 }
e8bedb2d 627 }
e219fb97 628
b65ca362 629 function getMailbox() {
630 $msg = $this;
631 while (is_object($msg->parent)) {
632 $msg = $msg->parent;
633 }
634 return $msg->mailbox;
319cf0d2 635 }
e219fb97 636
b65ca362 637 function calcEntity($msg) {
638 if (($this->type0 == 'message') && ($this->type1 == 'rfc822')) {
639 $msg->entity_id = $this->entity_id .'.0'; /* header of message/rfc822 */
640 } else if (isset($this->entity_id) && ($this->entity_id != '')) {
641 $ent_no = count($this->entities)+1;
642 $par_ent = substr($this->entity_id, -2);
643 if ($par_ent{0} == '.') {
644 $par_ent = $par_ent{1};
645 }
646 if ($par_ent == '0') {
647 $ent_no = count($this->entities) + 1;
648 if ($ent_no > 0) {
20760c79 649 $ent = substr($this->entity_id, 0, strrpos($this->entity_id, '.'));
b65ca362 650 $ent = ($ent ? $ent . ".$ent_no" : $ent_no);
651 $msg->entity_id = $ent;
652 } else {
653 $msg->entity_id = $ent_no;
e219fb97 654 }
b65ca362 655 } else {
656 $ent = $this->entity_id . ".$ent_no";
657 $msg->entity_id = $ent;
658 }
659 } else {
660 $msg->entity_id = '0';
661 }
662
663 return $msg->entity_id;
c52ffd66 664 }
e219fb97 665
666
667 /*
668 * Bodystructure parser, a recursive function for generating the
8f6b86cc 669 * entity-tree with all the mime-parts.
e219fb97 670 *
8f6b86cc 671 * It follows RFC2060 and stores all the described fields in the
e219fb97 672 * message object.
8f6b86cc 673 *
674 * Question/Bugs:
e219fb97 675 *
018d3a38 676 * Ask for me (Marc Groot Koerkamp, stekkel@users.sourceforge.net)
8f6b86cc 677 *
678 */
b65ca362 679 function parseStructure($read, $i = 0) {
e60230ae 680 $arg_no = 0;
681 $arg_a = array();
d625cff3 682 for ($cnt = strlen($read); $i < $cnt; ++$i) {
e60230ae 683 $char = strtoupper($read{$i});
b65ca362 684 switch ($char) {
685 case '(':
018d3a38 686 switch($arg_no) {
687 case 0:
688 if (!isset($msg)) {
689 $msg = new message();
690 $hdr = new msg_header();
691 $hdr->type0 = 'text';
692 $hdr->type1 = 'plain';
693 $hdr->encoding = 'us-ascii';
694 $msg->entity_id = $this->calcEntity($msg);
695 } else {
696 $msg->header->type0 = 'multipart';
697 $msg->type0 = 'multipart';
698 while ($read{$i} == '(') {
b65ca362 699 $res = $msg->parseStructure($read, $i);
700 $i = $res[1];
701 $msg->addEntity($res[0]);
702 }
018d3a38 703 }
704 break;
705 case 1:
706 /* multipart properties */
707 ++$i;
708 $res = $this->parseProperties($read, $i);
709 $arg_a[] = $res[0];
710 $i = $res[1];
711 ++$arg_no;
712 break;
713 case 2:
714 if (isset($msg->type0) && ($msg->type0 == 'multipart')) {
b65ca362 715 ++$i;
716 $res = $msg->parseDisposition($read, $i);
018d3a38 717 } else { /* properties */
718 $res = $msg->parseProperties($read, $i);
719 }
720 $arg_a[] = $res[0];
721 $i = $res[1];
722 ++$arg_no;
723 break;
724 case 3:
725 if (isset($msg->type0) && ($msg->type0 == 'multipart')) {
726 ++$i;
727 $res= $msg->parseLanguage($read, $i);
b65ca362 728 $arg_a[] = $res[0];
729 $i = $res[1];
018d3a38 730 }
731 case 7:
732 if (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822')) {
733 $msg->header->type0 = $arg_a[0];
734 $msg->header->type1 = $arg_a[1];
735 $msg->type0 = $arg_a[0];
736 $msg->type1 = $arg_a[1];
737 $rfc822_hdr = new rfc822_header();
738 $res = $msg->parseEnvelope($read, $i, $rfc822_hdr);
739 $msg->rfc822_header = $res[0];
740 $i = $res[1] + 1;
741 while (($i < $cnt) && ($read{$i} != '(')) {
742 ++$i;
b65ca362 743 }
018d3a38 744 $res = $msg->parseStructure($read, $i);
b65ca362 745 $i = $res[1];
018d3a38 746 $msg->addEntity($res[0]);
747 }
748 break;
749 case 8:
750 ++$i;
751 $res = $msg->parseDisposition($read, $i);
752 $arg_a[] = $res[0];
753 $i = $res[1];
754 ++$arg_no;
755 break;
756 case 9:
757 ++$i;
758 if (($arg_a[0] == 'text') || (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822'))) {
759 $res = $msg->parseDisposition($read, $i);
760 } else {
761 $res = $msg->parseLanguage($read, $i);
762 }
763 $arg_a[] = $res[0];
764 $i = $res[1];
765 ++$arg_no;
766 break;
767 case 10:
768 if (($arg_a[0] == 'text') || (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822'))) {
769 ++$i;
770 $res = $msg->parseLanguage($read, $i);
771 $arg_a[] = $res[0];
772 $i = $res[1];
773 } else {
b65ca362 774 $i = $msg->parseParenthesis($read, $i);
018d3a38 775 $arg_a[] = ''; /* not yet described in rfc2060 */
776 }
777 ++$arg_no;
778 break;
779 default:
780 /* unknown argument, skip this part */
781 $i = $msg->parseParenthesis($read, $i);
782 $arg_a[] = '';
783 ++$arg_no;
784 break;
785 } /* switch */
b65ca362 786 break;
018d3a38 787 case '"':
788 /* inside an entity -> start processing */
789 $debug = substr($read, $i, 20);
790 $res = $msg->parseQuote($read, $i);
791 $arg_s = $res[0];
792 $i = $res[1];
793 ++$arg_no;
794 if ($arg_no < 3) {
795 $arg_s = strtolower($arg_s); /* type0 and type1 */
796 }
797 $arg_a[] = $arg_s;
798 break;
799 case 'n':
800 case 'N':
801 /* probably NIL argument */
802 if (strtoupper(substr($read, $i, 4)) == 'NIL ') {
803 $arg_a[] = '';
804 ++$arg_no;
805 $i += 2;
806 }
b65ca362 807 break;
808 case '{':
809 /* process the literal value */
810 $res = $msg->parseLiteral($read, $i);
811 $arg_s = $res[0];
812 $i = $res[1];
813 ++$arg_no;
814 break;
815 case is_numeric($read{$i}):
816 /* process integers */
817 if ($read{$i} == ' ') { break; }
818 $arg_s = $read{$i};;
819 for (++$i; preg_match('/^[0-9]{1}$/', $read{$i}); ++$i) {
820 $arg_s .= $read{$i};
821 }
822 ++$arg_no;
823 $arg_a[] = $arg_s;
824 break;
825 case ')':
826 $multipart = (isset($msg->type0) && ($msg->type0 == 'multipart'));
827 if (!$multipart) {
828 $shifted_args = (($arg_a[0] == 'text') || (($arg_a[0] == 'message') && ($arg_a[1] == 'rfc822')));
829 $hdr->type0 = $arg_a[0];
e219fb97 830 $hdr->type1 = $arg_a[1];
b65ca362 831
832 $msg->type0 = $arg_a[0];
833 $msg->type1 = $arg_a[1];
b65ca362 834 $arr = $arg_a[2];
835 if (is_array($arr)) {
836 $hdr->parameters = $arg_a[2];
837 }
838 $hdr->id = str_replace('<', '', str_replace('>', '', $arg_a[3]));
839 $hdr->description = $arg_a[4];
840 $hdr->encoding = strtolower($arg_a[5]);
841 $hdr->entity_id = $msg->entity_id;
e219fb97 842 $hdr->size = $arg_a[6];
b65ca362 843 if ($shifted_args) {
844 $hdr->lines = $arg_a[7];
845 $s = 1;
846 } else {
847 $s = 0;
848 }
849 $hdr->md5 = (isset($arg_a[7+$s]) ? $arg_a[7+$s] : $hdr->md5);
850 $hdr->disposition = (isset($arg_a[8+$s]) ? $arg_a[8+$s] : $hdr->disposition);
851 $hdr->language = (isset($arg_a[9+$s]) ? $arg_a[9+$s] : $hdr->language);
852 $msg->header = $hdr;
19ac8f64 853 if ((strrchr($msg->entity_id, '.') == '.0') && ($msg->type0 !='multipart')) {
854 $msg->entity_id = $this->entity_id . '.1';
b65ca362 855 }
856 } else {
857 $hdr->type0 = 'multipart';
858 $hdr->type1 = $arg_a[0];
859 $msg->type0 = 'multipart';
860 $msg->type1 = $arg_a[0];
bc185bd2 861 $hdr->parameters = (isset($arg_a[1]) ? $arg_a[1] : $hdr->parameters);
862 $hdr->disposition = (isset($arg_a[2]) ? $arg_a[2] : $hdr->disposition);
863 $hdr->language = (isset($arg_a[3]) ? $arg_a[3] : $hdr->language);
b65ca362 864 $msg->header = $hdr;
865 }
19ac8f64 866 ++$i;
b65ca362 867 return (array($msg, $i));
868 default: break;
869 } /* switch */
870
871 } /* for */
319cf0d2 872 } /* parsestructure */
e219fb97 873
b65ca362 874 function parseProperties($read, $i) {
875 $properties = array();
876 $prop_name = '';
b65ca362 877
878 for (; $read{$i} != ')'; ++$i) {
e60230ae 879 $arg_s = '';
b65ca362 880 if ($read{$i} == '"') {
881 $res = $this->parseQuote($read, $i);
882 $arg_s = $res[0];
883 $i = $res[1];
884 } else if ($read{$i} == '{') {
885 $res = $this->parseLiteral($read, $i);
886 $arg_s = $res[0];
887 $i = $res[1];
888 }
889
e60230ae 890 if ($arg_s != '') {
891 if ($prop_name == '') {
892 $prop_name = strtolower($arg_s);
893 $properties[$prop_name] = '';
894 } else if ($prop_name != '') {
895 $properties[$prop_name] = $arg_s;
896 $prop_name = '';
897 }
b65ca362 898 }
899 }
e60230ae 900 return array($properties, $i);
8f6b86cc 901 }
e219fb97 902
b65ca362 903 function parseEnvelope($read, $i, $hdr) {
8f6b86cc 904 $arg_no = 0;
b65ca362 905 $arg_a = array();
b65ca362 906
d625cff3 907 for ($cnt = strlen($read); ($i < $cnt) && ($read{$i} != ')'); ++$i) {
b65ca362 908 ++$i;
909 $char = strtoupper($read{$i});
910 switch ($char) {
911 case '"':
912 $res = $this->parseQuote($read, $i);
913 $arg_a[] = $res[0];
914 $i = $res[1];
915 ++$arg_no;
916 break;
917 case '{':
918 $res = $this->parseLiteral($read, $i);
919 $arg_a[] = $res[0];
920 $i = $res[1];
921 ++$arg_no;
922 break;
e219fb97 923 case 'N':
b65ca362 924 /* probably NIL argument */
925 if (strtoupper(substr($read, $i, 3)) == 'NIL') {
926 $arg_a[] = '';
927 ++$arg_no;
928 $i += 2;
e219fb97 929 }
b65ca362 930 break;
931 case '(':
932 /* Address structure (with group support)
933 * Note: Group support is useless on SMTP connections
934 * because the protocol doesn't support it
935 */
936 $addr_a = array();
937 $group = '';
938 $a=0;
939 for (; $i < $cnt && $read{$i} != ')'; ++$i) {
940 if ($read{$i} == '(') {
941 $res = $this->parseAddress($read, $i);
942 $addr = $res[0];
943 $i = $res[1];
944 if (($addr->host == '') && ($addr->mailbox != '')) {
945 /* start of group */
946 $group = $addr->mailbox;
947 $group_addr = $addr;
948 $j = $a;
949 } else if ($group && ($addr->host == '') && ($addr->mailbox == '')) {
950 /* end group */
951 if ($a == ($j+1)) { /* no group members */
952 $group_addr->group = $group;
953 $group_addr->mailbox = '';
954 $group_addr->personal = "$group: Undisclosed recipients;";
955 $addr_a[] = $group_addr;
956 $group ='';
957 }
958 } else {
959 $addr->group = $group;
960 $addr_a[] = $addr;
961 }
962 ++$a;
963 }
964 }
965 $arg_a[] = $addr_a;
966 break;
967 default: break;
968 }
969 }
970
971 if (count($arg_a) > 9) {
972 /* argument 1: date */
8f6b86cc 973 $d = strtr($arg_a[0], array(' ' => ' '));
974 $d = explode(' ', $d);
975 $hdr->date = getTimeStamp($d);
b65ca362 976
977 /* argument 2: subject */
978 $arg_a[1] = (!trim($arg_a[1]) ? _("(no subject)") : $arg_a[1]);
979 $hdr->subject = $arg_a[1];
980
981 $hdr->from = $arg_a[2][0]; /* argument 3: from */
982 $hdr->sender = $arg_a[3][0]; /* argument 4: sender */
983 $hdr->replyto = $arg_a[4][0]; /* argument 5: reply-to */
984 $hdr->to = $arg_a[5]; /* argument 6: to */
985 $hdr->cc = $arg_a[6]; /* argument 7: cc */
986 $hdr->bcc = $arg_a[7]; /* argument 8: bcc */
987 $hdr->inreplyto = $arg_a[8]; /* argument 9: in-reply-to */
988 $hdr->message_id = $arg_a[9]; /* argument 10: message-id */
989 }
990 return (array($hdr, $i));
8f6b86cc 991 }
e219fb97 992
b65ca362 993 function parseLiteral($read, $i) {
994 $lit_cnt = '';
995 for (++$i; $read{$i} != '}'; ++$i) {
996 $lit_cnt .= $read{$i};
997 }
998
999 $lit_cnt +=2; /* add the { and } characters */
1000 $s = '';
1001 for ($j = 0; $j < $lit_cnt; ++$j) {
1002 $s .= $read{++$i};
1003 }
1004 return (array($s, $i));
8f6b86cc 1005 }
e219fb97 1006
b65ca362 1007 function parseQuote($read, $i) {
1008 $s = '';
1009 for (++$i; $read{$i} != '"'; ++$i) {
1010 if ($read{$i} == '\\') {
1011 ++$i;
e219fb97 1012 }
b65ca362 1013 $s .= $read{$i};
1014 }
e219fb97 1015 return (array($s, $i));
8f6b86cc 1016 }
e219fb97 1017
b65ca362 1018 function parseAddress($read, $i) {
1019 $arg_a = array();
1020
1021 for (; $read{$i} != ')'; ++$i) {
1022 $char = strtoupper($read{$i});
1023 switch ($char) {
1024 case '"':
e219fb97 1025 case '{':
b65ca362 1026 $res = ($char == '"' ? $this->parseQuote($read, $i) : $this->parseLiteral($read, $i));
1027 $arg_a[] = $res[0];
1028 $i = $res[1];
1029 break;
1030 case 'n':
e219fb97 1031 case 'N':
b65ca362 1032 if (strtoupper(substr($read, $i, 3)) == 'NIL') {
1033 $arg_a[] = '';
1034 $i += 2;
1035 }
1036 break;
1037 default: break;
1038 }
1039 }
1040
1041 if (count($arg_a) == 4) {
1042 $adr = new address_structure();
1043 $adr->personal = $arg_a[0];
1044 $adr->adl = $arg_a[1];
1045 $adr->mailbox = $arg_a[2];
1046 $adr->host = $arg_a[3];
1047 } else {
1048 $adr = '';
1049 }
1050 return (array($adr, $i));
8f6b86cc 1051 }
e219fb97 1052
b65ca362 1053 function parseDisposition($read, $i) {
8f6b86cc 1054 $arg_a = array();
b65ca362 1055
1056 for (; $read{$i} != ')'; ++$i) {
1057 switch ($read{$i}) {
1058 case '"':
e219fb97 1059 case '{':
b65ca362 1060 case '(':
1061 switch ($read{$i}) {
1062 case '"': $res = $this->parseQuote($read, $i); break;
1063 case '{': $res = $this->parseLiteral($read, $i); break;
1064 case '(': $res = $this->parseProperties($read, $i); break;
1065 }
1066 $arg_a[] = $res[0];
1067 $i = $res[1];
1068 break;
1069 default: break;
1070 }
e02d0fa7 1071 }
b65ca362 1072
1073 if (isset($arg_a[0])) {
1074 $disp = new disposition($arg_a[0]);
1075 if (isset($arg_a[1])) {
1076 $disp->properties = $arg_a[1];
1077 }
1078 }
1079
1080 return (is_object($disp) ? array($disp, $i) : array('', $i));
8f6b86cc 1081 }
e219fb97 1082
b65ca362 1083 function parseLanguage($read, $i) {
08c18186 1084 /* no idea how to process this one without examples */
31e0cfba 1085 $arg_a = array();
b65ca362 1086
1087 for (; $read{$i} != ')'; ++$i) {
1088 switch ($read{$i}) {
1089 case '"':
e219fb97 1090 case '{':
b65ca362 1091 case '(':
1092 switch ($read{$i}) {
1093 case '"': $res = $this->parseQuote($read, $i); break;
1094 case '{': $res = $this->parseLiteral($read, $i); break;
1095 case '(': $res = $this->parseProperties($read, $i); break;
1096 }
1097 $arg_a[] = $res[0];
1098 $i = $res[1];
1099 break;
1100 default: break;
1101 }
08c18186 1102 }
b65ca362 1103
1104 if (isset($arg_a[0])) {
1105 $lang = new language($arg_a[0]);
1106 if (isset($arg_a[1])) {
1107 $lang->properties = $arg_a[1];
1108 }
31e0cfba 1109 }
b65ca362 1110
1111 return (is_object($lang) ? array($lang, $i) : array('', $i));
8f6b86cc 1112 }
e219fb97 1113
b65ca362 1114 function parseParenthesis($read, $i) {
1115 for (; $read{$i} != ')'; ++$i) {
1116 switch ($read{$i}) {
1117 case '"':
e219fb97 1118 case '{':
b65ca362 1119 case '(':
1120 switch ($read{$i}) {
1121 case '"': $res = $this->parseQuote($read, $i); break;
1122 case '{': $res = $this->parseLiteral($read, $i); break;
1123 case '(': $res = $this->parseProperties($read, $i); break;
1124 }
1125 $i = $res[1];
1126 break;
1127 default: break;
1128 }
e219fb97 1129 }
b65ca362 1130 return $i;
c52ffd66 1131 }
1132
b65ca362 1133 /* Function to fill the message structure in case the */
1134 /* bodystructure is not available NOT FINISHED YET */
1135 function parseMessage($read, $type0, $type1) {
1136 switch ($type0) {
1137 case 'message':
1138 $rfc822_header = true;
1139 $mime_header = false;
1140 break;
1141 case 'multipart':
1142 $rfc822_header = false;
1143 $mime_header = true;
1144 break;
1145 default: return $read;
1146 }
1147
1148 for ($i = 1; $i < $count; ++$i) {
1149 $line = trim($body[$i]);
e219fb97 1150 if (($mime_header || $rfc822_header) &&
b65ca362 1151 (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i", $line, $reg))) {
1152 $bnd = $reg[1];
e219fb97 1153 $bndreg = $bnd;
1154 $bndreg = str_replace("\\", "\\\\", $bndreg);
b65ca362 1155 $bndreg = str_replace("?", "\\?", $bndreg);
e219fb97 1156 $bndreg = str_replace("+", "\\+", $bndreg);
1157 $bndreg = str_replace(".", "\\.", $bndreg);
b65ca362 1158 $bndreg = str_replace("/", "\\/", $bndreg);
1159 $bndreg = str_replace("-", "\\-", $bndreg);
1160 $bndreg = str_replace("(", "\\(", $bndreg);
1161 $bndreg = str_replace(")", "\\)", $bndreg);
1162 } else if ($rfc822_header && $line == '') {
1163 $rfc822_header = false;
1164 if ($msg->type0 == 'multipart') {
1165 $mime_header = true;
1166 }
e219fb97 1167 }
1168
b65ca362 1169 if ((($line{0} == '-') || $rfc822_header) && isset($boundaries[0])) {
62cfbd1d 1170 $cnt = count($boundaries)-1;
b65ca362 1171 $bnd = $boundaries[$cnt]['bnd'];
1172 $bndreg = $boundaries[$cnt]['bndreg'];
e219fb97 1173
b65ca362 1174 $regstr = '/^--'."($bndreg)".".*".'/';
1175 if (preg_match($regstr, $line, $reg)) {
1176 $bndlen = strlen($reg[1]);
e219fb97 1177 $bndend = false;
b65ca362 1178 if (strlen($line) > ($bndlen + 3)) {
1179 if (($line{$bndlen+2} == '-') && ($line{$bndlen+3} == '-')) {
1180 $bndend = true;
1181 }
1182 }
1183 if ($bndend) {
1184 /* calc offset and return $msg */
1185 //$entStr = CalcEntity("$entStr", -1);
1186 array_pop($boundaries);
1187 $mime_header = true;
1188 $bnd_end = true;
1189 } else {
1190 $mime_header = true;
1191 $bnd_end = false;
1192 //$entStr = CalcEntity("$entStr", 0);
1193 ++$content_indx;
1194 }
1195 } else {
1196 if ($header) { }
1197 }
e219fb97 1198 }
b65ca362 1199 }
319cf0d2 1200 }
1201
77b07064 1202 function findDisplayEntity($entity = array(), $alt_order = array('text/plain', 'text/html'), $strict=false) {
8f288482 1203 $found = false;
77b07064 1204 if ($this->type0 == 'multipart') {
1205 if($this->type1 == 'alternative') {
1206 $msg = $this->findAlternativeEntity($alt_order);
b65ca362 1207 if (count($msg->entities) == 0) {
8f288482 1208 $entity[] = $msg->entity_id;
b65ca362 1209 } else {
77b07064 1210 $entity = $msg->findDisplayEntity($entity, $alt_order, $strict);
8f288482 1211 }
8f288482 1212 $found = true;
77b07064 1213 } else if ($this->type1 == 'related') { /* RFC 2387 */
1214 $msgs = $this->findRelatedEntity();
1215 foreach ($msgs as $msg) {
1216 if (count($msg->entities) == 0) {
1217 $entity[] = $msg->entity_id;
1218 } else {
1219 $entity = $msg->findDisplayEntity($entity, $alt_order, $strict);
1220 }
1221 }
1222 if (count($msgs) > 0) {
1223 $found = true;
1224 }
1225 } else { /* Treat as multipart/mixed */
1226 foreach ($this->entities as $ent) {
1227 if(strtolower($ent->header->disposition->name) != 'attachment' &&
1228 ($ent->type0 != 'message' && $ent->type1 != 'rfc822'))
1229 {
1230 $entity = $ent->findDisplayEntity($entity, $alt_order, $strict);
1231 $found = true;
1232 }
1233 }
8f288482 1234 }
77b07064 1235 } else { /* If not multipart, then just compare with each entry from $alt_order */
1236 $type = $this->type0.'/'.$this->type1;
1237 foreach ($alt_order as $alt) {
1238 if( ($alt == $type) && isset($this->entity_id) ) {
1239 if ( (count($this->entities) == 0) &&
1240 (strtolower($this->header->disposition->name) != 'attachment') )
1241 {
1242 $entity[] = $this->entity_id;
1243 $found = true;
1244 }
8f288482 1245 }
1246 }
1247 }
77b07064 1248 if(!$found) {
8f288482 1249 foreach ($this->entities as $ent) {
b65ca362 1250 if((strtolower($ent->header->disposition->name) != 'attachment') &&
1251 (($ent->type0 != 'message') && ($ent->type1 != 'rfc822'))) {
77b07064 1252 $entity = $ent->findDisplayEntity($entity, $alt_order, $strict);
1253 $found = true;
1254 }
1255 }
1256 }
1257 if(!$strict && !$found) {
1258 if ($this->type0 == 'text' &&
1259 ($this->type1 == 'plain' ||
1260 $this->type1 == 'html' ||
1261 $this->type1 == 'message') &&
1262 isset($this->entity_id) )
1263 {
1264 if (count($this->entities) == 0) {
1265 if (strtolower($this->header->disposition->name) != 'attachment') {
1266 $entity[] = $this->entity_id;
1267 }
8f288482 1268 }
1269 }
1270 }
b65ca362 1271
77b07064 1272 return $entity;
8f6b86cc 1273 }
319cf0d2 1274
b65ca362 1275 function findAlternativeEntity($alt_order) {
1276 /* If we are dealing with alternative parts then we */
1277 /* choose the best viewable message supported by SM. */
319cf0d2 1278 $best_view = 0;
8f288482 1279 $entity = array();
b65ca362 1280 foreach($this->entities as $ent) {
1281 $type = $ent->header->type0 . '/' . $ent->header->type1;
1282 if ($type == 'multipart/related') {
8f288482 1283 $type = $ent->header->getParameter('type');
1284 }
d625cff3 1285 for ($j = $best_view, $altcount = count($alt_order); $j < $altcount; ++$j) {
b65ca362 1286 if (($alt_order[$j] == $type) && ($j >= $best_view)) {
8f288482 1287 $best_view = $j;
1288 $entity = $ent;
1289 }
1290 }
319cf0d2 1291 }
b65ca362 1292
8f288482 1293 return $entity;
319cf0d2 1294 }
e219fb97 1295
b65ca362 1296 function findRelatedEntity() {
e219fb97 1297 $msgs = array();
8f288482 1298 $entcount = count($this->entities);
b65ca362 1299
1300 for ($i = 0; $i < $entcount; ++$i) {
319cf0d2 1301 $type = $this->entities[$i]->header->type0.'/'.$this->entities[$i]->header->type1;
b65ca362 1302 if ($this->header->getParameter('type') == $type) {
8f288482 1303 $msgs[] = $this->entities[$i];
1304 }
319cf0d2 1305 }
b65ca362 1306
319cf0d2 1307 return $msgs;
1308 }
e219fb97 1309
b65ca362 1310 function getAttachments($exclude_id=array(), $result = array()) {
1311 if (($this->type0 == 'message') && ($this->type1 == 'rfc822')) {
1312 $this = $this->entities[0];
1313 }
1314
1315 if (count($this->entities)) {
1316 foreach ($this->entities as $entity) {
1317 $exclude = false;
1318
1319 foreach ($exclude_id as $excl) {
1320 if ($entity->entity_id === $excl) {
1321 $exclude = true;
1322 }
1323 }
1324
1325 if (!$exclude) {
e219fb97 1326 if (($entity->type0 == 'multipart') &&
b65ca362 1327 ($entity->type1 != 'related')) {
1328 $result = $entity->getAttachments($exclude_id, $result);
1329 } else if ($entity->type0 != 'multipart') {
1330 $result[] = $entity;
1331 }
1332 }
1333 }
1334 } else {
1335 $exclude = false;
1336 foreach ($exclude_id as $excl) {
1337 $exclude = $exclude || ($this->entity_id == $excl);
1338 }
1339
1340 if (!$exclude) {
1341 $result[] = $this;
1342 }
1343 }
1344
1345 return $result;
e219fb97 1346 }
8f6b86cc 1347}
1348
b65ca362 1349class smime_message {
1350
c52ffd66 1351}
1352
b65ca362 1353class disposition {
1354 function disposition($name) {
e8bedb2d 1355 $this->name = $name;
1356 $this->properties = array();
1357 }
924b0cac 1358
b65ca362 1359 function getProperty($par) {
924b0cac 1360 $value = strtolower($par);
b65ca362 1361 if (isset($this->properties[$par])) {
1362 return $this->properties[$par];
924b0cac 1363 }
1364 return '';
1365 }
8f6b86cc 1366}
1367
b65ca362 1368class language {
1369 function language($name) {
e8bedb2d 1370 $this->name = $name;
1371 $this->properties = array();
1372 }
1373}
1374
b65ca362 1375class content_type {
e219fb97 1376 var $type0 = 'text',
1377 $type1 = 'plain',
b65ca362 1378 $properties = '';
1379
1380 function content_type($type) {
1381 $pos = strpos($type, '/');
1382 if ($pos > 0) {
1383 $this->type0 = substr($type, 0, $pos);
1384 $this->type1 = substr($type, $pos+1);
1385 } else {
1386 $this->type0 = $type;
1387 }
1388 $this->properties = array();
c52ffd66 1389 }
31e0cfba 1390}
1391
4b8699db 1392?>