Beispiel #1
0
function osc_parse_mime_decode_output(&$obj, &$parts)
{
    if (!empty($obj->parts)) {
        for ($i = 0; $i < count($obj->parts); $i++) {
            if (isset($obj->parts[$i]->parts) && count($obj->parts[$i]->parts) > 0) {
                osc_parse_mime_decode_output($obj->parts[$i], $parts);
            } else {
                parse_output($obj->parts[$i], $parts, $i);
            }
        }
    } elseif (isset($obj->body)) {
        $ctype = $obj->ctype_primary . '/' . $obj->ctype_secondary;
        switch ($ctype) {
            case 'text/plain':
                if (!empty($obj->disposition) and $obj->disposition == 'attachment') {
                    $parts['attachments'][] = $obj->body;
                } else {
                    $parts['text'][] = $obj->body;
                }
                break;
            case 'text/html':
                if (!empty($obj->disposition) and $obj->disposition == 'attachment') {
                    $parts['attachments'][] = $obj->body;
                } else {
                    $parts['html'][] = $obj->body;
                }
                break;
            default:
                $parts['attachments'][] = $obj->body;
                break;
        }
    }
}
 $mail_struct = imap_fetchstructure($conn, $i);
 // Get the message header
 $headers_string = imap_fetchheader($conn, $i, FT_PREFETCHTEXT);
 // and the body, marking as seen if desired (no effect if messages deleted of course!)
 if ('true' == DEFAULT_HELPDESK_MARKSEEN) {
     $body = imap_body($conn, $i);
 } else {
     $body = imap_body($conn, $i, FT_PEEK);
 }
 // get some readable text from the mime input
 $params['input'] = $headers_string . $body;
 $tmp_obj = new Mail_mimeDecode($params['input'], "\r\n");
 $output = $tmp_obj->decode($params);
 // create the osc parts for an email
 $parts = array();
 osc_parse_mime_decode_output($output, $parts);
 /*
           $field_body = '';
           if( isset($parts['html']) && isset($parts['html'][0]) ) {
             $field_body = trim($parts['html'][0]);
           } elseif( isset($parts['text']) && isset($parts['text'][0]) ) {
             $field_body = nl2br(trim($parts['text'][0]));
           }
 */
 $field_html_body = $field_text_body = '';
 $text_index = $html_index = 0;
 foreach ($parts as $key => $value) {
     if ($key == 'html' && is_array($value) && isset($value[0])) {
         if ($html_index) {
             $field_html_body .= '<br /><hr />';
         }