[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * $Horde: imp/attachment.php,v 2.5.10.19 2007/01/02 13:54:53 jan Exp $ 4 * 5 * Copyright 2004-2007 Andrew Coleman <mercury@appisolutions.net> 6 * 7 * See the enclosed file COPYING for license information (GPL). If you 8 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 9 * 10 * This file should be the basis for serving hosted attachments. It 11 * should fetch the file from the VFS and funnel it to the client 12 * wishing to download the attachment. This will allow for the 13 * exchange of massive attachments without causing mail server havoc. 14 */ 15 16 // Set up initial includes. 17 // This does *not* include IMP's base.php because we do not need to be 18 // authenticated to get the file. Most users won't send linked 19 // attachments just to other IMP users. 20 if (!defined('HORDE_BASE')) { 21 @define('HORDE_BASE', dirname(__FILE__) . '/..'); 22 } 23 @define('IMP_BASE', dirname(__FILE__)); 24 require_once HORDE_BASE . '/lib/core.php'; 25 require_once 'VFS.php'; 26 require_once 'Horde/MIME/Magic.php'; 27 $registry = &Registry::singleton(); 28 $registry->importConfig('imp'); 29 30 $_self_url = Horde::selfUrl(false, true, true); 31 32 // Lets see if we are even able to send the user an attachment. 33 if (!$conf['compose']['link_attachments']) { 34 Horde::fatal(_("Linked attachments are forbidden."), $_self_url, __LINE__); 35 } 36 37 // Gather required form variables. 38 $mail_user = Util::getFormData('u'); 39 $time_stamp = Util::getFormData('t'); 40 $file_name = Util::getFormData('f'); 41 if (!isset($mail_user) || !isset($time_stamp) || !isset($file_name) || 42 $mail_user == '' || $time_stamp == '' || $file_name == '') { 43 Horde::fatal(_("The attachment was not found."), 44 $_self_url, __LINE__); 45 } 46 47 // Initialize the VFS. 48 $vfsroot = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type'])); 49 if (is_a($vfsroot, 'PEAR_Error')) { 50 Horde::fatal(sprintf(_("Could not create the VFS backend: %s"), $vfsroot->getMessage()), $_self_url, __LINE__); 51 } 52 53 // Check if the file exists. 54 $mail_user = basename($mail_user); 55 $time_stamp = basename($time_stamp); 56 $file_name = escapeshellcmd(basename($file_name)); 57 $full_path = sprintf('.horde/imp/attachments/%s/%d', $mail_user, $time_stamp); 58 if (!$vfsroot->exists($full_path, $file_name)) { 59 Horde::fatal(_("The specified file does not exist."), $_self_url, __LINE__); 60 } 61 62 // Check to see if we need to send a verification message. 63 if ($conf['compose']['link_attachments_notify']) { 64 if ($vfsroot->exists($full_path, $file_name . '.notify')) { 65 $delete_id = Util::getFormData('d'); 66 $read_id = $vfsroot->read($full_path, $file_name . '.notify'); 67 if (is_a($read_id, 'PEAR_Error')) { 68 Horde::logMessage($read_id, __FILE__, __LINE__, PEAR_LOG_ERR); 69 } elseif ($delete_id == $read_id) { 70 $vfsroot->deleteFile($full_path, $file_name); 71 $vfsroot->deleteFile($full_path, $file_name . '.notify'); 72 printf(_("Attachment %s deleted."), $file_name); 73 exit; 74 } 75 } else { 76 /* Create a random identifier for this file. */ 77 $id = base_convert($file_name . microtime(), 10, 36); 78 $res = $vfsroot->writeData($full_path, $file_name . '.notify' , $id, true); 79 if (is_a($res, 'PEAR_Error')) { 80 Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR); 81 } else { 82 /* Load $mail_user's preferences so that we can use their 83 * locale for the notification message. */ 84 include_once 'Horde/Prefs.php'; 85 $mail_prefs = &Prefs::singleton($conf['prefs']['driver'], 86 'horde', $mail_user); 87 $mail_prefs->retrieve(); 88 include_once 'Horde/Identity.php'; 89 $mail_identity = &Identity::singleton('none', $mail_user); 90 $mail_address = $mail_identity->getDefaultFromAddress(); 91 /* Ignore missing addresses, which are returned as <>. */ 92 if (strlen($mail_address) > 2) { 93 $mail_address_full = $mail_identity->getDefaultFromAddress(true); 94 NLS::setLang($mail_prefs->getValue('language')); 95 NLS::setTextdomain('imp', IMP_BASE . '/locale', NLS::getCharset()); 96 String::setDefaultCharset(NLS::getCharset()); 97 98 /* Set up the mail headers and read the log file. */ 99 include_once 'Horde/MIME/Headers.php'; 100 $msg_headers = new MIME_Headers(); 101 $msg_headers->addReceivedHeader(); 102 $msg_headers->addMessageIdHeader(); 103 $msg_headers->addAgentHeader(); 104 $msg_headers->addHeader('Date', date('r')); 105 $msg_headers->addHeader('From', $mail_address_full); 106 $msg_headers->addHeader('To', $mail_address_full); 107 $msg_headers->addHeader('Subject', _("Notification: Linked attachment downloaded")); 108 109 include_once 'Horde/MIME/Message.php'; 110 $msg = new MIME_Message(); 111 $msg->setType('text/plain'); 112 $msg->setCharset(NLS::getCharset()); 113 $msg->setContents(String::wrap(sprintf(_("Your linked attachment has been downloaded by at least one user.\n\nAttachment name: %s\nAttachment date: %s\n\nClick on the following link to permanently delete the attachment:\n%s"), $file_name, date('r', $time_stamp), Util::addParameter(Horde::selfUrl(true, false, true), 'd', $id)))); 114 115 $msg_headers->addMIMEHeaders($msg); 116 117 $msg->send($mail_address, $msg_headers); 118 } 119 } 120 } 121 } 122 123 // Find the file's mime-type. 124 $file_data = $vfsroot->read($full_path, $file_name); 125 if (is_a($file_data, 'PEAR_Error')) { 126 Horde::logMessage($file_data, __FILE__, __LINE__, PEAR_LOG_ERR); 127 Horde::fatal(_("The specified file cannot be read."), $_self_url, __LINE__); 128 } 129 $mime_type = MIME_Magic::analyzeData($file_data, isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null); 130 if ($mime_type === false) { 131 $type = MIME_Magic::filenameToMIME($file_name, false); 132 } 133 134 // Send the client the file. 135 $browser->downloadHeaders($file_name, $mime_type, false, strlen($file_data)); 136 echo $file_data;
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |