Exemplo n.º 1
0
 /**
  * Performs the decoding. Decodes the body string passed to it
  * If it finds certain content-types it will call itself in a
  * recursive fashion
  *
  * @param string Header section
  * @param string Body section
  * @return object Results of decoding process
  * @access private
  */
 function _decode($headers, $body, $default_ctype = 'text/plain')
 {
     $return = new stdClass();
     $return->headers = array();
     $headers = $this->_parseHeaders($headers);
     foreach ($headers as $value) {
         if (isset($return->headers[strtolower($value['name'])]) and !is_array($return->headers[strtolower($value['name'])])) {
             $return->headers[strtolower($value['name'])] = array($return->headers[strtolower($value['name'])]);
             $return->headers[strtolower($value['name'])][] = $value['value'];
         } elseif (isset($return->headers[strtolower($value['name'])])) {
             $return->headers[strtolower($value['name'])][] = $value['value'];
         } else {
             $return->headers[strtolower($value['name'])] = $value['value'];
         }
     }
     reset($headers);
     while (list($key, $value) = each($headers)) {
         $headers[$key]['name'] = strtolower($headers[$key]['name']);
         switch ($headers[$key]['name']) {
             case 'content-type':
                 $content_type = $this->_parseHeaderValue($headers[$key]['value']);
                 if (preg_match('/([0-9a-z+.-]+)\\/([0-9a-z+.-]+)/i', $content_type['value'], $regs)) {
                     $return->ctype_primary = $regs[1];
                     $return->ctype_secondary = $regs[2];
                 }
                 if (isset($content_type['other'])) {
                     while (list($p_name, $p_value) = each($content_type['other'])) {
                         $return->ctype_parameters[$p_name] = $p_value;
                     }
                 }
                 break;
             case 'content-disposition':
                 $content_disposition = $this->_parseHeaderValue($headers[$key]['value']);
                 $return->disposition = $content_disposition['value'];
                 if (isset($content_disposition['other'])) {
                     while (list($p_name, $p_value) = each($content_disposition['other'])) {
                         $return->d_parameters[$p_name] = $p_value;
                     }
                 }
                 break;
             case 'content-transfer-encoding':
                 $content_transfer_encoding = $this->_parseHeaderValue($headers[$key]['value']);
                 break;
         }
     }
     if (isset($content_type)) {
         switch (strtolower($content_type['value'])) {
             case 'text/plain':
                 $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
                 $this->_include_bodies ? $return->body = $this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body : null;
                 break;
             case 'text/html':
                 $encoding = isset($content_transfer_encoding) ? $content_transfer_encoding['value'] : '7bit';
                 $this->_include_bodies ? $return->body = $this->_decode_bodies ? $this->_decodeBody($body, $encoding) : $body : null;
                 break;
             case 'multipart/parallel':
             case 'multipart/report':
                 // RFC1892
             // RFC1892
             case 'multipart/signed':
                 // PGP
             // PGP
             case 'multipart/digest':
             case 'multipart/alternative':
             case 'multipart/related':
             case 'multipart/mixed':
                 if (!isset($content_type['other']['boundary'])) {
                     $this->_error = 'No boundary found for ' . $content_type['value'] . ' part';
                     return false;
                 }
                 $default_ctype = strtolower($content_type['value']) === 'multipart/digest' ? 'message/rfc822' : 'text/plain';
                 $parts = $this->_boundarySplit($body, $content_type['other']['boundary']);
                 for ($i = 0; $i < count($parts); $i++) {
                     list($part_header, $part_body) = $this->_splitBodyHeader($parts[$i]);
                     $part = $this->_decode($part_header, $part_body, $default_ctype);
                     if ($part === false) {
                         $part = $this->raiseError($this->_error);
                     }
                     $return->parts[] = $part;
                 }
                 break;
             case 'message/rfc822':
                 $obj = new D3diary_Mail_mimeDecode($body);
                 $return->parts[] = $obj->decode(array('include_bodies' => $this->_include_bodies, 'decode_bodies' => $this->_decode_bodies, 'decode_headers' => $this->_decode_headers));
                 unset($obj);
                 break;
             default:
                 if (!isset($content_transfer_encoding['value'])) {
                     $content_transfer_encoding['value'] = '7bit';
                 }
                 $this->_include_bodies ? $return->body = $this->_decode_bodies ? $this->_decodeBody($body, $content_transfer_encoding['value']) : $body : null;
                 break;
         }
     } else {
         $ctype = explode('/', $default_ctype);
         $return->ctype_primary = $ctype[0];
         $return->ctype_secondary = $ctype[1];
         $this->_include_bodies ? $return->body = $this->_decode_bodies ? $this->_decodeBody($body) : $body : null;
     }
     return $return;
 }
