Exemplo n.º 1
0
    }
    if ($filename == '') {
        $filename = 'untitled' . strip_tags($ent_id);
    }
    $filename = $filename . '.' . $suffix;
}
/*
 * Note:
 *    The following sections display the attachment in different
 *    ways depending on how they choose.  The first way will download
 *    under any circumstance.  This sets the Content-type to be
 *    applicatin/octet-stream, which should be interpreted by the
 *    browser as "download me".
 *      The second method (view) is used for images or other formats
 *    that should be able to be handled by the browser.  It will
 *    most likely display the attachment inline inside the browser.
 *      And finally, the third one will be used by default.  If it
 *    is displayable (text or html), it will load them up in a text
 *    viewer (built in to squirrelmail).  Otherwise, it sets the
 *    content-type as application/octet-stream
 */
if (isset($absolute_dl) && $absolute_dl) {
    SendDownloadHeaders($type0, $type1, $filename, 1);
} else {
    SendDownloadHeaders($type0, $type1, $filename, 0);
}
/* be aware that any warning caused by download.php will corrupt the
 * attachment in case of ERROR reporting = E_ALL and the output is the screen */
mime_print_body_lines($imapConnection, $passed_id, $ent_id, $encoding);
$mailbox_cache[$aMailbox['NAME']] = $aMailbox;
sqsession_register($mailbox_cache, 'mailbox_cache');
Exemplo n.º 2
0
function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection)
{
    global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages;
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
    if (!count($message->entities) || $message->type0 == 'message' && $message->type1 == 'rfc822') {
        if (!in_array($message->entity_id, $entities) && $message->entity_id) {
            switch ($message->type0) {
                case 'message':
                    if ($message->type1 == 'rfc822') {
                        $filename = $message->rfc822_header->subject;
                        if ($filename == "") {
                            $filename = "untitled-" . $message->entity_id;
                        }
                        $filename .= '.msg';
                    } else {
                        $filename = $message->getFilename();
                    }
                    break;
                default:
                    if (!$message->mime_header) {
                        /* temporary hack */
                        $message->mime_header = $message->header;
                    }
                    $filename = $message->getFilename();
                    break;
            }
            $filename = decodeHeader($filename, false, false);
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
                $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
            }
            $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}";
            }
            $fp = fopen("{$hashed_attachment_dir}/{$localfilename}", 'wb');
            $message->att_local_name = $full_localfilename;
            $composeMessage->initAttachment($message->type0 . '/' . $message->type1, $filename, $full_localfilename);
            /* Write Attachment to file 
                  The function mime_print_body_lines writes directly to the 
                  provided resource $fp. That prohibits large memory consumption in
                  case of forwarding mail with large attachments.
               */
            mime_print_body_lines($imapConnection, $passed_id, $message->entity_id, $message->header->encoding, $fp);
            fclose($fp);
        }
    } else {
        for ($i = 0, $entCount = count($message->entities); $i < $entCount; $i++) {
            $composeMessage = getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
        }
    }
    return $composeMessage;
}
Exemplo n.º 3
0
/**
 * downloads attachments from original message, stores them in attachment directory and adds
 * them to composed message.
 * @param object $message
 * @param object $composeMessage
 * @param integer $passed_id
 * @param mixed $entities
 * @param mixed $imapConnection
 * @return object
 */
function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection)
{
    global $squirrelmail_language, $languages, $username, $attachment_dir;
    if (!count($message->entities) || $message->type0 == 'message' && $message->type1 == 'rfc822') {
        if (!in_array($message->entity_id, $entities) && $message->entity_id) {
            switch ($message->type0) {
                case 'message':
                    if ($message->type1 == 'rfc822') {
                        $filename = $message->rfc822_header->subject;
                        if ($filename == "") {
                            $filename = "untitled-" . $message->entity_id;
                        }
                        $filename .= '.eml';
                    } else {
                        $filename = $message->getFilename();
                    }
                    break;
                default:
                    if (!$message->mime_header) {
                        /* temporary hack */
                        $message->mime_header = $message->header;
                    }
                    $filename = $message->getFilename();
                    break;
            }
            //FIXME: added three args to the following, so as to set the last one to TRUE, to mimick a fix in 1.4.21 (#2994865), but didn't test this (note that in 1.4.21, the 2nd and 3rd args are FALSE, but here in this code, they weren't being specified (thus defaulting to TRUE), so I don't know if that means this code is outdated and should have been changed to FALSE, FALSE or if this code is completely different and the addition of the TRUE for arg #4 is wrong
            $filename = str_replace('&#32;', ' ', decodeHeader($filename, true, true, true));
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
                $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename);
            }
            $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
            $localfilename = sq_get_attach_tempfile();
            $message->att_local_name = $localfilename;
            $composeMessage->initAttachment($message->type0 . '/' . $message->type1, $filename, $localfilename);
            /* Write Attachment to file */
            $fp = fopen($hashed_attachment_dir . '/' . $localfilename, 'wb');
            mime_print_body_lines($imapConnection, $passed_id, $message->entity_id, $message->header->encoding, $fp);
            fclose($fp);
        }
    } else {
        for ($i = 0, $entCount = count($message->entities); $i < $entCount; $i++) {
            $composeMessage = getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
        }
    }
    return $composeMessage;
}
Exemplo n.º 4
0
 * mime_print_body_lines() call duration depends on size of 
 * attachment and script can cause interface lockups, if session 
 * is not closed.
 */
$mailbox_cache[$aMailbox['NAME']] = $aMailbox;
sqsession_register($mailbox_cache, 'mailbox_cache');
session_write_close();
/*
 * Note:
 *    The following sections display the attachment in different
 *    ways depending on how they choose.  The first way will download
 *    under any circumstance.  This sets the Content-type to be
 *    applicatin/octet-stream, which should be interpreted by the
 *    browser as "download me".
 *      The second method (view) is used for images or other formats
 *    that should be able to be handled by the browser.  It will
 *    most likely display the attachment inline inside the browser.
 *      And finally, the third one will be used by default.  If it
 *    is displayable (text or html), it will load them up in a text
 *    viewer (built in to SquirrelMail).  Otherwise, it sets the
 *    content-type as application/octet-stream
 */
if (isset($absolute_dl) && $absolute_dl) {
    SendDownloadHeaders($type0, $type1, $filename, 1);
} else {
    SendDownloadHeaders($type0, $type1, $filename, 0);
}
/* be aware that any warning caused by download.php will corrupt the
 * attachment in case of ERROR reporting = E_ALL and the output is the screen */
mime_print_body_lines($imapConnection, $passed_id, $ent_id, $encoding, 'php://stdout', $force_crlf);