+ break 3;
+ }
+ break;
+ case 'ENVELOPE':
+ // sqimap_parse_address($read,$i,$aMsg);
+ break; // to be implemented, moving imap code out of the Message class
+ case 'BODYSTRUCTURE':
+ break; // to be implemented, moving imap code out of the Message class
+ case 'INTERNALDATE':
+ $aMsg['INTERNALDATE'] = trim(str_replace(' ', ' ',parseString($read,$i)));
+ break;
+ case 'BODY.PEEK[HEADER.FIELDS':
+ case 'BODY[HEADER.FIELDS':
+ $i = strpos($read,'{',$i); // header is always returned as literal because it contain \n characters
+ $header = parseString($read,$i);
+ if ($header === false) break 2;
+ /* First we replace all \r\n by \n, and unfold the header */
+ $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $header));
+ /* Now we can make a new header array with
+ each element representing a headerline */
+ $aHdr = explode("\n" , $hdr);
+ $aReceived = array();
+ foreach ($aHdr as $line) {
+ $pos = strpos($line, ':');
+ if ($pos > 0) {
+ $field = strtolower(substr($line, 0, $pos));
+ if (!strstr($field,' ')) { /* valid field */
+ $value = trim(substr($line, $pos+1));
+ switch($field) {
+ case 'date':
+ $aMsg['date'] = trim(str_replace(' ', ' ', $value));
+ break;
+ case 'x-priority': $aMsg['x-priority'] = ($value) ? (int) $value{0} : 3; break;
+ case 'priority':
+ case 'importance':
+ // duplicate code with Rfc822Header.cls:parsePriority()
+ if (!isset($aMsg['x-priority'])) {
+ $aPrio = preg_split('/\s/',trim($value));
+ $sPrio = strtolower(array_shift($aPrio));
+ if (is_numeric($sPrio)) {
+ $iPrio = (int) $sPrio;
+ } elseif ( $sPrio == 'non-urgent' || $sPrio == 'low' ) {
+ $iPrio = 5;
+ } elseif ( $sPrio == 'urgent' || $sPrio == 'high' ) {
+ $iPrio = 1;
+ } else {
+ // default is normal priority
+ $iPrio = 3;
+ }
+ $aMsg['x-priority'] = $iPrio;
+ }
+ break;
+ case 'content-type':
+ $type = $value;
+ if ($pos = strpos($type, ";")) {
+ $type = substr($type, 0, $pos);
+ }
+ $type = explode("/", $type);
+ if(!is_array($type) || count($type) < 2) {
+ $aMsg['content-type'] = array('text','plain');
+ } else {
+ $aMsg['content-type'] = array(strtolower($type[0]),strtolower($type[1]));
+ }
+ break;
+ case 'received':
+ $aMsg['received'][] = $value;
+ break;
+ default:
+ $aMsg[$field] = $value;
+ break;
+ }
+ }
+ }