Example #1
0
/**
 * Given a username and datafilename, this will return the path to the
 * hashed location of that datafile.
 *
 * @param string username the username of the current user
 * @param string dir the squirrelmail datadir
 * @param string datafile the name of the file to open
 * @param bool hash_seach default true
 * @return string the hashed location of datafile
 */
function getHashedFile($username, $dir, $datafile, $hash_search = true)
{
    global $dir_hash_level;
    /* Remove trailing slash from $dir if found */
    if (substr($dir, -1) == '/') {
        $dir = substr($dir, 0, strlen($dir) - 1);
    }
    /* Compute the hash for this user and extract the hash directories. */
    $hash_dirs = computeHashDirs($username);
    /* First, get and make sure the full hash directory exists. */
    $real_hash_dir = getHashedDir($username, $dir, $hash_dirs);
    /* Set the value of our real data file, after we've removed unwanted characters. */
    $datafile = str_replace('/', '_', $datafile);
    $result = "{$real_hash_dir}/{$datafile}";
    /* Check for this file in the real hash directory. */
    if ($hash_search && !@file_exists($result)) {
        /* First check the base directory, the most common location. */
        if (@file_exists("{$dir}/{$datafile}")) {
            rename("{$dir}/{$datafile}", $result);
            /* Then check the full range of possible hash directories. */
        } else {
            $check_hash_dir = $dir;
            for ($h = 0; $h < 4; ++$h) {
                $check_hash_dir .= '/' . $hash_dirs[$h];
                if (@is_readable("{$check_hash_dir}/{$datafile}")) {
                    rename("{$check_hash_dir}/{$datafile}", $result);
                    break;
                }
            }
        }
    }
    /* Return the full hashed datafile path. */
    return $result;
}
Example #2
0
/**
 * Get a new file to write an attachment to.
 * This function makes sure it doesn't overwrite other attachments,
 * preventing collisions and race conditions.
 *
 * @return filename of the tempfile only (not full path)
 * @since 1.5.2
 */
function sq_get_attach_tempfile()
{
    global $username, $attachment_dir;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    // using PHP >= 4.3.2 we can be truly atomic here
    $filemods = check_php_version(4, 3, 2) ? 'x' : 'w';
    // give up after 1000 tries
    $TMP_MAX = 1000;
    for ($try = 0; $try < $TMP_MAX; ++$try) {
        $localfilename = GenerateRandomString(32, '', 7);
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
        // filename collision. try again
        if (file_exists($full_localfilename)) {
            continue;
        }
        // try to open for (binary) writing
        $fp = @fopen($full_localfilename, $filemods);
        if ($fp !== FALSE) {
            // success! make sure it's not readable, close and return filename
            chmod($full_localfilename, 0600);
            fclose($fp);
            return $localfilename;
        }
    }
    // we tried 1000 times but didn't succeed.
    error_box(_("Could not open temporary file to store attachment. Contact your system administrator to resolve this issue."));
    return FALSE;
}
Example #3
0
function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id = '', $imapConnection)
{
    global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    if (!$passed_ent_id) {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' RFC822', TRUE, $response, $readmessage, $uid_support);
    } else {
        $body_a = sqimap_run_command($imapConnection, 'FETCH ' . $passed_id . ' BODY[' . $passed_ent_id . ']', TRUE, $response, $readmessage, $uid_support);
        $message = $message->parent;
    }
    if ($response == 'OK') {
        $subject = encodeHeader($message->rfc822_header->subject);
        array_shift($body_a);
        $body = implode('', $body_a) . "\r\n";
        $localfilename = GenerateRandomString(32, 'FILE', 7);
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
        $fp = fopen($full_localfilename, 'w');
        fwrite($fp, $body);
        fclose($fp);
        /* dirty relative dir fix */
        if (substr($attachment_dir, 0, 3) == '../') {
            $attachment_dir = substr($attachment_dir, 3);
            $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
        }
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
        $composeMessage->initAttachment('message/rfc822', 'email.txt', $full_localfilename);
    }
    return $composeMessage;
}
function attachSelectedMessages($msg, $imapConnection)
{
    global $username, $attachment_dir, $startMessage, $data_dir, $composesession, $uid_support, $msgs, $thread_sort_messages, $allow_server_sort, $show_num, $compose_messages;
    if (!isset($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');
    }
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession);
    if ($thread_sort_messages || $allow_server_sort) {
        $start_index = 0;
    } else {
        $start_index = ($startMessage - 1) * $show_num;
    }
    $i = 0;
    $j = 0;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $composeMessage = new Message();
    $rfc822_header = new Rfc822Header();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->reply_rfc822_header = '';
    while ($j < count($msg)) {
        if (isset($msg[$i])) {
            $id = $msg[$i];
            $body_a = sqimap_run_command($imapConnection, "FETCH {$id} RFC822", true, $response, $readmessage, $uid_support);
            if ($response == 'OK') {
                // fetch the subject for the message with $id from msgs.
                // is there a more efficient way to do this?
                foreach ($msgs as $k => $vals) {
                    if ($vals['ID'] == $id) {
                        $subject = $msgs[$k]['SUBJECT'];
                        break;
                    }
                }
                array_shift($body_a);
                array_pop($body_a);
                $body = implode('', $body_a);
                $body .= "\r\n";
                $localfilename = GenerateRandomString(32, 'FILE', 7);
                $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
                $fp = fopen($full_localfilename, 'wb');
                fwrite($fp, $body);
                fclose($fp);
                $composeMessage->initAttachment('message/rfc822', $subject . '.msg', $full_localfilename);
            }
            $j++;
        }
        $i++;
    }
    $compose_messages[$composesession] = $composeMessage;
    sqsession_register($compose_messages, 'compose_messages');
    session_write_close();
    return $composesession;
}
Example #5
0
 /**
  * Delete all attachments from this object from disk.
  * @since 1.5.1
  */
 function purgeAttachments()
 {
     if ($this->att_local_name) {
         global $username, $attachment_dir;
         $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
         if (file_exists($hashed_attachment_dir . '/' . $this->att_local_name)) {
             unlink($hashed_attachment_dir . '/' . $this->att_local_name);
         }
     }
     // recursively delete attachments from entities contained in this object
     for ($i = 0, $entCount = count($this->entities); $i < $entCount; ++$i) {
         $this->entities[$i]->purgeAttachments();
     }
 }
