Changeset 5359
- Timestamp:
- 01/11/12 14:02:37 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.attachment.inc.php
r5316 r5359 168 168 //TODO: Descartar código após atualização do módulo de segurança da SERPRO 169 169 if($this->isSignedMenssage()) 170 $this->convertSignedMenssage($rawM essageData);170 $this->convertSignedMenssage($rawMail); 171 171 ////////////////////////////////////////////////////////////////////////// 172 172 } … … 379 379 380 380 if (!$name) 381 $name = ( $attach->structure->headers['subject']) ? $attach->structure->headers['subject'] : 'no title';381 $name = (isset($attach->structure->headers['subject'])) ? $attach->structure->headers['subject'] : 'no title'; 382 382 383 383 if (!preg_match("/\.eml$/", $name)) … … 464 464 $definition['name'] = addslashes($name); 465 465 $definition['type'] = $ctype; 466 $definition['encoding'] = $part->headers['content-transfer-encoding'];467 $definition['cid'] = $part->headers['content-id'];466 $definition['encoding'] = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : 'base64'; 467 $definition['cid'] = isset($part->headers['content-id']) ? $part->headers['content-id'] : ''; 468 468 array_push($images, $definition); 469 469 } -
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r5346 r5359 20 20 var $ldap; 21 21 var $mbox; 22 var $mboxFolder; 22 23 var $imap_port; 23 24 var $has_cid; … … 29 30 var $rawMessage; 30 31 var $folders; 31 32 32 var $cache = false; 33 var $useCache = false; 34 var $expirationCache = false; 35 33 36 function imap_functions (){ 34 37 $this->init(); 35 38 } 36 39 37 40 function init(){ 38 41 $this->foldersLimit = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] ? $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] : 20000; //Limit of folders (mailboxes) user can see … … 53 56 $this->folders['trash'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ? 'Trash' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; 54 57 58 if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache']) && $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache'] === 'true') 59 $this->useCache = true; 60 61 if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) && trim($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) != '') 62 $this->expirationCache = $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']; 63 55 64 if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 56 {57 65 $this->imap_options = '/tls/novalidate-cert'; 58 }59 66 else 60 {61 67 $this->imap_options = '/notls/novalidate-cert'; 62 }68 63 69 } 64 70 … … 68 74 69 75 // BEGIN of functions. 70 function open_mbox($folder = False,$force_die=true) 71 { 72 $folder = mb_convert_encoding($folder, "UTF7-IMAP",'UTF-8, ISO-8859-1, UTF7-IMAP'); 73 if (is_resource($this->mbox)) 74 { 75 if ($force_die) 76 { 77 @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 78 } 79 else 80 { 81 @imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder); 82 } 83 } 76 function open_mbox( $folder = false, $force_die = true) 77 { 78 $this->mboxFolder = mb_convert_encoding($folder, 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP'); 79 $url = '{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$this->mboxFolder; 80 81 if (is_resource($this->mbox)) 82 if ($force_die) 83 imap_reopen($this->mbox, $url ) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 84 else 85 imap_reopen($this->mbox, $url ); 86 else 87 if($force_die) 88 $this->mbox = imap_open( $url , $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 84 89 else 85 { 86 if($force_die) 87 { 88 $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 89 } 90 else 91 { 92 $this->mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password); 93 } 94 95 } 96 return $this->mbox; 90 $this->mbox = imap_open( $url , $this->username, $this->password); 91 92 return $this->mbox; 97 93 } 98 94 … … 127 123 function get_range_msgs2($params) 128 124 { 129 // Free others requests 130 session_write_close(); 131 $folder = $params['folder']; 132 $msg_range_begin = $params['msg_range_begin']; 133 $msg_range_end = $params['msg_range_end']; 134 $sort_box_type = isset($params['sort_box_type']) ? $params['sort_box_type'] : ''; 135 $sort_box_reverse = isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : ''; 136 $search_box_type = (isset($params['search_box_type']) && $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" )? $params['search_box_type'] : false; 137 138 if( !$this->mbox || !is_resource( $this->mbox ) ) 139 $this->mbox = $this->open_mbox($folder); 140 141 $return = array(); 142 143 $return['folder'] = $folder; 144 145 //Para enviar o offset entre o timezone definido pelo usuário e GMT 146 $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); 147 148 if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") { 149 $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, "UTF7-IMAP", "ISO_8859-1" ) ,SA_ALL); 150 151 152 $return['tot_unseen'] = $search_box_type == "SEEN" ? 0 : $msgs_info->unseen; 153 154 $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 155 156 $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); 157 158 $i = 0; 159 if(is_array($sort_array_msg)){ 160 foreach($sort_array_msg as $msg_number => $value) 161 { 162 $temp = $this->get_info_head_msg($msg_number); 163 $temp['msg_sample'] = $this->get_msg_sample($msg_number,$folder); 164 if(!$temp) 165 return false; 166 167 $return[$i] = $temp; 168 $i++; 169 } 170 } 171 $return['num_msgs'] = $num_msgs; 125 // Free others requests 126 session_write_close(); 127 $folder = $params['folder']; 128 $msg_range_begin = $params['msg_range_begin']; 129 $msg_range_end = $params['msg_range_end']; 130 $sort_box_type = isset($params['sort_box_type']) ? $params['sort_box_type'] : ''; 131 $sort_box_reverse = isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : ''; 132 $search_box_type = (isset($params['search_box_type']) && $params['search_box_type'] != 'ALL' && $params['search_box_type'] != '' )? $params['search_box_type'] : false; 133 134 if( !$this->mbox || !is_resource( $this->mbox ) ) 135 $this->mbox = $this->open_mbox($folder); 136 137 $return = array(); 138 $return['folder'] = $folder; 139 //Para enviar o offset entre o timezone definido pelo usuário e GMT 140 $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); 141 142 if(!$search_box_type || $search_box_type == 'UNSEEN' || $search_box_type == 'SEEN') { 143 $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, 'UTF7-IMAP', 'ISO_8859-1' ) ,SA_ALL); 144 145 $return['tot_unseen'] = ($search_box_type == 'SEEN') ? 0 : $msgs_info->unseen; 146 147 $sort_array_msg = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 148 149 $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); 150 151 $i = 0; 152 if(is_array($sort_array_msg)){ 153 foreach($sort_array_msg as $msg_number => $value) 154 { 155 $sample = false; 156 if( (isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] === '1')) && 157 (isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] === '1')) ) 158 $sample = true; 159 160 $return[$i] = $this->get_info_head_msg( $msg_number , $sample ) ; 161 $i++; 162 } 163 } 164 $return['num_msgs'] = $num_msgs; 172 165 } 173 166 else { … … 200 193 return $return; 201 194 } 202 203 function get_info_head_msg($msg_number) 204 { 205 $head_array = array(); 206 include_once("class.imap_attachment.inc.php"); 207 208 $imap_attachment = new imap_attachment(); 209 //if ($this->prefs['use_important_flag'] ) 210 //{ 211 /*Como eu preciso do atributo Importance para saber se o email é 212 * importante ou não, uso abaixo a função imap_fetchheader e busco 213 * o atributo importance nela. Isso faz com que eu acesse o cabeçalho 214 * duas vezes e de duas formas diferentes, mas em contrapartida, eu 215 * não preciso reimplementar o método utilizando o fetchheader. 216 * Como as mensagens são renderizadas em um número pequeno por vez, 217 * não parece ter perda considerável de performance. 218 */ 219 220 $tempHeader = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); 221 $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); 222 //} 223 // Reimplementado código para identificação dos e-mails assinados e cifrados 224 // no método getMessageType(). Mário César Kolling <mario.kolling@serpro.gov.br> 225 $head_array['ContentType'] = $this->getMessageType($msg_number, $tempHeader); 226 $head_array['Importance'] = $flag==0?"Normal":$importance[1]; 227 228 $header = $this->get_header($msg_number); 229 if (!is_object($header)) 230 return false; 231 $head_array['Recent'] = $header->Recent; 232 $head_array['Unseen'] = $header->Unseen; 233 if($header->Answered =='A' && $header->Draft == 'X'){ 234 $head_array['Forwarded'] = 'F'; 235 } 236 else { 237 $head_array['Answered'] = $header->Answered; 238 $head_array['Draft'] = $header->Draft; 239 } 240 $head_array['Deleted'] = $header->Deleted; 241 $head_array['Flagged'] = $header->Flagged; 242 $head_array['msg_number'] = $msg_number; 243 $head_array['udate'] = $header->udate; 244 $head_array['offsetToGMT'] = $this->functions->CalculateDateOffset(); 245 246 $msgTimestamp = $header->udate + $head_array['offsetToGMT']; 247 $head_array['timestamp'] = $msgTimestamp; 248 249 $date_msg = gmdate("d/m/Y",$msgTimestamp); 250 // if (date("d/m/Y") == $date_msg) 251 // $return['udate'] = $header->udate; 252 // else 253 254 if (date("d/m/Y") == $date_msg) //no dia 255 { 256 $head_array['smalldate'] = gmdate("H:i",$msgTimestamp); 195 196 /** 197 * Decodifica uma string no formato mime RFC2047 198 * 199 * @license http://www.gnu.org/copyleft/gpl.html GPL 200 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 201 * @sponsor Caixa Econômica Federal 202 * @author Cristiano Corrêa Schmidt 203 * @param string $string string no formato mime RFC2047 204 * @return string 205 * @access public 206 */ 207 static function decodeMimeString( $string ) 208 { 209 return preg_replace_callback( '/\=\?([^\?]*)\?([qb])\?([^\?]*)\?=/i' ,array( self , 'decodeMimeStringCallback'), $string); 210 } 211 212 /** 213 * Decodifica os tokens encontrados na função decodeMimeString 214 * 215 * @license http://www.gnu.org/copyleft/gpl.html GPL 216 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 217 * @sponsor Caixa Econômica Federal 218 * @author Cristiano Corrêa Schmidt 219 * @param array $mathes array retornado pelo preg_replace_callback da função decodeMimeString 220 * @return string 221 * @access public 222 */ 223 static function decodeMimeStringCallback( $mathes ) 224 { 225 $str = (strtolower($mathes[2]) == 'q') ? quoted_printable_decode(str_replace('_','=20',$mathes[3])) : base64_decode( $mathes[3]) ; 226 return ( strtoupper($mathes[1]) == 'UTF-8' ) ? mb_convert_encoding( $str , 'ISO-8859-1' , 'UTF-8') : $str; 227 } 228 229 /** 230 * Formata um mailObject para um array com name e email 231 * 232 * @license http://www.gnu.org/copyleft/gpl.html GPL 233 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 234 * @sponsor Caixa Econômica Federal 235 * @author Cristiano Corrêa Schmidt 236 * @return bool 237 * @access public 238 */ 239 static function formatMailObject( $obj ) 240 { 241 $return = array(); 242 $return['email'] = self::decodeMimeString($obj->mailbox) . (isset( $obj->host ) ? '@'. $obj->host : ''); 243 $return['name'] = ( isset( $obj->personal ) && trim($obj->personal) !== '' ) ? self::decodeMimeString($obj->personal) : $return['email']; 244 return $return; 245 } 246 247 /** 248 * Retorna informações do cabeçario da mensagem e um preview caso appendSample = true 249 * Utiliza memCache caso esta preferencia esteja ativada. 250 * 251 * @license http://www.gnu.org/copyleft/gpl.html GPL 252 * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 253 * @sponsor Caixa Econômica Federal 254 * @author Cristiano Corrêa Schmidt 255 * @return bool 256 * @access public 257 */ 258 function get_info_head_msg( $msg_number , $appendSample = false ) 259 { 260 $return = false; 261 $cached = false; 262 if( $this->useCache === true ) 263 { 264 if( $this->cache === false ) 265 { 266 $this->cache = ServiceLocator::getService( 'memCache' ); //Serviço Cache 267 $this->cache->connect( $_SESSION['phpgw_info']['expressomail']['server']['server_memcache'] , $_SESSION['phpgw_info']['expressomail']['server']['port_server_memcache'] ); 257 268 } 258 else 259 { 260 $head_array['smalldate'] = gmdate("d/m/Y",$msgTimestamp); 261 } 262 263 if(isset($header->from)) 264 $from = $header->from; 265 $head_array['from'] = array(); 266 $head_array['from']['name'] = ( isset( $from[0]->personal ) ) ? $this->decode_string($from[0]->personal) : NULL; 267 if(isset($from)) 268 $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; 269 else 270 $head_array['from']['email'] = $this->decode_string($from[0]->mailbox) . "@"; 271 if(!$head_array['from']['name'] || trim($head_array['from']['name']) === '' ) 272 $head_array['from']['name'] = $head_array['from']['email']; 273 if(isset($header->to)) 274 $to = $header->to; 275 $head_array['to'] = array(); 276 if(isset($to[1]) && isset($to[1]->host) && $to[1]->host == ".SYNTAX-ERROR.") { //E-mails que não possuem o campo "para", vêm com o recipiente preenchido, porém com um recipiente a mais alegando erro de sintaxe. 277 $head_array['to']['name'] = $head_array['to']['email'] = NULL; 278 } 279 else { 280 $tmp = ( isset( $to[0]->personal ) ) ? imap_mime_header_decode($to[0]->personal) : NULL; 281 $head_array['to']['name'] = ( isset( $tmp[0]->text ) ) ? $this->decode_string($this->decode_string($tmp[0]->text)) : NULL; 282 $head_array['to']['email'] = ( isset( $to[0]->mailbox ) ) ? ( $this->decode_string($to[0]->mailbox) . "@" . ( ( isset( $to[0]->host ) ) ? $to[0]->host : '' ) ) : NULL; 283 if(!$head_array['to']['name']) 284 $head_array['to']['name'] = $head_array['to']['email']; 285 } 286 $cc = null; 287 $cco = null; 288 if(isset($header->cc)){ 289 $cc = $header->cc; 290 } 291 if(isset($header->bcc)){ 292 $cco = $header->bcc; 293 } 294 if ( ($cc) && (!$head_array['to']['name']) ){ 295 $head_array['to']['name'] = ( isset( $cc[0]->personal ) ) ? $this->decode_string($cc[0]->personal) : NULL; 296 $head_array['to']['email'] = $this->decode_string($cc[0]->mailbox) . "@" . $cc[0]->host; 297 if(!$head_array['to']['name']){ 298 $head_array['to']['name'] = $head_array['from']['name']; 299 //$head_array['to']['email'] = $head_array['from']['email']; 300 } 301 } 302 else if ( ($cco) && (!$head_array['to']['name']) ){ 303 $head_array['to']['name'] = ( isset( $cco[0]->personal ) ) ? $this->decode_string($cco[0]->personal) : NULL; 304 $head_array['to']['email'] = $this->decode_string($cco[0]->mailbox) . "@" . $cco[0]->host; 305 if(!$head_array['to']['name']) 306 $head_array['to']['name'] = $head_array['from']['name']; 307 } 308 $head_array['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; 309 if($head_array['subject'] == "" || $head_array['subject'] == '' || $head_array['subject'] == null ){ 310 $head_array['subject'] = $this->functions->getLang("(no subject) "); 311 } 312 313 if($head_array['to']['name'] == 'undisclosed-recipients@' || $head_array['to']['name'] == '@'){ 314 $head_array['to']['name'] = $head_array['from']['name']; 315 $head_array['to']['email'] = $head_array['from']['email']; 316 } 317 318 $head_array['Size'] = $header->Size; 319 320 $head_array['attachment'] = array(); 321 $head_array['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 322 323 return $head_array; 269 270 if( $return = $this->cache->get( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number )) 271 $cached = true; 272 } 273 274 $header = imap_headerinfo($this->mbox, imap_msgno( $this->mbox , $msg_number )); //Resgata o objeto Header da mensagem , nescessario mesmo com o cache pois as flags podem ser atualizadas por outro cliente de email 275 $return['Recent'] = $header->Recent; 276 $return['Unseen'] = $header->Unseen; 277 $return['Deleted'] = $header->Deleted; 278 $return['Flagged'] = $header->Flagged; 279 if($header->Answered =='A' && $header->Draft == 'X') 280 $return['Forwarded'] = 'F'; 281 else 282 { 283 $return['Answered'] = $header->Answered; 284 $return['Draft'] = $header->Draft; 285 } 286 287 if( $cached === true ) //Caso a mensagem ja tenha vindo do cache da o return 288 { 289 if($appendSample !== false && !isset($return['msg_sample'])) //verifica o msg_sample caso seja alterada a preferencia e não esteja em cache carregar 290 $return['msg_sample'] = $this->get_msg_sample($msg_number); 291 292 return $return; 293 } 294 295 $importance = array(); 296 $mimeHeader = imap_fetchheader( $this->mbox, $msg_number , FT_UID ); //Resgata o Mime Header da mensagem 297 $mimeBody = imap_body( $this->mbox, $msg_number , FT_UID ); //Resgata o Mime Body da mensagem 298 $offsetToGMT = $this->functions->CalculateDateOffset(); 299 $return['ContentType'] = $this->getMessageType( $msg_number , $mimeHeader , $mimeBody ); 300 $return['Importance'] = ( preg_match('/importance *: *(.*)\r/i', $mimeHeader , $importance) === 0 ) ? 'Normal' : $importance[1]; 301 $return['msg_number'] = $msg_number; 302 $return['udate'] = $header->udate; 303 $return['offsetToGMT'] = $offsetToGMT; 304 $return['timestamp'] = $header->udate + $return['offsetToGMT']; 305 $return['smalldate'] = (date('d/m/Y') == gmdate( 'd/m/Y', $return['timestamp'] )) ? gmdate("H:i", $return['timestamp'] ) : gmdate("d/m/Y", $return['timestamp'] ); 306 $return['Size'] = $header->Size; 307 $return['from'] = (isset( $header->from[0] )) ? self::formatMailObject( $header->from[0] ) : array( 'name' => '' , 'email' => ''); 308 $return['subject'] = ( isset($header->subject) && trim($header->subject) !== '' ) ? self::decodeMimeString($header->subject) : $this->functions->getLang('(no subject) '); 309 $return['attachment'] = ( preg_match('/((Content-Disposition:(.)*(\r\n filename=|filename=))|(Content-Type:(.)*(\r\n name=|name=)))/', $mimeBody) ) ? '1' : '0'; //Verifica se a anexos na mensagem 310 $return['reply_toaddress'] = isset($header->reply_toaddress) ? $header->reply_toaddress : ''; 311 $return['flag'] = $header->Unseen.$header->Recent.$header->Flagged.$header->Draft.$header->Answered.$header->Deleted.( $return['attachment'] === '1' ? 'T': '' ); 312 313 if( isset( $header->to[0] )) 314 $return['to'] = self::formatMailObject( $header->to[0] ); 315 else if( isset( $header->cc[0] )) 316 $return['to'] = self::formatMailObject( $header->cc[0] ); 317 else if( isset( $header->bcc[0] )) 318 $return['to'] = self::formatMailObject( $header->bcc[0] ); 319 else 320 $return['to'] = array( 'name' => '' , 'email' => ''); 321 322 if($return['to']['name'] == 'undisclosed-recipients@' || $return['to']['name'] == '@') 323 $return['to'] = $return['from']; 324 325 if($appendSample !== false) 326 $return['msg_sample'] = $this->get_msg_sample($msg_number); 327 328 if( $this->useCache === true ) 329 $this->cache->set( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number , $return , $this->expirationCache); 330 331 return $return; 324 332 } 325 333 … … 880 888 function get_msg_sample($msg_number) 881 889 { 882 $content = ''; 883 884 $return = ""; 885 if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) && 886 (!isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] != "1")) ) 887 { 888 $return['body'] = ""; 889 return $return; 890 } 891 892 include_once("class.message_components.inc.php"); 890 $content = ''; 891 $return = array(); 892 893 include_once('class.message_components.inc.php'); 893 894 $msg = new message_components($this->mbox); 894 895 $msg->fetch_structure($msg_number); … … 896 897 if(!isset($msg->structure[$msg_number]->parts)) 897 898 { 898 $content = ''; 899 if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") 900 { 901 $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); 902 } 899 $content = ''; 900 if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") 901 $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); 903 902 } 904 903 else 905 904 { 906 foreach($msg->pid[$msg_number] as $values => $msg_part) 907 { 908 909 $file_type = strtolower($msg->file_type[$msg_number][$values]); 910 if($file_type == "text/plain" || $file_type == "text/html") { 911 $content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); 912 break; 913 } 914 } 915 } 916 905 foreach($msg->pid[$msg_number] as $values => $msg_part) 906 { 907 $file_type = strtolower($msg->file_type[$msg_number][$values]); 908 if($file_type == "text/plain" || $file_type == "text/html") { 909 $content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); 910 break; 911 } 912 } 913 } 914 917 915 $tags_replace = array("<br>","<br/>","<br />"); 918 916 $content = str_replace($tags_replace," ", nl2br($content)); 919 917 $content = $this->html2txt($content); 920 918 $content != "" ? $return['body'] = " - " . $content: $return['body'] = ""; 921 $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1' ));919 $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1' , 'UTF-8,ISO-8859-1')); 922 920 return $return; 923 921 } 922 924 923 function html2txt($document){ 925 924 $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript … … 1265 1264 if($return['toaddress2'] == 'undisclosed-recipients@, @'){ 1266 1265 $return['toaddress2'] = $this->functions->getLang('without destination'); 1267 } 1266 } 1268 1267 return $return; 1269 1268 } … … 1276 1275 * @author luka8088 <luka8088@gmail.com> 1277 1276 */ 1278 function utf8_to_html ($data)1279 { 1280 return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", ' $this->_utf8_to_html("\\1")', $data);1277 static function utf8_to_html ($data) 1278 { 1279 return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", 'self::_utf8_to_html("\\1")', $data); 1281 1280 } 1282 1281 1283 function _utf8_to_html ($data)1284 1282 static function _utf8_to_html ($data) 1283 { 1285 1284 $ret = 0; 1286 1285 foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) 1287 1286 $ret += (ord($v) % 128) * pow(64, $k); 1288 1287 return html_entity_decode("&#$ret;" , ENT_QUOTES); 1289 1288 } 1290 1289 //------------------------------------------------------------------------------// 1291 1290 … … 1298 1297 */ 1299 1298 function decodeMailPart($part, $encode, $html = true) 1300 1299 { 1301 1300 switch (strtolower($encode)) 1302 1301 { 1303 1302 case 'iso-8859-1': 1304 1303 return $part; 1305 1304 break; 1306 1307 1305 case 'utf-8': 1308 if ($html) return $this->utf8_to_html($part);1306 if ($html) return self::utf8_to_html($part); 1309 1307 else return utf8_decode ($part); 1310 1308 break; 1311 1312 1309 default: 1313 1310 return mb_convert_encoding($part, 'iso-8859-1'); 1314 1315 1316 1311 break; 1312 } 1313 } 1317 1314 1318 1315 … … 1864 1861 1865 1862 foreach ($regs_found as $block_found) { 1863 if(!isset($block_found[0])) continue; 1864 1866 1865 $n_start = strpos($block_found[0], '>') + 1; 1867 1866 $n_length = strrpos($block_found[0], '<') - $n_start; … … 2141 2140 $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); 2142 2141 $msgs_in_the_server = array_keys($msgs_in_the_server); 2143 2144 2142 $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); 2145 2146 2143 $dif = ($params['msg_range_end'] - $params['msg_range_begin']) +1; 2147 2144 if(!count($msgs_in_the_server)){ … … 2192 2189 foreach($msgs_to_exec as $msg_number) 2193 2190 { 2194 /*A função imap_headerinfo não traz o cabeçalho completo, e sim alguns 2195 * atributos do cabeçalho. Como eu preciso do atributo Importance 2196 * para saber se o email é importante ou não, uso abaixo a função 2197 * imap_fetchheader e busco o atributo importance nela para passar 2198 * para as funções ajax. Isso faz com que eu acesse o cabeçalho 2199 * duas vezes e de duas formas diferentes, mas em contrapartida, eu 2200 * não preciso reimplementar o método utilizando o fetchheader. 2201 */ 2202 2203 $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); 2204 $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); 2205 $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 2206 2207 $msg_sample = $this->get_msg_sample($msg_number); 2208 $return[$i]['msg_sample'] = $msg_sample; 2209 2210 $header = $this->get_header($msg_number); 2211 if (!is_object($header)) 2212 continue; 2213 2214 $return[$i]['msg_number'] = $msg_number; 2191 $sample = false; 2192 if( (isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] === '1')) && (isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] === '1')) ) 2193 $sample = true; 2194 2195 $return[$i] = $this->get_info_head_msg($msg_number , $sample ); 2196 2197 //get the next msg number to append this msg in the view in a correct place 2198 $msg_key_position = array_search($msg_number, $msgs_in_the_server); 2215 2199 2216 //get the next msg number to append this msg in the view in a correct place 2217 $msg_key_position = array_search($msg_number, $msgs_in_the_server); 2218 2219 $return[$i]['msg_key_position'] = $msg_key_position; 2220 if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false) 2221 $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; 2222 else 2223 $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position]; 2224 2225 $return[$i]['msg_folder'] = $folder; 2226 // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type 2227 $return[$i]['ContentType'] = $this->getMessageType($msg_number, $tempHeader); 2228 $return[$i]['Recent'] = $header->Recent; 2229 $return[$i]['Unseen'] = $header->Unseen; 2230 $return[$i]['Answered'] = $header->Answered; 2231 $return[$i]['Deleted'] = $header->Deleted; 2232 $return[$i]['Draft'] = $header->Draft; 2233 $return[$i]['Flagged'] = $header->Flagged; 2234 2235 $return[$i]['udate'] = $header->udate; 2236 2237 $from = $header->from; 2238 $return[$i]['from'] = array(); 2239 $tmp = imap_mime_header_decode($from[0]->personal); 2240 $return[$i]['from']['name'] = $tmp[0]->text; 2241 $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; 2242 //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; 2243 if(!$return[$i]['from']['name'] || trim($return[$i]['from']['name']) === '') 2244 $return[$i]['from']['name'] = $return[$i]['from']['email']; 2245 2246 /*$toaddress = imap_mime_header_decode($header->toaddress); 2247 $return[$i]['toaddress'] = ''; 2248 foreach ($toaddress as $tmp) 2249 $return[$i]['toaddress'] .= $tmp->text;*/ 2250 $to = $header->to; 2251 $return[$i]['to'] = array(); 2252 if(isset($to[0]->personal)) 2253 $tmp = imap_mime_header_decode($to[0]->personal); 2254 if(trim($return[$i]['to']['name']) === '') 2255 $return[$i]['to']['name'] = $to[0]->mailbox . "@" . $to[0]->host; 2256 else 2257 $return[$i]['to']['name'] = $tmp[0]->text; 2258 $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; 2259 $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; 2260 if(isset($header->cc)) 2261 $cc = $header->cc; 2262 2263 if ( isset($cc) && (!$return[$i]['to']['name'] || $return[$i]['to']['name'] == '@') ){ 2264 $return[$i]['to']['name'] = $cc[0]->personal; 2265 $return[$i]['to']['email'] = $cc[0]->mailbox . "@" . $cc[0]->host; 2266 } 2267 $return[$i]['subject'] = ( isset( $header->fetchsubject ) ) ? $this->decode_string($header->fetchsubject) : ''; 2268 if($return[$i]['subject'] == "" || $return[$i]['subject'] == '' || $return[$i]['subject'] == null ){ 2269 $return[$i]['subject'] = $this->functions->getLang("(no subject) "); 2270 } 2271 $return[$i]['Size'] = $header->Size; 2272 $return[$i]['reply_toaddress'] = $header->reply_toaddress; 2273 2274 if($return[$i]['to']['email'] == '@' || $return[$i]['to']['email'] =='undisclosed-recipients@' || $return[$i]['to']['name'] =='undisclosed-recipients@' 2275 || $return[$i]['to']['name'] == null){ 2276 $return[$i]['to']['email'] = $return[$i]['from']['email']; 2277 $return[$i]['to']['name'] = $return[$i]['from']['name']; 2278 $return[$i]['to']['full'] = $return[$i]['reply_toaddress']; 2279 } 2280 2281 $return[$i]['attachment'] = array(); 2282 if (!isset($imap_attachment)) 2283 { 2284 include_once("class.imap_attachment.inc.php"); 2285 $imap_attachment = new imap_attachment(); 2286 } 2287 $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); 2288 $i++; 2200 $return[$i]['msg_key_position'] = $msg_key_position; 2201 if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false) 2202 $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; 2203 else 2204 $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position]; 2205 2206 $return[$i]['msg_folder'] = $folder; 2207 $i++; 2289 2208 } 2290 2209 $return['quota'] = $this->get_quota(array('folder_id' => $folder)); 2291 2210 $return['sort_box_type'] = $params['sort_box_type']; 2292 2211 if(!$this->mbox || !is_resource($this->mbox)) 2293 {2294 2212 $this->open_mbox($folder); 2295 } 2296 2213 2297 2214 $return['msgs_to_delete'] = $msg_to_delete; 2298 2215 $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); … … 2311 2228 * @return Retorna o tipo da mensagem (normal, signature, cipher). 2312 2229 */ 2313 function getMessageType($msg_number, $headers = false ){2230 function getMessageType($msg_number, $headers = false , &$body = false){ 2314 2231 include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); 2315 2232 $contentType = "normal"; 2316 if (!$headers){2317 $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number));2318 }2319 2320 if (preg_match("/pkcs7-signature/i", $headers) == 1) {2233 2234 if (!$headers) 2235 $headers = imap_fetchheader($this->mbox, $msg_number, FT_UID); 2236 2237 if (preg_match("/pkcs7-signature/i", $headers) == 1) 2321 2238 $contentType = "signature"; 2322 } else if (preg_match("/pkcs7-mime/i", $headers) == 1){ 2323 $contentType = testa_p7m( imap_body($this->mbox, imap_msgno($this->mbox, $msg_number)) ); 2324 } 2325 2239 else if (preg_match("/pkcs7-mime/i", $headers) == 1) 2240 $contentType = testa_p7m( $body ? $body : imap_body($this->mbox, $msg_number , FT_UID )) ; 2241 2326 2242 return $contentType; 2327 2243 } … … 3360 3276 if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} 3361 3277 $slice_array = true; 3362 3278 3363 3279 for ($i=$num_msgs; $i>0; $i--) 3364 3280 { … … 4431 4347 function search_msg( $params = false ) 4432 4348 { 4433 $mbox_stream = "";4349 4434 4350 4435 4351 if(strpos($params['condition'],"#")===false) … … 4495 4411 $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); 4496 4412 4497 if(!is_resource($mbox_stream)) 4498 $mbox_stream = $this->open_mbox($name_box); 4499 else 4500 imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 4501 4413 4414 $this->open_mbox($name_box); 4415 4502 4416 if (preg_match("/^.?\bALL\b/", $filter)) 4503 4417 { … … 4509 4423 $_filter = $criteria_fixed . substr($filter,4); 4510 4424 4511 $search_criteria = imap_search($ mbox_stream, $_filter, SE_UID);4425 $search_criteria = imap_search($this->mbox, $_filter, SE_UID); 4512 4426 4513 4427 if(is_array($search_criteria)) … … 4515 4429 foreach($search_criteria as $new_search) 4516 4430 { 4517 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 4431 $elem = $this->get_info_head_msg($new_search); 4432 4518 4433 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); 4519 4434 $elem['uid'] = $new_search; … … 4526 4441 } 4527 4442 else{ 4528 $search_criteria = imap_search($ mbox_stream, $filter, SE_UID);4443 $search_criteria = imap_search($this->mbox, $filter, SE_UID); 4529 4444 if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) 4530 4445 { 4531 4446 if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) 4532 4447 { 4533 $num_msgs = imap_num_msg($ mbox_stream);4448 $num_msgs = imap_num_msg($this->mbox); 4534 4449 $flagged_msgs = array(); 4535 4450 for ($i=$num_msgs; $i>0; $i--) … … 4561 4476 foreach($search_criteria as $new_search) 4562 4477 { 4563 $elem = $this->get_ msg_detail($new_search,$name_box,$mbox_stream);4564 4478 $elem = $this->get_info_head_msg( $new_search ); 4479 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); 4565 4480 $elem['uid'] = $new_search; 4566 4481 /* compare dates in ordering */ … … 4573 4488 } 4574 4489 4575 if($mbox_stream) 4576 { 4577 imap_close($mbox_stream); 4578 } 4579 4490 imap_close($this->mbox); 4580 4491 $num_msgs = count($retorno); 4581 4582 4492 /* Comparison functions, descendent is ascendent with parms inverted */ 4583 4493 function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); } … … 4603 4513 $arrayRetorno['currentTab'] = $params['current_tab']; 4604 4514 4605 if ($pageret) 4606 { 4607 return $arrayRetorno; 4608 } 4609 else 4610 { 4611 return 'none'; 4612 } 4613 } 4614 4615 function get_msg_detail($uid_msg,$name_box, $mbox_stream ) 4616 { 4617 $header = $this->get_header($uid_msg); 4618 require_once("class.imap_attachment.inc.php"); 4619 $imap_attachment = new imap_attachment(); 4620 $attachments = $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg); 4621 $attachments = $attachments['number_attachments'] > 0?"T".$attachments['number_attachments']:""; 4622 $flag = $header->Unseen 4623 .$header->Recent 4624 .$header->Flagged 4625 .$header->Draft 4626 .$header->Answered 4627 .$header->Deleted 4628 .$attachments; 4629 4630 4631 $subject = $this->decode_string($header->fetchsubject); 4632 $from = $header->from[0]->mailbox; 4633 if($header->from[0]->personal != "") 4634 $from = $header->from[0]->personal; 4635 $ret_msg['from'] = $this->decode_string($from); 4636 $ret_msg['subject'] = $subject; 4637 $ret_msg['udate'] = gmdate("d/m/Y",$header->udate + $this->functions->CalculateDateOffset()); 4638 $ret_msg['size'] = $header->Size; 4639 $ret_msg['flag'] = $flag; 4640 return $ret_msg; 4641 } 4642 4515 return ($pageret) ? $arrayRetorno : 'none'; 4516 } 4643 4517 4644 4518 function size_msg($size){ -
trunk/expressoMail1_2/js/draw_api.js
r5321 r5359 1296 1296 1297 1297 td_element2 = createTDElement(0,1,"td_msg"); 1298 if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)1299 td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(headers_msgs.attachment.names) + "'>";1298 if (headers_msgs.attachment == 1) 1299 td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' >"; 1300 1300 1301 1301 td_element21 = createTDElement(0,2,"td_msg",null,"td_message_answered_"+headers_msgs.msg_number); 1302 1303 if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {1304 attach_name = headers_msgs.attachment.names.split(", ");1305 for(var item in attach_name)1306 {1307 if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){1308 td_element21.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(attach_name[item]) + "'>";1309 break;1310 }1311 }1312 }1313 1302 1314 1303 if ((headers_msgs.Forwarded == 'F') || (headers_msgs.Draft == 'X' && headers_msgs.Answered == 'A')){ -
trunk/expressoMail1_2/setup/phpgw_pt-br.lang
r5350 r5359 740 740 Error marking messages. expressoMail1_2 pt-br Erro ao marcar as mensagens. 741 741 Error importing. expressoMail1_2 pt-br Erro ao Importar. 742 Using cache for list of messages admin pt-br Tempo maximo para listagem de mensagems ficar no cache 743 Maximum time for the list of messages keep in cache admin pt-br Tempo maximo para listagem de mensagems ficar no cache -
trunk/expressoMail1_2/templates/default/config.tpl
r5346 r5359 185 185 </tr> 186 186 187 <tr bgcolor="{th_bg}"> 188 <td colspan="2"> 189 190 </td> 191 </tr> 192 193 <tr bgcolor="{row_on}"> 194 <td colspan="2"> 195 <label style="font-weight:bold;">MemCache</label> 196 </td> 197 </tr> 198 199 <tr bgcolor="{row_off}"> 200 <td>{lang_Using_cache_for_list_of_messages}</td> 201 <td> 202 <select id="useCache" name="newsettings[expressoMail_enable_memcache]"> 203 <option value="false" {selected_expressoMail_enable_memcache_false}>{lang_No}</option> 204 <option value="true" {selected_expressoMail_enable_memcache_true}>{lang_Yes}</option> 205 </select> 206 </td> 207 </tr> 208 <tr bgcolor="{row_on}"> 209 <td>{lang_Maximum_time_for_the_list_of_messages_keep_in_cache} </td> 210 <td> 211 <input size="5" name="newsettings[expressoMail_time_memcache]" value="{value_expressoMail_time_memcache}"> 212 <span>s</span> 213 </td> 214 </tr> 215 187 216 <!-- END body --> 188 217 <!-- BEGIN footer --> -
trunk/setup/templates/default/config.tpl
r392 r5359 108 108 <td>{lang_Enter_your_HTTP_proxy_server_password}:</td> 109 109 <td><input name="newsettings[httpproxy_server_password]" value="{value_httpproxy_server_password}"></td> 110 </tr> 111 112 <tr class="row_off"> 113 <td>{lang_Enter_your_MemCache_server}:</td> 114 <td><input name="newsettings[server_memcache]" value="{value_server_memcache}"></td> 115 </tr> 116 117 <tr class="row_off"> 118 <td>{lang_Enter_your_MemCache_server_port}:</td> 119 <td><input name="newsettings[port_server_memcache]" value="{value_port_server_memcache}"></td> 110 120 </tr> 111 121
Note: See TracChangeset
for help on using the changeset viewer.