示例#1
0
/**
 * Stores message in attachment directory, when email based reports are used
 * @access private
 * @todo Duplicate code in src/compose.php
 */
function spamcop_getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id = '', $imapConnection)
{
    global $username, $attachment_dir;
    if (!$passed_ent_id) {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' RFC822', TRUE, $response, $readmessage, TRUE);
    } else {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' BODY[' . $passed_ent_id . ']', TRUE, $response, $readmessage, TRUE);
        $message = $message->parent;
    }
    if ($response == 'OK') {
        array_shift($body_a);
        $body = implode('', $body_a) . "\r\n";
        $filename = sq_get_attach_tempfile();
        $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
        $fp = fopen("{$hashed_attachment_dir}/{$filename}", 'wb');
        fwrite($fp, $body);
        fclose($fp);
        $composeMessage->initAttachment('message/rfc822', 'email.txt', $filename);
    }
    return $composeMessage;
}
示例#2
0
/**
 * Attach messages to a compose session
 *
 * @param  resource $imapConnection imap connection
 * @param  array $aMsgHeaders
 * @return int $composesession unique compose_session_id where the attached messages belong to
 * @author Marc Groot Koerkamp
 */
function attachSelectedMessages($imapConnection, $aMsgHeaders)
{
    sqgetGlobalVar('composesession', $composesession, SQ_SESSION);
    sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
    if (!isset($compose_messages) || is_null($compose_messages)) {
        $compose_messages = array();
        sqsession_register($compose_messages, 'compose_messages');
    }
    if (!$composesession) {
        $composesession = 1;
        sqsession_register($composesession, 'composesession');
    } else {
        $composesession++;
        sqsession_register($composesession, 'composesession');
    }
    $composeMessage = new Message();
    $rfc822_header = new Rfc822Header();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->reply_rfc822_header = '';
    foreach ($aMsgHeaders as $iUid => $aMsgHeader) {
        /**
         * Retrieve the full message
         */
        $body_a = sqimap_run_command($imapConnection, "FETCH {$iUid} RFC822", true, $response, $readmessage, TRUE);
        if ($response == 'OK') {
            $subject = isset($aMsgHeader['subject']) ? $aMsgHeader['subject'] : $iUid;
            array_shift($body_a);
            array_pop($body_a);
            $body = implode('', $body_a);
            $body .= "\r\n";
            global $username, $attachment_dir;
            $filename = sq_get_attach_tempfile();
            $fullpath = getHashedDir($username, $attachment_dir) . '/' . $filename;
            $fp = fopen($fullpath, 'wb');
            fwrite($fp, $body);
            fclose($fp);
            $composeMessage->initAttachment('message/rfc822', $subject . '.eml', $filename);
            // create subject for new message
            //
            $subject = decodeHeader($subject, false, false, true);
            $subject = str_replace('"', "'", $subject);
            $subject = trim($subject);
            if (substr(strtolower($subject), 0, 4) != 'fwd:') {
                $subject = 'Fwd: ' . $subject;
            }
            $composeMessage->rfc822_header->subject = $subject;
        }
    }
    $compose_messages[$composesession] = $composeMessage;
    sqsession_register($compose_messages, 'compose_messages');
    return $composesession;
}
示例#3
0
function saveAttachedFiles($session)
{
    global $composeMessage, $username, $attachment_dir;
    /* get out of here if no file was attached at all */
    if (!is_uploaded_file($_FILES['attachfile']['tmp_name'])) {
        return true;
    }
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $localfilename = sq_get_attach_tempfile();
    $fullpath = $hashed_attachment_dir . '/' . $localfilename;
    // m_u_f works better with restricted PHP installs (safe_mode, open_basedir),
    // if that doesn't work, try a simple rename.
    if (!sq_call_function_suppress_errors('move_uploaded_file', array($_FILES['attachfile']['tmp_name'], $fullpath))) {
        if (!sq_call_function_suppress_errors('rename', array($_FILES['attachfile']['tmp_name'], $fullpath))) {
            return true;
        }
    }
    $type = strtolower($_FILES['attachfile']['type']);
    $name = $_FILES['attachfile']['name'];
    $composeMessage->initAttachment($type, $name, $localfilename);
}