Changeset 5134 for trunk/expressoMail1_2/inc/class.attachment.inc.php
- Timestamp:
- 11/03/11 13:24:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.attachment.inc.php
r5079 r5134 32 32 * @param integer $msgNumber Imap menssagem number 33 33 */ 34 function attachment( $rootPath = false)34 function attachment() 35 35 { 36 36 /* 37 37 * Requires 38 38 */ 39 if($rootPath)40 {41 require_once $rootPath.'/library/mime/mimePart.php';42 require_once $rootPath.'/library/mime/mimeDecode.php';43 }44 else45 {46 39 require_once $_SESSION['rootPath'].'/library/mime/mimePart.php'; 47 40 require_once $_SESSION['rootPath'].'/library/mime/mimeDecode.php'; 48 }49 41 //----------------------------------------------------------// 50 42 … … 52 44 $this->decodeConf['decode_bodies'] = true; 53 45 $this->decodeConf['decode_headers'] = true; 46 47 if( array_key_exists('nested_messages_are_shown', $_SESSION['phpgw_info']['user']['preferences']['expressoMail']) && ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] == '1')) 48 $this->decodeConf['rfc_822bodies'] = true; 54 49 } 55 50 //----------------------------------------------------------------------------// … … 86 81 $this->structure = $decoder->decode($this->decodeConf); 87 82 83 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 84 if($this->isSignedMenssage()) 85 $this->convertSignedMenssage($rawMessageData); 86 ////////////////////////////////////////////////////// 87 88 88 89 /* 89 90 * Clean memory and close imap connection … … 95 96 } 96 97 98 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 99 private function isSignedMenssage() 100 { 101 if(strtolower($this->structure->ctype_primary) == 'application' && strtolower($this->structure->ctype_secondary) == 'x-pkcs7-mime' ) 102 return true; 103 else 104 return false; 105 } 106 ////////////////////////////////////////////////////////////////////////// 107 108 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 109 private function convertSignedMenssage($rawMessageData) 110 { 111 $decoder = new Mail_mimeDecode($this->extractSignedContents($rawMessageData)); 112 $this->structure = $decoder->decode($this->decodeConf); 113 } 114 /////////////////////////////////////////////////////////////////////////// 115 116 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 117 private function extractSignedContents( $data ) 118 { 119 $pipes_desc = array( 120 0 => array('pipe', 'r'), 121 1 => array('pipe', 'w') 122 ); 123 124 $fp = proc_open( 'openssl smime -verify -noverify -nochain', $pipes_desc, $pipes); 125 if (!is_resource($fp)) { 126 return false; 127 } 128 129 $output = ''; 130 131 /* $pipes[0] => writeable handle connected to child stdin 132 $pipes[1] => readable handle connected to child stdout */ 133 fwrite($pipes[0], $data); 134 fclose($pipes[0]); 135 136 while (!feof($pipes[1])) { 137 $output .= fgets($pipes[1], 1024); 138 } 139 fclose($pipes[1]); 140 proc_close($fp); 141 142 return $output; 143 } 144 ///////////////////////////////////////////////////////////////////////////////////// 145 97 146 /** 98 147 * Set Stucture from Mail_mimeDecode Structure … … 116 165 $decoder = new Mail_mimeDecode($rawMail); 117 166 $this->structure = $decoder->decode($this->decodeConf); 167 168 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 169 if($this->isSignedMenssage()) 170 $this->convertSignedMenssage($rawMessageData); 171 ////////////////////////////////////////////////////////////////////////// 118 172 } 119 173 … … 169 223 $attachment = array(); 170 224 $this->_getPartInfo($this->structure,$partNumber,$attachment); 171 return $attachment ;225 return $attachment[0]; 172 226 } 173 227 … … 180 234 private function _getRaw() 181 235 { 182 return imap_fetchheader($this->mbox, $this->msgNumber, FT_UID).imap_body($this->mbox, $this->msgNumber, FT_UID); 236 /* 237 * Chamada original imap_fetchheader($this->mbox, $this->msgNumber, FT_UID)."\r\n".imap_body($this->mbox, $this->msgNumber, FT_UID); 238 * Inserido replace para corrigir um bug que acontece raramente em mensagens vindas do outlook com muitos destinatarios 239 */ 240 return str_replace("\r\n\t", '', imap_fetchheader($this->mbox, $this->msgNumber, FT_UID))."\r\n".imap_body($this->mbox, $this->msgNumber, FT_UID); 183 241 } 184 242 … … 202 260 else 203 261 { 204 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) )262 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) && $this->decodeConf['rfc_822bodies'] !== true ) 205 263 $this->_getPartContent($part,$soughtIndex,$body,$pIndex.'.'.$index); 206 264 else 207 265 { 208 266 $currentIndex = $pIndex.'.'.$index; 209 if($currentIndex == $soughtIndex)267 if($currentIndex === $soughtIndex) 210 268 { 211 269 $body = $part->body; … … 235 293 else 236 294 { 237 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) )295 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) && $this->decodeConf['rfc_822bodies'] !== true) 238 296 $this->_getPartInfo($part,$soughtIndex,$info,$pIndex.'.'.$index); 239 297 else 240 298 { 241 299 $currentIndex = $pIndex.'.'.$index; 242 if($currentIndex == $soughtIndex)300 if($currentIndex === $soughtIndex) 243 301 { 244 302 $this->_pushAttachmentsInfo($part,$info,$currentIndex); … … 262 320 { 263 321 264 if( $structure->parts)322 if(isset($structure->parts)) 265 323 { 266 324 foreach ($structure->parts as $index => $part) … … 270 328 else 271 329 { 272 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) )330 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) && $this->decodeConf['rfc_822bodies'] !== true) 273 331 $this->_getAttachmentsInfo($part,$attachments,$pIndex.'.'.$index); 274 332 else … … 293 351 /** 294 352 * Write in $$attachments, array with the information of attachment 295 * 296 * @license http://www.gnu.org/copyleft/gpl.html GPL 297 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 298 * @sponsor Caixa Econômica Federal 299 * @param $structure 300 * @param $attachments 301 * @param $pIndex 353 * @param <type> $structure 354 * @param <type> $attachments 355 * @param <type> $pIndex 302 356 */ 303 357 private function _pushAttachmentsInfo(&$structure, &$attachments, $pIndex = '0') 304 358 { 305 $name = false;306 if( $structure->d_parameters['filename']) $name = $structure->d_parameters['filename'];307 else if( $structure->ctype_parameters['name']) $name = $structure->ctype_parameters['name'];359 $name = ''; 360 if((isset($structure->d_parameters['filename']))&& ($structure->d_parameters['filename'])) $name = $structure->d_parameters['filename']; 361 else if((isset($structure->ctype_parameters['name']))&&($structure->ctype_parameters['name'])) $name = $structure->ctype_parameters['name']; 308 362 else if(strtolower($structure->ctype_primary) == 'text' && strtolower($structure->ctype_secondary) == 'calendar') $name = 'calendar.ics'; 309 363 364 //Attachments com nomes grandes são quebrados em varias partes VER RFC2231 365 if( !$name && isset($structure->disposition) && (strtolower($structure->disposition) === 'attachment' || strtolower($structure->ctype_primary) == 'image')) 366 foreach ($structure->d_parameters as $i => $v) 367 if(strpos($i , 'filename') !== false) 368 $name .= urldecode(str_ireplace(array('ISO-8859-1','UTF-8','US-ASCII'),'',$v)); 369 if( !$name && isset($structure->disposition) && (strtolower($structure->disposition) === 'attachment' || strtolower($structure->ctype_primary) == 'image') ) 370 foreach ($structure->ctype_parameters as $i => $v) 371 if(strpos($i , 'name') !== false) 372 $name .= urldecode(str_ireplace(array('ISO-8859-1','UTF-8','US-ASCII'),'',$v)); 373 //////////////////////////////////////////////////////////////////////////////////// 374 375 376 if($structure->ctype_primary == 'message') { 377 $attach = new attachment(); 378 $attach->setStructureFromRawMail($structure->body); 379 380 if (!$name) 381 $name = ($attach->structure->headers['subject']) ? $attach->structure->headers['subject'] : 'no title'; 382 383 if (!preg_match("/\.eml$/", $name)) 384 $name .= '.eml'; 385 } 386 387 if(!$name && strtolower($structure->ctype_primary) == 'image') 388 { 389 if(strlen($structure->ctype_secondary) === 3) 390 $ext = strtolower($structure->ctype_secondary); 391 392 $name = 'Embedded-Image.'.$ext; 393 } 394 310 395 if($name) 311 396 { … … 316 401 $definition['name'] = addslashes(mb_convert_encoding($name, "ISO-8859-1")); 317 402 $definition['encoding'] = $structure->headers['content-transfer-encoding']; 403 $definition['type'] = strtolower($structure->ctype_primary).'/'.strtolower($structure->ctype_secondary); 318 404 $definition['fsize'] = mb_strlen($structure->body, $structure->headers['content-transfer-encoding']); 319 405 … … 334 420 private function _getEmbeddedImagesInfo($structure, &$images, $pIndex = '0') 335 421 { 422 if(isset($structure->parts)) 336 423 foreach ($structure->parts as $index => $part) 337 424 { … … 340 427 else 341 428 { 342 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) )429 if(strtolower($part->ctype_primary) == 'message' && is_array($part->parts) && $this->decodeConf['rfc_822bodies'] !== true) 343 430 $this->_getEmbeddedImagesInfo($part,$images,$pIndex.'.'.$index); 344 431 else 345 432 { 346 if(!$part->ctype_parameters['name']) 433 if(is_array($part->ctype_parameters) && !array_key_exists('name', $part->ctype_parameters)) 434 if(isset($part->d_parameters['filename'])) 347 435 $name = $part->d_parameters['filename']; 348 436 else 437 $name = null; 438 else 349 439 $name = $part->ctype_parameters['name']; 350 440 351 $type = strtolower(substr($name, -4)); 441 if($name && (strlen($name) - (strrpos($name, '.')+1) === 3 )) 442 $ext = strtolower(substr ( $name , (strrpos($name, '.')+1) )); 443 else if(strlen($structure->ctype_secondary) === 3) 444 $ext = strtolower($structure->ctype_secondary); 445 446 if(!$name && strtolower($structure->ctype_primary) == 'image') $name = 'Embedded-Image.'.$ext; 447 352 448 $ctype = strtolower($part->ctype_primary.'/'.$part->ctype_secondary); 353 if(strtolower($part->ctype_primary) == 'image' || ($ctype == 'application/octet-stream' && ($type == '.png' || $type == '.jpg' || $type == '.gif'))) 449 450 if(strtolower($part->ctype_primary) == 'image' || ($ctype == 'application/octet-stream' && ($ext == 'png' || $ext == 'jpg' || $ext == 'gif' || $ext == 'bmp' || $ext == 'tif'))) 354 451 { 355 452 $definition['pid'] = $pIndex.'.'.$index; 356 453 $definition['name'] = addslashes($name); 357 $definition['type'] = 'image/'.strtolower($part->ctype_secondary);454 $definition['type'] = $ctype; 358 455 $definition['encoding'] = $part->headers['content-transfer-encoding']; 359 456 $definition['cid'] = $part->headers['content-id'];
Note: See TracChangeset
for help on using the changeset viewer.