Exemplo n.º 2
0
 function get_list()
 {
     $count = $this->login();
     $max = 100;
     $start = $count > $max ? $count - $max : 0;
     //var_dump($count);
     if (0 == $count) {
         //	print "There doesn't seem to be any new mail.";
         return false;
     } else {
         for ($i = $count; $i > $start; $i--) {
             //variables
             $content_type = '';
             $boundary = '';
             $bodysignal = 0;
             // added override "mb_detect_order"
             $chr_order = !empty($this->mod_config['post_detect_order']) ? $this->mod_config['post_detect_order'] : 'auto';
             $mb_rtn = mb_detect_order($chr_order);
             if ($mb_rtn != true) {
                 $this->_err_msg .= "Error: INVALID DETECT ORDER '" . $chr_order . "'<br />\n";
                 mb_detect_order('auto');
             }
             $input = implode('', $this->pop3->get($i));
             // decode the mime
             $params['include_bodies'] = true;
             $params['decode_bodies'] = true;
             $params['decode_headers'] = true;
             $params['input'] = $input;
             $structure = D3diary_Mail_mimeDecode::decode($params);
             // read and check "from" address
             $from = $this->yn_read_address($structure);
             if (!$from) {
                 $this->_err_msg .= "Error: No sender address found at message #{$i}.<br />\n";
                 continue;
                 // jump through
             }
             // validate "from" address
             // user profile's email address
             // must get email of $this->req_uid not for $xoopsUser
             $ret = $this->d3dConf->func->get_xoopsuname($this->req_uid);
             $this->email = $ret['email'];
             if (strcmp($from, $this->dcfg->address) != 0 && strcmp($from, $this->email) != 0) {
                 continue;
                 // jump through
             }
             // pickup subject
             $subject = trim($structure->headers['subject']);
             //$subject = mb_convert_encoding($subject, _CHARSET, "auto");
             $subject = mb_convert_encoding($subject, _CHARSET, mb_detect_encoding($subject));
             $title = $this->myts->makeTboxData4Show($subject);
             if (empty($title)) {
                 $title = _MD_DIARY_NO_TITLE;
             }
             //date reformating
             $post_time_gmt = strtotime(trim($structure->headers['date']));
             if (!$post_time_gmt) {
                 $this->_err_msg .= "Error: There is no Date: field at message #{$i}.<br />\n";
                 continue;
             }
             $post_date = gmdate('Y-m-d H:i:s', $post_time_gmt + $this->d3dConf->server_TZ * 3600);
             $create_time = $this->myts->makeTboxData4Show($post_date);
             $post_date_gmt = gmdate('Y-m-d H:i:s', $post_time_gmt);
             $post_date_gmt = $this->myts->makeTboxData4Show($post_date_gmt);
             $this->mails[$i]['id'] = $i;
             $this->mails[$i]['title'] = $title;
             $this->mails[$i]['create_time'] = $create_time;
             $this->mails[$i]['post_date'] = $post_date;
             $this->mails[$i]['post_date_gmt'] = $post_date_gmt;
             $this->structure[$i] = $structure;
         }
         // end looping over messages
         return true;
     }
 }