[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * This script displays a rendered MIME_Part object. 4 * The following are potential URL parameters that we should honor: 5 * 'actionID' -- The action ID to perform 6 * -> 'compose_attach_preview' 7 * -> 'download_all' 8 * -> 'download_attach' 9 * -> 'download_render' 10 * -> 'save_message' 11 * -> 'view_attach' 12 * -> 'view_source' 13 * 'ctype' -- The content-type to use instead of the content-type 14 * found in the original MIME_Part object 15 * 'id' -- The MIME part to display 16 * 'index' -- The index of the message; only used for IMP_Contents 17 * objects 18 * 'zip' -- Download in .zip format? 19 * 20 * $Horde: imp/view.php,v 2.199.4.11 2007/01/02 13:54:54 jan Exp $ 21 * 22 * Copyright 1999-2007 Charles J. Hagenbuch <chuck@horde.org> 23 * Copyright 1999-2007 Jon Parise <jon@horde.org> 24 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 25 * 26 * See the enclosed file COPYING for license information (GPL). If you 27 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 28 */ 29 30 /* We can't register this session as 'readonly' if we are doing a 31 * 'view_attach' since some MIME_Drivers may need to create temporary cache 32 * files to correctly generate links. */ 33 if (isset($_GET['actionID']) && $_GET['actionID'] != 'view_attach') { 34 $session_control = 'readonly'; 35 } 36 37 $no_compress = true; 38 @define('IMP_BASE', dirname(__FILE__)); 39 require_once IMP_BASE . '/lib/base.php'; 40 require_once IMP_BASE . '/lib/MIME/Contents.php'; 41 42 $index = Util::getFormData('index'); 43 $id = Util::getFormData('id'); 44 $actionID = Util::getFormData('actionID'); 45 46 /* 'compose_attach_preview' doesn't use IMP_Contents since there is no 47 * IMAP message data - rather, we must use the IMP_Compose object to 48 * get the necessary MIME_Part. */ 49 if ($actionID == 'compose_attach_preview') { 50 /* Initialize the IMP_Compose:: object. */ 51 require_once IMP_BASE . '/lib/Compose.php'; 52 $imp_compose = &new IMP_Compose(array('cacheID' => Util::getFormData('messageCache'))); 53 $mime = $imp_compose->buildAttachment($id); 54 55 /* Create a dummy MIME_Contents() object so we can use the view 56 * code below. Then use the 'view_attach' handler to output to 57 * the user. */ 58 $contents = &new IMP_Contents(new MIME_Message()); 59 $actionID = 'view_attach'; 60 } else { 61 /* Prevent blind fetching of attachments without knowing the MIME ID. 62 * Index *can* be empty (think embedded MIME parts - there is no 63 * corresponding message index) - but see below; id can be part 0 (whole 64 * message) so just make sure that it's specified. */ 65 if (!in_array($actionID, array('save_message', 'download_all')) 66 && is_null($id)) { 67 exit; 68 } 69 70 /* Get cached item, if available. */ 71 if (!($contents = &IMP_Contents::getCache())) { 72 /* If we make it to here without an index, then something is broken 73 * since there is nothing in the cache and we have no way to create 74 * a viewable object. */ 75 if (empty($index)) { 76 exit; 77 } 78 $contents = &IMP_Contents::singleton($index . IMP_IDX_SEP . $_SESSION['imp']['thismailbox']); 79 } 80 81 if (!in_array($actionID, array('download_attach', 'download_all', 'save_message', 'view_source'))) { 82 $mime = $contents->getDecodedMIMEPart($id); 83 if (($ctype = Util::getFormData('ctype'))) { 84 $mime->setType($ctype); 85 } 86 } 87 } 88 89 /* Run through action handlers */ 90 switch ($actionID) { 91 case 'download_all': 92 $tosave = array(); 93 $headers = &$contents->getHeaderOb(); 94 $headers->buildHeaders(); 95 $zipfile = trim(preg_replace('/[^\w-+_\. ]/', '_', $headers->getValue('subject')), ' _'); 96 if (empty($zipfile)) { 97 $zipfile = _("attachments.zip"); 98 } else { 99 $zipfile .= '.zip'; 100 } 101 foreach ($contents->getDownloadAllList() as $val) { 102 $mime = $contents->getDecodedMIMEPart($val); 103 $tosave[] = array('data' => $mime->getContents(), 'name' => $mime->getName(true, true)); 104 } 105 if (is_a($contents, 'PEAR_Error')) { 106 Horde::fatal($contents, __FILE__, __LINE__); 107 } 108 109 require_once 'Horde/Compress.php'; 110 $horde_compress = &Horde_Compress::singleton('zip'); 111 $body = $horde_compress->compress($tosave); 112 $browser->downloadHeaders($zipfile, 'application/zip', false, strlen($body)); 113 echo $body; 114 exit; 115 116 case 'download_attach': 117 case 'download_render': 118 switch ($actionID) { 119 case 'download_attach': 120 /* Make sure we get the entire contents of the part. */ 121 $mime = $contents->getDecodedMIMEPart($id, true); 122 $body = $mime->getContents(); 123 $type = $mime->getType(true); 124 break; 125 126 case 'download_render': 127 $body = $contents->renderMIMEPart($mime); 128 $type = $contents->getMIMEViewerType($mime); 129 break; 130 } 131 132 $name = $mime->getName(true, true); 133 134 /* Compress output? */ 135 if (($actionID == 'download_attach') && Util::getFormData('zip')) { 136 require_once 'Horde/Compress.php'; 137 $horde_compress = &Horde_Compress::singleton('zip'); 138 $body = $horde_compress->compress(array(array('data' => $body, 'name' => $name))); 139 $name .= '.zip'; 140 $type = 'application/zip'; 141 } 142 $browser->downloadHeaders($name, $type, false, strlen($body)); 143 echo $body; 144 exit; 145 146 case 'view_attach': 147 $body = $contents->renderMIMEPart($mime); 148 $type = $contents->getMIMEViewerType($mime); 149 $browser->downloadHeaders($mime->getName(true, true), $type, true, strlen($body)); 150 echo $body; 151 exit; 152 153 case 'view_source': 154 $msg = $contents->fullMessageText(); 155 $browser->downloadHeaders('Message Source', 'text/plain', true, strlen($msg)); 156 echo $msg; 157 exit; 158 159 case 'save_message': 160 require_once IMP_BASE . '/lib/MIME/Headers.php'; 161 $imp_headers = &new IMP_Headers($index); 162 163 $name = 'saved_message'; 164 if (($subject = $imp_headers->getOb('subject', true))) { 165 $name = trim(preg_replace('/[^\w-+_\. ]/', '_', $subject), ' _'); 166 } 167 168 if (!($from = $imp_headers->getFromAddress())) { 169 $from = '<>'; 170 } 171 $date = strftime('%a %b %d %H:%M:%S %Y', $imp_headers->getOb('udate')); 172 $body = 'From ' . $from . ' ' . $date . "\n" . $contents->fullMessageText(); 173 $body = str_replace("\r\n", "\n", $body); 174 175 $browser->downloadHeaders($name . '.eml', 'message/rfc822', false, strlen($body)); 176 echo $body; 177 exit; 178 }
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 |
![]() |