Example #6
0
function attachSelectedMessages($msg, $imapConnection)
{
    global $username, $attachment_dir, $startMessage, $data_dir, $composesession, $uid_support, $mailbox, $msgs, $thread_sort_messages, $allow_server_sort, $show_num, $compose_messages;
    if (!isset($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');
    }
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir, $composesession);
    if ($thread_sort_messages || $allow_server_sort) {
        $start_index = 0;
    } else {
        $start_index = ($startMessage - 1) * $show_num;
    }
    $i = 0;
    $j = 0;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $composeMessage = new Message();
    $rfc822_header = new Rfc822Header();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->reply_rfc822_header = '';
    while ($j < count($msg)) {
        if (isset($msg[$i])) {
            $id = $msg[$i];
            $body_a = sqimap_run_command($imapConnection, "FETCH {$id} RFC822", true, $response, $readmessage, $uid_support);
            if ($response == 'OK') {
                $message = sqimap_get_message($imapConnection, $id, $mailbox);
                // fetch the subject for the message from the object
                $filename = $message->rfc822_header->subject;
                if (empty($filename)) {
                    $filename = "untitled-" . $message->entity_id;
                }
                $filename .= '.msg';
                $filename = decodeHeader($filename, false, false);
                array_shift($body_a);
                array_pop($body_a);
                $body = implode('', $body_a);
                $body .= "\r\n";
                $localfilename = GenerateRandomString(32, 'FILE', 7);
                $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
                while (file_exists($full_localfilename)) {
                    $localfilename = GenerateRandomString(32, 'FILE', 7);
                    $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
                }
                $fp = fopen($full_localfilename, 'wb');
                fwrite($fp, $body);
                fclose($fp);
                $composeMessage->initAttachment('message/rfc822', $filename, $localfilename);
            }
            $j++;
        }
        $i++;
    }
    $compose_messages[$composesession] = $composeMessage;
    sqsession_register($compose_messages, 'compose_messages');
    session_write_close();
    return $composesession;
}
function attachSelectedMessages($imapConnection, $aMsgHeaders)
{
    global $username, $attachment_dir, $data_dir, $composesession, $compose_messages;
    if (!isset($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');
    }
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $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";
            $localfilename = GenerateRandomString(32, 'FILE', 7);
            $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
            $fp = fopen($full_localfilename, 'wb');
            fwrite($fp, $body);
            fclose($fp);
            $composeMessage->initAttachment('message/rfc822', $subject . '.msg', $full_localfilename);
        }
    }
    $compose_messages[$composesession] = $composeMessage;
    sqsession_register($compose_messages, 'compose_messages');
    return $composesession;
}
Example #8
0
function SendMDN($mailbox, $passed_id, $sender, $message, $imapConnection)
{
    global $username, $attachment_dir, $color, $default_move_to_sent, $version, $attachments, $squirrelmail_language, $default_charset, $languages, $useSendmail, $domain, $sent_folder, $popuser, $data_dir;
    sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
    $header = $message->rfc822_header;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $rfc822_header = new Rfc822Header();
    $content_type = new ContentType('multipart/report');
    $content_type->properties['report-type'] = 'disposition-notification';
    set_my_charset();
    if ($default_charset) {
        $content_type->properties['charset'] = $default_charset;
    }
    $rfc822_header->content_type = $content_type;
    $rfc822_header->to[] = $header->dnt;
    $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject, true, false);
    // FIXME: use identity.php from SM 1.5. Change this also in compose.php
    $reply_to = '';
    if (isset($identity) && $identity != 'default') {
        $from_mail = getPref($data_dir, $username, 'email_address' . $identity);
        $full_name = getPref($data_dir, $username, 'full_name' . $identity);
        $from_addr = '"' . $full_name . '" <' . $from_mail . '>';
        $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
    } else {
        $from_mail = getPref($data_dir, $username, 'email_address');
        $full_name = getPref($data_dir, $username, 'full_name');
        $from_addr = '"' . $full_name . '" <' . $from_mail . '>';
        $reply_to = getPref($data_dir, $username, 'reply_to');
    }
    // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
    // This merely comes from compose.php and only happens when there is no
    // email_addr specified in user's identity (which is the startup config)
    if (ereg("^([^@%/]+)[@%/](.+)\$", $username, $usernamedata)) {
        $popuser = $usernamedata[1];
        $domain = $usernamedata[2];
        unset($usernamedata);
    } else {
        $popuser = $username;
    }
    if (!$from_mail) {
        $from_mail = "{$popuser}@{$domain}";
        $from_addr = $from_mail;
    }
    $rfc822_header->from = $rfc822_header->parseAddress($from_addr, true);
    if ($reply_to) {
        $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to, true);
    }
    // part 1 (RFC2298)
    $senton = getLongDateString($header->date, $header->date_unparsed);
    $to_array = $header->to;
    $to = '';
    foreach ($to_array as $line) {
        $to .= ' ' . $line->getAddress();
    }
    $now = getLongDateString(time());
    set_my_charset();
    $body = _("Your message") . "\r\n\r\n" . "\t" . _("To") . ': ' . decodeHeader($to, false, false, true) . "\r\n" . "\t" . _("Subject") . ': ' . decodeHeader($header->subject, false, false, true) . "\r\n" . "\t" . _("Sent") . ': ' . $senton . "\r\n" . "\r\n" . sprintf(_("Was displayed on %s"), $now);
    $special_encoding = '';
    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
        $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
        if (strtolower($default_charset) == 'iso-2022-jp') {
            if (mb_detect_encoding($body) == 'ASCII') {
                $special_encoding = '8bit';
            } else {
                $body = mb_convert_encoding($body, 'JIS');
                $special_encoding = '7bit';
            }
        }
    } elseif (sq_is8bit($body)) {
        // detect 8bit symbols added by translations
        $special_encoding = '8bit';
    }
    $part1 = new Message();
    $part1->setBody($body);
    $mime_header = new MessageHeader();
    $mime_header->type0 = 'text';
    $mime_header->type1 = 'plain';
    if ($special_encoding) {
        $mime_header->encoding = $special_encoding;
    } else {
        $mime_header->encoding = '7bit';
    }
    if ($default_charset) {
        $mime_header->parameters['charset'] = $default_charset;
    }
    $part1->mime_header = $mime_header;
    // part2  (RFC2298)
    $original_recipient = $to;
    $original_message_id = $header->message_id;
    $report = "Reporting-UA : {$SERVER_NAME} ; SquirrelMail (version {$version}) \r\n";
    if ($original_recipient != '') {
        $report .= "Original-Recipient : {$original_recipient}\r\n";
    }
    $final_recipient = $sender;
    $report .= "Final-Recipient: rfc822; {$final_recipient}\r\n" . "Original-Message-ID : {$original_message_id}\r\n" . "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
    $part2 = new Message();
    $part2->setBody($report);
    $mime_header = new MessageHeader();
    $mime_header->type0 = 'message';
    $mime_header->type1 = 'disposition-notification';
    $mime_header->encoding = '7bit';
    $part2->mime_header = $mime_header;
    $composeMessage = new Message();
    $composeMessage->rfc822_header = $rfc822_header;
    $composeMessage->addEntity($part1);
    $composeMessage->addEntity($part2);
    if ($useSendmail) {
        require_once SM_PATH . 'class/deliver/Deliver_SendMail.class.php';
        global $sendmail_path, $sendmail_args;
        // Check for outdated configuration
        if (!isset($sendmail_args)) {
            if ($sendmail_path == '/var/qmail/bin/qmail-inject') {
                $sendmail_args = '';
            } else {
                $sendmail_args = '-i -t';
            }
        }
        $deliver = new Deliver_SendMail(array('sendmail_args' => $sendmail_args));
        $stream = $deliver->initStream($composeMessage, $sendmail_path);
    } else {
        require_once SM_PATH . 'class/deliver/Deliver_SMTP.class.php';
        $deliver = new Deliver_SMTP();
        global $smtpServerAddress, $smtpPort, $pop_before_smtp, $pop_before_smtp_host;
        $authPop = isset($pop_before_smtp) && $pop_before_smtp ? true : false;
        $user = '';
        $pass = '';
        if (empty($pop_before_smtp_host)) {
            $pop_before_smtp_host = $smtpServerAddress;
        }
        get_smtp_user($user, $pass);
        $stream = $deliver->initStream($composeMessage, $domain, 0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host);
    }
    $success = false;
    if ($stream) {
        $deliver->mail($composeMessage, $stream);
        $success = $deliver->finalizeStream($stream);
    }
    if (!$success) {
        $msg = _("Message not sent.") . ' ' . _("Server replied:") . "\n<blockquote>\n" . $deliver->dlv_msg . '<br />' . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg . "</blockquote>\n\n";
        require_once SM_PATH . 'functions/display_messages.php';
        plain_error_message($msg, $color);
    } else {
        unset($deliver);
        // copy message to sent folder
        $move_to_sent = getPref($data_dir, $username, 'move_to_sent');
        if (isset($default_move_to_sent) && $default_move_to_sent != 0) {
            $svr_allow_sent = true;
        } else {
            $svr_allow_sent = false;
        }
        if (isset($sent_folder) && ($sent_folder != '' || $sent_folder != 'none') && sqimap_mailbox_exists($imapConnection, $sent_folder)) {
            $fld_sent = true;
        } else {
            $fld_sent = false;
        }
        if (isset($move_to_sent) && $move_to_sent != 0 || !isset($move_to_sent)) {
            $lcl_allow_sent = true;
        } else {
            $lcl_allow_sent = false;
        }
        if ($fld_sent && $svr_allow_sent && !$lcl_allow_sent || $fld_sent && $lcl_allow_sent) {
            require_once SM_PATH . 'class/deliver/Deliver_IMAP.class.php';
            $imap_deliver = new Deliver_IMAP();
            $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder);
            unset($imap_deliver);
        }
    }
    return $success;
}
Example #9
0
function saveAttachedFiles($session)
{
    global $_FILES, $attachment_dir, $attachments, $username, $data_dir, $compose_messages;
    /* 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 = GenerateRandomString(32, '', 7);
    $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
    while (file_exists($full_localfilename)) {
        $localfilename = GenerateRandomString(32, '', 7);
        $full_localfilename = "{$hashed_attachment_dir}/{$localfilename}";
    }
    // FIXME: we SHOULD prefer move_uploaded_file over rename because
    // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
    if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
        if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
            return true;
        }
    }
    $message = $compose_messages[$session];
    $type = strtolower($_FILES['attachfile']['type']);
    $name = $_FILES['attachfile']['name'];
    $message->initAttachment($type, $name, $full_localfilename);
    $compose_messages[$session] = $message;
    sqsession_register($compose_messages, 'compose_messages');
}
Example #10
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;
}
Example #11
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;
}
Example #12
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);
}
Example #13
0
 /**
  * function prepareMIME_Header - creates the mime header
  *
  * @param Message $message  Message object to act on
  * @param string  $boundary mime boundary from fn MimeBoundary
  *
  * @return string $header properly formatted mime header
  */
 function prepareMIME_Header($message, $boundary)
 {
     $mime_header = $message->mime_header;
     $rn = "\r\n";
     $header = array();
     $contenttype = 'Content-Type: ' . $mime_header->type0 . '/' . $mime_header->type1;
     if (count($message->entities)) {
         $contenttype .= ';' . 'boundary="' . $boundary . '"';
     }
     if (isset($mime_header->parameters['name'])) {
         $contenttype .= '; name="' . encodeHeader($mime_header->parameters['name']) . '"';
     }
     if (isset($mime_header->parameters['charset'])) {
         $charset = $mime_header->parameters['charset'];
         $contenttype .= '; charset="' . encodeHeader($charset) . '"';
     }
     $header[] = $contenttype . $rn;
     if ($mime_header->description) {
         $header[] = 'Content-Description: ' . $mime_header->description . $rn;
     }
     if ($mime_header->encoding) {
         $encoding = $mime_header->encoding;
         $header[] = 'Content-Transfer-Encoding: ' . $mime_header->encoding . $rn;
     } else {
         // inspect attached file for lines longer than allowed by RFC,
         // in which case we'll be using base64 encoding (so we can split
         // the lines up without corrupting them) instead of 8bit unencoded...
         // (see RFC 2822/2.1.1)
         //
         if (!empty($message->att_local_name)) {
             // is this redundant? I have no idea
             global $username, $attachment_dir;
             $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
             $filename = $hashed_attachment_dir . '/' . $message->att_local_name;
             // using 990 because someone somewhere is folding lines at
             // 990 instead of 998 and I'm too lazy to find who it is
             //
             $file_has_long_lines = file_has_long_lines($filename, 990);
         } else {
             $file_has_long_lines = FALSE;
         }
         if ($mime_header->type0 == 'multipart' || $mime_header->type0 == 'alternative') {
             /* no-op; no encoding needed */
         } else {
             if (($mime_header->type0 == 'text' || $mime_header->type0 == 'message') && !$file_has_long_lines) {
                 $header[] = 'Content-Transfer-Encoding: 8bit' . $rn;
             } else {
                 $header[] = 'Content-Transfer-Encoding: base64' . $rn;
             }
         }
     }
     if ($mime_header->id) {
         $header[] = 'Content-ID: ' . $mime_header->id . $rn;
     }
     if ($mime_header->disposition) {
         $disposition = $mime_header->disposition;
         $contentdisp = 'Content-Disposition: ' . $disposition->name;
         if ($disposition->getProperty('filename')) {
             $contentdisp .= '; filename="' . encodeHeader($disposition->getProperty('filename')) . '"';
         }
         $header[] = $contentdisp . $rn;
     }
     if ($mime_header->md5) {
         $header[] = 'Content-MD5: ' . $mime_header->md5 . $rn;
     }
     if ($mime_header->language) {
         $header[] = 'Content-Language: ' . $mime_header->language . $rn;
     }
     $cnt = count($header);
     $hdr_s = '';
     for ($i = 0; $i < $cnt; $i++) {
         $hdr_s .= $this->foldLine($header[$i], 78);
     }
     $header = $hdr_s;
     $header .= $rn;
     /* One blank line to separate mimeheader and body-entity */
     return $header;
 }
Example #14
0
/**
 * Save newmail plugin settings
 */
function newmail_sav_function()
{
    global $data_dir, $username, $_FILES, $newmail_uploadsounds;
    if (sqgetGlobalVar('submit_newmail', $submit, SQ_POST)) {
        $media_enable = '';
        $media_popup = '';
        $media_recent = '';
        $media_changetitle = '';
        $media_sel = '';
        $popup_width = '';
        $popup_height = '';
        sqgetGlobalVar('media_enable', $media_enable, SQ_POST);
        sqgetGlobalVar('media_popup', $media_popup, SQ_POST);
        sqgetGlobalVar('media_recent', $media_recent, SQ_POST);
        sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
        sqgetGlobalVar('popup_width', $popup_width, SQ_POST);
        sqgetGlobalVar('popup_height', $popup_height, SQ_POST);
        // sanitize height and width
        $popup_width = (int) $popup_width;
        if ($popup_width <= 0) {
            $popup_width = 200;
        }
        $popup_height = (int) $popup_height;
        if ($popup_height <= 0) {
            $popup_height = 130;
        }
        setPref($data_dir, $username, 'newmail_enable', $media_enable);
        setPref($data_dir, $username, 'newmail_popup', $media_popup);
        setPref($data_dir, $username, 'newmail_recent', $media_recent);
        setPref($data_dir, $username, 'newmail_changetitle', $media_changetitle);
        setPref($data_dir, $username, 'newmail_popup_width', $popup_width);
        setPref($data_dir, $username, 'newmail_popup_height', $popup_height);
        if (sqgetGlobalVar('newmail_unseen_notify', $newmail_unseen_notify, SQ_POST)) {
            $newmail_unseen_notify = (int) $newmail_unseen_notify;
            setPref($data_dir, $username, 'newmail_unseen_notify', $newmail_unseen_notify);
        }
        if (sqgetGlobalVar('media_sel', $media_sel, SQ_POST) && $media_sel == '(none)') {
            removePref($data_dir, $username, 'newmail_media');
        } else {
            setPref($data_dir, $username, 'newmail_media', $media_sel);
        }
        // process uploaded file
        if ($newmail_uploadsounds && isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name'] != '') {
            // set temp file and get media file name
            $newmail_tempmedia = getHashedDir($username, $data_dir) . "/{$username}.tempsound";
            $newmail_mediafile = getHashedFile($username, $data_dir, $username . '.sound');
            if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
                // new media file is in $newmail_tempmedia
                if (file_exists($newmail_mediafile)) {
                    unlink($newmail_mediafile);
                }
                if (!rename($newmail_tempmedia, $newmail_mediafile)) {
                    // remove (userfile), if file rename fails
                    removePref($data_dir, $username, 'newmail_media');
                } else {
                    // store media type
                    if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
                        setPref($data_dir, $username, 'newmail_userfile_type', newmail_get_mediatype($_FILES['media_file']['type'], $_FILES['media_file']['name']));
                    } else {
                        removePref($data_dir, $username, 'newmail_userfile_type');
                    }
                    // store file name
                    if (isset($_FILES['media_file']['name'])) {
                        setPref($data_dir, $username, 'newmail_userfile_name', basename($_FILES['media_file']['name']));
                    } else {
                        setPref($data_dir, $username, 'newmail_userfile_name', 'mediafile.unknown');
                    }
                }
            }
        }
    }
}
function ClearAttachments()
{
    global $username, $attachments, $attachment_dir;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    $rem_attachments = array();
    if (isset($attachments)) {
        foreach ($attachments as $info) {
            if ($info['session'] == -1) {
                $attached_file = "{$hashed_attachment_dir}/{$info['localfilename']}";
                if (file_exists($attached_file)) {
                    unlink($attached_file);
                }
            } else {
                $rem_attachments[] = $info;
            }
        }
    }
    $attachments = $rem_attachments;
}
Example #16
0
 * @package squirrelmail
 */
/**
 * Path for SquirrelMail required files.
 * @ignore
 */
define('SM_PATH', '../');
/* SquirrelMail required files. */
require_once SM_PATH . 'include/validate.php';
require_once SM_PATH . 'functions/prefs.php';
require_once SM_PATH . 'functions/plugin.php';
require_once SM_PATH . 'functions/strings.php';
require_once SM_PATH . 'functions/html.php';
/* Erase any lingering attachments */
if (isset($attachments) && is_array($attachments) && sizeof($attachments)) {
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    foreach ($attachments as $info) {
        $attached_file = "{$hashed_attachment_dir}/{$info['localfilename']}";
        if (file_exists($attached_file)) {
            unlink($attached_file);
        }
    }
}
if (!isset($frame_top)) {
    $frame_top = '_top';
}
/* If a user hits reload on the last page, $base_uri isn't set
 * because it was deleted with the session. */
if (!sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION)) {
    require_once SM_PATH . 'functions/display_messages.php';
    $base_uri = sqm_baseuri();