コード例 #1
0
ファイル: helpdesk.php プロジェクト: enigma1/i-metrics-cms
function help_desk_parsepart($p, $i, $link, $msgid, &$partsarray, &$attachments_array)
{
    //global $link, $msgid,$partsarray;
    //where to write file attachments to:
    $filestore = DIR_FS_ADMIN . HELPDESK_ATTACHMENTS_FOLDER;
    //fetch part
    $part = imap_fetchbody($link, $msgid, $i);
    //if type is not text
    if ($p->type != 0 || $p->type == 0 && isset($p->disposition)) {
        //if ($p->type != 0 ) {
        //DECODE PART
        switch ($p->encoding) {
            case 3:
                //decode if base64
                $part = base64_decode($part);
                break;
            case 4:
                //decode if quoted printable
                $part = quoted_printable_decode($part);
                break;
            default:
                //no need to decode binary or 8bit!
                break;
        }
        //get filename of attachment if present
        $filename = '';
        // if there are any dparameters present in this part
        if (isset($p->dparameters) && is_array($p->dparameters) && count($p->dparameters) > 0) {
            foreach ($p->dparameters as $dparam) {
                if (strtoupper($dparam->attribute) == 'NAME' || strtoupper($dparam->attribute) == 'FILENAME') {
                    $filename = $dparam->value;
                }
            }
        }
        //if no filename found
        if ($filename == '') {
            // if there are any parameters present in this part
            if (isset($p->parameters) && is_array($p->parameters) && count($p->parameters) > 0) {
                foreach ($p->parameters as $param) {
                    if (strtoupper($param->attribute) == 'NAME' || strtoupper($param->attribute) == 'FILENAME') {
                        $filename = $param->value;
                    }
                }
            }
        }
        //write to disk and set partsarray variable
        if ($filename != '') {
            $filename = helpdesk_decode_string($filename);
            $filename = basename(strtolower($filename));
            $filename = tep_create_safe_string($filename, '-', '/[^0-9a-z_\\-\\.]+/');
            if (strlen($filename) < 5) {
                $filename = tep_create_random_value(32, 'mixed_lower');
            }
            $partsarray[$i]['attachment'] = array('filename' => $filename, 'binary' => $part);
            $index = 0;
            $org_filename = $filename;
            while (is_file($filestore . $filename)) {
                $index++;
                $filename = 'copy' . $index . '-' . $org_filename;
            }
            $fp = fopen($filestore . $filename, "w+");
            if (!$fp) {
                echo '<div class="messageStackError">' . sprintf(ERROR_WRITE_ATTACHMENT, $filestore) . '</div>';
            } else {
                echo '<div class="linepad heavy">' . sprintf(TEXT_INFO_ATTACHMENT_WRITE, $filestore . $filename) . '</div>';
                fwrite($fp, $part);
                fclose($fp);
                if (!in_array($filename, $attachments_array)) {
                    $attachments_array[] = $filename;
                }
            }
        }
        //end if type!=0
        //elseif part is text
    } elseif ($p->type == 0) {
        //decode text
        //if QUOTED-PRINTABLE
        if ($p->encoding == 4) {
            $part = quoted_printable_decode($part);
        }
        //if base 64
        if ($p->encoding == 3) {
            $part = base64_decode($part);
        }
        //OPTIONAL PROCESSING e.g. nl2br for plain text
        //if plain text
        if (strtoupper($p->subtype) == 'PLAIN') {
            1;
            //if HTML
        } elseif (strtoupper($p->subtype) == 'HTML') {
            1;
        }
        $partsarray[$i]['text'] = array('type' => $p->subtype, 'string' => $part);
    }
    //if subparts... recurse into function and parse them too!
    if (isset($p->parts) && count($p->parts) > 0) {
        foreach ($p->parts as $pno => $parr) {
            help_desk_parsepart($parr, $i . '.' . ($pno + 1), $link, $msgid, $partsarray, $attachments_array);
        }
    }
    return;
}
コード例 #2
0
 }
 if ($skip_mail) {
     echo '<div class="messageStackWarning">' . sprintf(WARNING_SPAM_REMOVED, '<b>[' . $field_ip . ']</b>') . '</div>';
     if (DEFAULT_HELPDESK_DELETE_EMAILS != 'true') {
         imap_delete($conn, $i);
     }
     continue;
 }
 //-MS- Check Attachments
 $parts_array = array();
 $attachments_array = array();
 //see if there are any parts
 if (isset($mail_struct->parts) && is_array($mail_struct->parts)) {
     foreach ($mail_struct->parts as $partno => $partarr) {
         //parse parts of email
         help_desk_parsepart($partarr, $partno + 1, $conn, $i, $parts_array, $attachments_array);
         //if( isset($parts_array[$partno+1]['attachment']) && !in_array($parts_array[$partno+1]['attachment']['filename'], $attachments_array) ) {
         //  $attachments_array[] = $parts_array[$partno+1]['attachment']['filename'];
         //}
         //$attachment = help_desk_parsepart($partarr, $partno+1, $conn, $i, $parts_array);
         //if( is_string($attachment) && !in_array($attachment, $attachments_array) ) {
         //$attachments_array[] = help_desk_parsepart($partarr, $partno+1, $conn, $i, $parts_array);
         //}
     }
 }
 //-MS- Check Attachments EOM
 // Make sure we try had to have a valid from email address
 if (!empty($output->headers['from'])) {
     if (is_array($output->headers['from'])) {
         $tmp_string = '';
         foreach ($output->headers['from'] as $value) {