Changeset 1035 for trunk/expressoMail1_2/inc
- Timestamp:
- 06/20/09 01:07:18 (15 years ago)
- Location:
- trunk/expressoMail1_2/inc
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.db_functions.inc.php
r906 r1035 407 407 return $uiicalendar = $uiicalendar->import_from_mail($calendar); 408 408 } 409 409 410 function insert_certificate($email,$certificate,$serialnumber,$authoritykeyidentifier=null) 411 { 412 if(!$email || !$certificate || !$serialnumber || !$authoritykeyidentifier) 413 return false; 414 // Insere uma chave publica na tabela phpgw_certificados. 415 $data = array ('email' => $email, 416 'chave_publica' => $certificate, 417 'serialnumber' => $serialnumber, 418 'authoritykeyidentifier' => $authoritykeyidentifier); 419 420 if(!$this->db->insert('phpgw_certificados',$data,array(),__LINE__,__FILE__)){ 421 return $this->db->Error; 422 } 423 return true; 424 } 425 426 function get_certificate($email=null) 427 { 428 if(!$email) return false; 429 $result = array(); 430 431 $where = array ('email' => $email, 432 'revogado' => 0, 433 'expirado' => 0); 434 435 if(!$this->db->select('phpgw_certificados','chave_publica', $where, __LINE__,__FILE__)) 436 { 437 $result['dberr1'] = $this->db->Error; 438 return $result; 439 } 440 $regs = array(); 441 while($this->db->next_record()) 442 { 443 $regs[] = $this->db->row(); 444 } 445 if (count($regs) == 0) 446 { 447 $result['dberr2'] = ' Certificado nao localizado.'; 448 return $result; 449 } 450 $result['certs'] = $regs; 451 return $result; 452 } 453 454 function update_certificate($serialnumber=null,$email=null,$authoritykeyidentifier,$expirado,$revogado) 455 { 456 if(!$email || !$serialnumber) return false; 457 if(!$expirado) 458 $expirado = 0; 459 if(!$revogado) 460 $revogado = 0; 461 462 $data = array ('expirado' => $expirado, 463 'revogado' => $revogado); 464 465 $where = array ('email' => $email, 466 'serialnumber' => $serialnumber, 467 'authoritykeyidentifier' => $authoritykeyidentifier); 468 469 if(!$this->db->update('phpgw_certificados',$data,$where,__LINE__,__FILE__)) 470 { 471 return $this->db->Error; 472 } 473 return true; 474 } 475 410 476 } 411 477 ?> -
trunk/expressoMail1_2/inc/class.exporteml.inc.php
r1000 r1035 242 242 imap_close($this->mbox_stream); 243 243 return $tempDir.'/'.$file; 244 } 245 246 function export_msg_data($id_msg,$folder) { 247 $this->folder = $folder; 248 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); 249 250 $this->connectImap(); 251 $header = $this-> getHeader($id_msg); 252 $body = $this-> getBody($id_msg); 253 254 $msg_data = $header ."\r\n\r\n". $body; 255 256 imap_close($this->mbox_stream); 257 return $msg_data; 244 258 } 245 259 -
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r1012 r1035 404 404 $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 405 405 406 $return['body'] = $body; 407 $return['attachments'] = $return_get_body['attachments']; 408 $return['thumbs'] = $return_get_body['thumbs']; 409 $return['signature'] = $return_get_body['signature']; 410 406 if($return_get_body['body']=='isCripted'){ 407 $exporteml = new ExportEml(); 408 $return['source']=$exporteml->export_msg_data($msg_number,$msg_folder); 409 $return['body'] = ""; 410 $return['attachments'] = ""; 411 $return['thumbs'] = ""; 412 $return['signature'] = ""; 413 //return $return; 414 }else{ 415 $return['body'] = $body; 416 $return['attachments'] = $return_get_body['attachments']; 417 $return['thumbs'] = $return_get_body['thumbs']; 418 $return['signature'] = $return_get_body['signature']; 419 } 411 420 $pattern = '/^[ \t]*Disposition-Notification-To(^:)*:(.+)*@(.+)*$/isUm'; 412 421 if (preg_match($pattern, $header_, $fields)) … … 661 670 if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 662 671 { 672 if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 673 $return['body']='isCripted'; 674 return $return; 675 } 676 663 677 $attachment = array(); //No attachments 664 678 679 if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 680 $return['body']='isCripted'; 681 return $return; 682 } 683 665 684 $content = ''; 666 685 if (strtolower($msg->structure[$msg_number]->subtype) == "plain") … … 1007 1026 1008 1027 function get_signature($msg, $msg_number, $msg_folder) 1009 { 1028 { 1029 include_once("../seguranca/classes/CertificadoB.php"); 1030 include_once("class.db_functions.inc.php"); 1010 1031 foreach ($msg->file_type[$msg_number] as $index => $file_type) 1011 1032 { 1033 $sign = array(); 1034 $temp = $this->get_info_head_msg($msg_number); 1035 if($temp['ContentType'] =='normal') return $sign; 1012 1036 $file_type = strtolower($file_type); 1013 1037 if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') … … 1015 1039 if ($file_type == 'application/x-pkcs7-signature' || $file_type == 'application/pkcs7-signature') 1016 1040 { 1017 $export_mail = new ExportEml(); 1018 $params['folder'] = $msg_folder; 1019 $params['msgs_to_export'] = $msg_number; 1020 $tempDir = ini_get("session.save_path"); 1021 $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; 1022 $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); 1023 if (file_exists($cert_file)) 1041 if(!$this->mbox || !is_resource($this->mbox)) 1042 $this->mbox = $this->open_mbox($msg_folder); 1043 1044 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 1045 1046 $imap_msg = @imap_fetchheader($this->mbox, $msg_number, FT_UID); 1047 $imap_msg .= @imap_body($this->mbox, $msg_number, FT_UID); 1048 1049 $certificado = new certificadoB(); 1050 $validade = $certificado->verificar($imap_msg); 1051 1052 if ($certificado->apresentado) 1024 1053 { 1025 $handle = fopen ($cert_file,"r"); 1026 $pemout = fread($handle,filesize($cert_file)); 1027 fclose($handle); 1028 $cert=openssl_x509_parse($pemout); 1029 $temp = "\\nSigned by: ".$cert[subject][CN]; 1030 $temp .= "\\nEmail Address: ".$cert[subject][emailAddress]; 1031 $temp .= "\\nCertificate issued by: ".$cert[issuer][CN]."\\n"; 1054 $from = $header->from; 1055 foreach ($from as $id => $object) { 1056 $fromname = $object->personal; 1057 $fromaddress = $object->mailbox . "@" . $object->host; 1032 1058 } 1033 /* Message verified */ 1034 if ($result === true) 1035 $sign = $temp; 1059 $sign_alert = ''; 1060 foreach ($certificado->erros_ssl as $item) 1061 { 1062 $check_error_msg = $this->functions->getLang($item); 1063 /* 1064 * Desabilite o teste abaixo para mostrar todas as mensagem 1065 * de erro. 1066 */ 1067 //if (!strpos($check_error_msg,'*',strlen($check_error_msg-1))) 1068 //{ 1069 $sign[] = "<span style=color:red>" . $check_error_msg . " </span>"; 1070 //} 1071 } 1072 if (count($certificado->erros_ssl) < 1) 1073 { 1074 $check_msg = $this->functions->getLang('Message untouched') . " "; 1075 if($fromaddress == $certificado->dados['EMAIL']) 1076 { 1077 $check_msg .= $this->functions->getLang('and') . " "; 1078 $check_msg .= $this->functions->getLang('authentic'); 1079 } 1080 $sign[] = "<strong>".$check_msg."</strong>"; 1081 } 1082 if($fromaddress != $certificado->dados['EMAIL']) 1083 { 1084 $sign[] = "<span style=color:red>" . 1085 $this->functions->getLang('message') . " " . 1086 $this->functions->getLang('with signer different from sender') . 1087 " </span>"; 1088 } 1089 $sign[] = "<strong>" . $this->functions->getLang('Message signed by: ') . "</strong>" . $certificado->dados['NOME']; 1090 $sign[] = "<strong>" . $this->functions->getLang('Certificate email: ') . "</strong>" . $certificado->dados['EMAIL']; 1091 $sign[] = "<strong>" . $this->functions->getLang('Mail from: ') . "</strong>" . $fromaddress; 1092 $sign[] = "<strong>" . $this->functions->getLang('Certificate Authority: ') . "</strong>" . $certificado->dados['EMISSOR']; 1093 $sign[] = "<strong>" . $this->functions->getLang('Validity of certificate: ') . "</strong>" . gmdate('r',openssl_to_timestamp($certificado->dados['FIM_VALIDADE'])); 1094 $sign[] = "<strong>" . $this->functions->getLang('Message date: ') . "</strong>" . $header->Date; 1095 1096 $cert = openssl_x509_parse($certificado->cert_assinante); 1097 /* 1098 $sign[] = '<table>'; 1099 $sign[] = '<tr><td colspan=1><b>Expedido para:</b></td></tr>'; 1100 $sign[] = '<tr><td>Nome Comum (CN) </td><td>' . $cert[subject]['CN'] . '</td></tr>'; 1101 $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); 1102 $sign[] = '<tr><td>Data de nascimento </td><td>' . $certificado->dados['NASCIMENTO'] . '</td></tr>'; 1103 $sign[] = '<tr><td>CPF </td><td>' . $certificado->dados['CPF'] . '</td></tr>'; 1104 $sign[] = '<tr><td>Documento identidade </td><td>' . $certificado->dados['RG'] . '</td></tr>'; 1105 $sign[] = '<tr><td>Empresa (O) </td><td>' . $cert[subject]['O'] . '</td></tr>'; 1106 $sign[] = '<tr><td>Unidade Organizacional (OU) </td><td>' . $cert[subject]['OU'][0] . '</td></tr>'; 1107 //$sign[] = '<tr><td>Numero de serie </td><td>' . $cert['serialNumber'] . '</td></tr>'; 1108 $sign[] = '<tr><td colspan=1> </td></tr>'; 1109 $sign[] = '<tr><td colspan=1><b>Expedido por:</b></td></tr>'; 1110 $sign[] = '<tr><td>Nome Comum (CN) </td><td>' . $cert[issuer]['CN'] . '</td></tr>'; 1111 $sign[] = '<tr><td>Empresa (O) </td><td>' . $cert[issuer]['O'] . '</td></tr>'; 1112 $sign[] = '<tr><td>Unidade Organizacional (OU) </td><td>' . $cert[issuer]['OU'][0] . '</td></tr>'; 1113 $sign[] = '<tr><td colspan=1> </td></tr>'; 1114 $sign[] = '<tr><td colspan=1><b>Validade:</b></td></tr>'; 1115 $H = data_hora($cert[validFrom]); 1116 $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); 1117 $sign[] = '<tr><td>Expedido em </td><td>' . $X . '</td></tr>'; 1118 $H = data_hora($cert[validTo]); 1119 $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); 1120 $sign[] = '<tr><td>Valido ate </td><td>' . $X . '</td></tr>'; 1121 $sign[] = '<tr><td colspan=1> </td></tr>'; 1122 $sign[] = '</table>'; 1123 */ 1124 $sign_alert .= 'Expedido para:\n'; 1125 $sign_alert .= 'Nome Comum (CN) ' . $cert[subject]['CN'] . '\n'; 1126 $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); 1127 $sign_alert .= 'Data de nascimento ' . $X . '\n'; 1128 $sign_alert .= 'CPF ' . $certificado->dados['CPF'] . '\n'; 1129 $sign_alert .= 'Documento identidade ' . $certificado->dados['RG'] . '\n'; 1130 $sign_alert .= 'Empresa (O) ' . $cert[subject]['O'] . '\n'; 1131 $sign_alert .= 'Unidade Organizacional (OU) ' . $cert[subject]['OU'][0] . '\n'; 1132 //$sign_alert[] = '<tr><td>Numero de serie </td><td>' . $cert['serialNumber'] . '</td></tr>'; 1133 $sign_alert .= '\n'; 1134 $sign_alert .= 'Expedido por:\n'; 1135 $sign_alert .= 'Nome Comum (CN) ' . $cert[issuer]['CN'] . '\n'; 1136 $sign_alert .= 'Empresa (O) ' . $cert[issuer]['O'] . '\n'; 1137 $sign_alert .= 'Unidade Organizacional (OU) ' . $cert[issuer]['OU'][0] . '\n'; 1138 $sign_alert .= '\n'; 1139 $sign_alert .= 'Validade:\n'; 1140 $H = data_hora($cert[validFrom]); 1141 $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); 1142 $sign_alert .= 'Expedido em ' . $X . '\n'; 1143 $H = data_hora($cert[validTo]); 1144 $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); 1145 $sign_alert .= 'Valido ate ' . $X . '\n'; 1146 1147 $sign[] = "<a onclick=\"javascript:alert('" . $sign_alert . "')\"><b><font color=\"#0000FF\">".$this->functions->getLang("More")."...</font></b></a>"; 1148 $this->db = new db_functions(); 1149 1150 // TODO: testar se existe um certificado no banco e verificar qual ï¿œ o mais atual. 1151 if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) 1152 $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); 1153 } 1036 1154 else 1037 $sign = "void"; 1155 { 1156 $sign[] = "<span style=color:red>" . $this->functions->getLang('Invalid signature') . "</span>"; 1157 foreach($certificado->erros_ssl as $item) 1158 $sign[] = "<span style=color:red>" . $this->functions->getLang($item) . "</span>"; 1159 } 1038 1160 } 1039 1161 } … … 1173 1295 * a perda em performance é insignificante. 1174 1296 */ 1175 $flag = preg_match('/importance *: *(.*)\r/i', 1176 @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) 1177 ,$importance); 1297 $tempHeader = @imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); 1298 $flag = preg_match('/importance *: *(.*)\r/i', $tempHeader, $importance); 1178 1299 $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 1179 1300 … … 1186 1307 1187 1308 $return[$i]['msg_folder'] = $folder; 1309 // Atribui o tipo (normal, signature ou cipher) ao campo Content-Type 1310 $return[$i]['ContentType'] = $this->getMessageType($msg_number, $tempHeader); 1188 1311 $return[$i]['Recent'] = $header->Recent; 1189 1312 $return[$i]['Unseen'] = $header->Unseen; … … 1236 1359 } 1237 1360 1361 /** 1362 * Método que faz a verificação do Content-Type do e-mail e verifica se é um e-mail normal, 1363 * assinado ou cifrado. 1364 * @author Mário César Kolling <mario.kolling@serpro.gov.br> 1365 * @param $headers Uma String contendo os Headers do e-mail retornados pela função imap_imap_fetchheader 1366 * @param $msg_number O número da mesagem 1367 * @return Retorna o tipo da mensagem (normal, signature, cipher). 1368 */ 1369 function getMessageType($msg_number, $headers = false){ 1370 1371 $contentType = "normal"; 1372 if (!$headers){ 1373 $headers = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); 1374 } 1375 //$header2 = imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)); 1376 if (preg_match("/Content-Type:.*pkcs7-signature/i", $headers) == 1){ 1377 $contentType = "signature"; 1378 } else if (preg_match("/Content-Type:.*x-pkcs7-mime/i", $headers) == 1){ 1379 $contentType = "cipher"; 1380 } 1381 1382 return $contentType; 1383 } 1384 1238 1385 function get_folders_list($params = null) 1239 1386 { … … 1248 1395 if (is_array($folders_list)) { 1249 1396 reset($folders_list); 1397 $this->ldap = new ldap_functions(); 1250 1398 1251 1399 $i = 0; 1252 1400 while (list($key, $val) = each($folders_list)) { 1253 1401 $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 1254 $result[$i]['folder_unseen'] = $status->unseen; 1255 1402 1256 1403 //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 1257 1404 $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); 1405 if($tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas'){ 1406 //error_log('passou', 3,'/tmp/imap_get_list.log'); 1407 //imap_deletemailbox($mbox_stream,imap_utf7_encode("{".$this->imap_server."}".'INBOX/decifradas')); 1408 continue; 1409 } 1410 $result[$i]['folder_unseen'] = $status->unseen; 1258 1411 $folder_id = $tmp_folder_id[1]; 1259 1412 $result[$i]['folder_id'] = $folder_id; … … 1263 1416 $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 1264 1417 if (is_numeric($result[$i]['folder_name'])) { 1265 $this->ldap = new ldap_functions();1418 //$this->ldap = new ldap_functions(); 1266 1419 if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){ 1267 1420 $result[$i]['folder_name'] = $cn; … … 1428 1581 $return_receipt = $params['input_return_receipt']; 1429 1582 $is_important = $params['input_important_message']; 1430 $body = $params['body']; 1583 $encrypt = $params['input_return_cripto']; 1584 $signed = $params['input_return_digital']; 1585 1586 if($params['smime']) 1587 { 1588 $body = $params['smime']; 1589 $mail->SMIME = true; 1590 // A MSG assinada deve ser testada neste ponto. 1591 // Testar o certificado e a integridade da msg.... 1592 include_once("../seguranca/classes/CertificadoB.php"); 1593 $erros_acumulados = ''; 1594 $certificado = new certificadoB(); 1595 $validade = $certificado->verificar($body); 1596 if(!$validade) 1597 { 1598 foreach($certificado->erros_ssl as $linha_erro) 1599 { 1600 $erros_acumulados .= $linha_erro; 1601 } 1602 } 1603 else 1604 { 1605 // Testa o CERTIFICADO: se o CPF he o do usuario logado, se pode assinar msgs e se nao esta expirado... 1606 if ($certificado->apresentado) 1607 { 1608 if($certificado->dados['EXPIRADO']) $erros_acumulados .='Certificado expirado.'; 1609 if($certificado->dados['CPF'] != $this->username) $erros_acumulados .=' CPF no certificado diferente do logado no expresso.'; 1610 if(!($certificado->dados['KEYUSAGE']['digitalSignature'] && $certificado->dados['EXTKEYUSAGE']['emailProtection'])) $erros_acumulados .=' Certificado nao permite assinar mensagens.'; 1611 } 1612 else 1613 { 1614 $$erros_acumulados .= 'Nao foi possivel usar o certificado para assinar a msg'; 1615 } 1616 } 1617 if(!$erros_acumulados =='') 1618 { 1619 return $erros_acumulados; 1620 } 1621 } 1622 else 1623 { 1624 $body = $params['body']; 1625 } 1431 1626 //echo "<script language=\"javascript\">javascript:alert('".$body."');</script>"; 1432 1627 $attachments = $params['FILES']; … … 1447 1642 //////////////////////////////////////////////////////////////////////////////////////////////////// 1448 1643 $mail->SMTPDebug = false; 1449 1450 $mail->IsSMTP(); 1644 1645 if($signed && !$params['smime']) 1646 { 1647 $mail->Mailer = "smime"; 1648 $mail->SignedBody = true; 1649 } 1650 else 1651 $mail->IsSMTP(); 1652 1451 1653 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 1452 1654 $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; … … 1465 1667 $mail->Subject = $subject; 1466 1668 $mail->IsHTML(true); 1467 $mail->Body = $params['body']; 1669 $mail->Body = $body; 1670 1671 if (($encrypt && $signed && $params['smime']) || ($encrypt && !$signed)) // a msg deve ser enviada cifrada... 1672 { 1673 $email = $this->add_recipients_cert($toaddress . ',' . $ccaddress. ',' .$ccoaddress); 1674 $email = explode(",",$email); 1675 // Deve ser testado se foram obtidos os certificados de todos os destinatarios. 1676 // Deve ser verificado um numero limite de destinatarios. 1677 // Deve ser verificado se os certificados sao validos. 1678 // Se uma das verificacoes falhar, nao enviar o e-mail e avisar o usuario. 1679 // O array $mail->Certs_crypt soh deve ser preenchido se os certificados passarem nas verificacoes. 1680 $numero_maximo = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher']; // Este valor dever ser configurado pelo administrador do site .... 1681 $erros_acumulados = ""; 1682 $aux_mails = array(); 1683 $mail_list = array(); 1684 if(count($email) > $numero_maximo) 1685 { 1686 $erros_acumulados .= "Excedido o numero maximo (" . $numero_maximo . ") de destinatarios para uma msg cifrada...." . chr(0x0A); 1687 return $erros_acumulados; 1688 } 1689 // adiciona o email do remetente. eh para cifrar a msg para ele tambem. Assim vai poder visualizar a msg na pasta enviados.. 1690 $email[] = $_SESSION['phpgw_info']['expressomail']['user']['email']; 1691 foreach($email as $item) 1692 { 1693 $certificate = $db->get_certificate(strtolower($item)); 1694 if(!$certificate) 1695 { 1696 $erros_acumulados .= "Chamada com parametro invalido. e-Mail nao pode ser vazio." . chr(0x0A); 1697 return $erros_acumulados; 1698 } 1699 1700 if (array_key_exists("dberr1", $certificate)) 1701 { 1702 1703 $erros_acumulados .= "Ocorreu um erro quando pesquisava certificados dos destinatarios para cifrar a msg." . chr(0x0A); 1704 return $erros_acumulados; 1705 } 1706 if (array_key_exists("dberr2", $certificate)) 1707 { 1708 $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); 1709 //continue; 1710 } 1711 /* Retirado este teste para evitar mensagem de erro duplicada. 1712 if (!array_key_exists("certs", $certificate)) 1713 { 1714 $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); 1715 continue; 1716 } 1717 */ 1718 include_once("../seguranca/classes/CertificadoB.php"); 1719 1720 foreach ($certificate['certs'] as $registro) 1721 { 1722 $c1 = new certificadoB(); 1723 $c1->certificado($registro['chave_publica']); 1724 if ($c1->apresentado) 1725 { 1726 $c2 = new Verifica_Certificado($c1->dados,$registro['chave_publica']); 1727 if (!$c1->dados['EXPIRADO'] && !$c2->revogado && $c2->status) 1728 { 1729 $aux_mails[] = $registro['chave_publica']; 1730 $mail_list[] = strtolower($item); 1731 } 1732 else 1733 { 1734 if ($c1->dados['EXPIRADO'] || $c2->revogado) 1735 { 1736 $db->update_certificate($c1->dados['SERIALNUMBER'],$c1->dados['EMAIL'],$c1->dados['AUTHORITYKEYIDENTIFIER'], 1737 $c1->dados['EXPIRADO'],$c2->revogado); 1738 } 1739 1740 $erros_acumulados .= $item . ': ' . $c2->msgerro . chr(0x0A); 1741 foreach($c2->erros_ssl as $linha) 1742 { 1743 $erros_acumulados .= $linha . chr(0x0A); 1744 } 1745 $erros_acumulados .= 'Emissor: ' . $c1->dados['EMISSOR'] . chr(0x0A); 1746 $erros_acumulados .= $c1->dados['CRLDISTRIBUTIONPOINTS'] . chr(0x0A); 1747 } 1748 } 1749 else 1750 { 1751 $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado invalido.' . chr(0x0A); 1752 } 1753 } 1754 if(!(in_array(strtolower($item),$mail_list)) && !empty($erros_acumulados)) 1755 { 1756 return $erros_acumulados; 1757 } 1758 } 1759 1760 $mail->Certs_crypt = $aux_mails; 1761 } 1468 1762 1469 1763 //////////////////////////////////////////////////////////////////////////////////////////////////// … … 1589 1883 else 1590 1884 { 1885 if ($signed && !$params['smime']) 1886 { 1887 return $sent; 1888 } 1591 1889 if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") 1592 1890 { … … 1606 1904 return array("success" => true); 1607 1905 } 1906 } 1907 1908 function add_recipients_cert($full_address) 1909 { 1910 $result = ""; 1911 $parse_address = imap_rfc822_parse_adrlist($full_address, ""); 1912 foreach ($parse_address as $val) 1913 { 1914 //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; 1915 if ($val->mailbox == "INVALID_ADDRESS") 1916 continue; 1917 if ($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS") 1918 continue; 1919 if (empty($val->personal)) 1920 $result .= $val->mailbox."@".$val->host . ","; 1921 else 1922 $result .= $val->mailbox."@".$val->host . ","; 1923 } 1924 1925 return substr($result,0,-1); 1608 1926 } 1609 1927 … … 2367 2685 $folder_id = "INBOX"; 2368 2686 2369 if(!$this->mbox )2687 if(!$this->mbox || !is_resource($this->mbox)) 2370 2688 $this->mbox = $this->open_mbox(); 2371 2689 … … 2958 3276 } 2959 3277 3278 function show_decript($params){ 3279 $source = $params['source']; 3280 //error_log("source: $source\nversao: " . PHP_VERSION, 3, '/tmp/teste.log'); 3281 $source = str_replace(" ", "+", $source,$i); 3282 3283 if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 3284 if(!$source = base64_decode($source,true)) 3285 return "error ".$source."Espaços ".$i; 3286 3287 } 3288 else { 3289 if(!$source = base64_decode($source)) 3290 return "error ".$source."Espaços ".$i; 3291 } 3292 3293 $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); 3294 3295 $get['msg_number'] = $insert['msg_no']; 3296 $get['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; 3297 $return = $this->get_info_msg($get); 3298 $get['msg_number'] = $params['ID']; 3299 $get['msg_folder'] = $params['folder']; 3300 $tmp = $this->get_info_msg($get); 3301 if(!$tmp['status_get_msg_info']) 3302 { 3303 $return['msg_day']=$tmp['msg_day']; 3304 $return['msg_hour']=$tmp['msg_hour']; 3305 $return['fulldate']=$tmp['fulldate']; 3306 $return['smalldate']=$tmp['smalldate']; 3307 } 3308 else 3309 { 3310 $return['msg_day']=''; 3311 $return['msg_hour']=''; 3312 $return['fulldate']=''; 3313 $return['smalldate']=''; 3314 } 3315 $return['msg_no'] =$insert['msg_no']; 3316 $return['error'] = $insert['error']; 3317 $return['folder'] = $params['folder']; 3318 //$return['acls'] = $insert['acls']; 3319 $return['original_ID'] = $params['ID']; 3320 3321 return $return; 3322 3323 } 3324 2960 3325 //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Trata fontes de emails enviados via POST para o servidor por um xmlhttprequest, as partes codificados com 2961 3326 //Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. -
trunk/expressoMail1_2/inc/class.phpmailer.php
r614 r1035 101 101 102 102 /** 103 * Sets the signed body of the message. This automatically sets the 104 * email to multipart/signed. 105 * @var string 106 */ 107 var $SignedBody = false; 108 var $SMIME = false; 109 var $Certs_crypt = array(); 110 /** 111 * Sets the encrypted body of the message. This automatically sets the 112 * email to multipart/encript. 113 * @var string 114 */ 115 var $CryptedBody = ""; 116 117 /** 103 118 * Sets word wrapping on the body of the message to a given number of 104 119 * characters. … … 148 163 var $SaveMessageInFolder = ""; 149 164 var $SaveMessageAsDraft = ""; 165 166 var $xMailer = ""; 150 167 151 168 ///////////////////////////////////////////////// … … 372 389 $this->SetMessageType(); 373 390 $header .= $this->CreateHeader(); 374 $body = $this->CreateBody(); 375 376 if($body == "") { return false; } 391 392 if ($this->SMIME == false) 393 { 394 $body = $this->CreateBody(); 395 if($body == "") 396 { 397 return false; 398 } 399 } 377 400 378 401 // Choose the mailer 379 402 switch($this->Mailer) 380 403 { 404 // Usado para processar o email e retornar para a applet 405 case "smime": 406 $retorno['body'] = $header.$this->LE.$body; 407 $retorno['type'] = $this->write_message_type(); 408 return $retorno; 381 409 case "sendmail": 382 410 $result = $this->SendmailSend($header, $body); … … 473 501 include_once($this->PluginDir . "class.smtp.php"); 474 502 $error = ""; 503 475 504 $bad_rcpt = array(); 476 505 $errorx = ''; 477 506 if(!$this->SmtpConnect()) 478 507 return false; 508 509 if($this->SMIME) 510 { 511 $header=''; 512 $body = $this->Body; 513 } 479 514 480 515 $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; … … 490 525 for($i = 0; $i < count($this->to); $i++) 491 526 { 492 if(!$this->smtp->Recipient($this->to[$i][0])) 493 $bad_rcpt[] = $this->to[$i][0]; 527 if($this->valEm($this->to[$i][0])) 528 { 529 if(!$this->smtp->Recipient($this->to[$i][0])) $bad_rcpt[] = $this->to[$i][0]; 530 } 531 else 532 { 533 $errorx .= $this->to[$i][0] . ', '; 534 } 494 535 } 495 536 for($i = 0; $i < count($this->cc); $i++) 496 537 { 497 if(!$this->smtp->Recipient($this->cc[$i][0])) 498 $bad_rcpt[] = $this->cc[$i][0]; 538 if($this->valEm($this->cc[$i][0])) 539 { 540 if(!$this->smtp->Recipient($this->cc[$i][0])) $bad_rcpt[] = $this->cc[$i][0]; 541 } 542 else 543 { 544 $errorx .= $this->cc[$i][0] . ', '; 545 } 499 546 } 500 547 for($i = 0; $i < count($this->bcc); $i++) 501 548 { 502 if(!$this->smtp->Recipient($this->bcc[$i][0])) 503 $bad_rcpt[] = $this->bcc[$i][0]; 504 } 549 if($this->valEm($this->bcc[$i][0])) 550 { 551 if(!$this->smtp->Recipient($this->bcc[$i][0])) $bad_rcpt[] = $this->bcc[$i][0]; 552 } 553 else 554 { 555 $errorx .= $this->bcc[$i][0] . ', '; 556 } 557 } 558 if($errorx != '') 559 { 560 $error = $errorx; 561 $error = $this->Lang("recipients_failed") . ' ' . $errorx; 562 $this->SetError($error); 563 $this->smtp->Reset(); 564 return false; 565 } 505 566 506 567 if(count($bad_rcpt) > 0) // Create error message … … 524 585 return false; 525 586 } 587 588 // Vai verificar se deve cifrar a msg ...... 589 if(count($this->Certs_crypt) > 0) 590 { 591 // Vai cifrar a msg antes de enviar ...... 592 include_once("../seguranca/classes/CertificadoB.php"); 593 594 $teste1 = array(); 595 $aux_cifra1 = $header . $body; 596 597 // Início relocação dos headers 598 // Esta relocação dos headers podem causar problemas. 599 600 $match = 0; 601 $pattern = '/^Disposition\-Notification\-To:.*\n/m'; 602 $match = preg_match($pattern, $aux_cifra1, $teste1); 603 604 if (!empty($match)){ 605 $aux_cifra1 = preg_replace($pattern, '', $aux_cifra1, 1); // retira o Disposition-Notification-To 606 607 $match = 0; 608 $teste2 = array(); 609 $pattern = '/^MIME\-Version:.*\n/m'; 610 $match = preg_match($pattern, $aux_cifra1, $teste2); 611 $aux_cifra1 = preg_replace($pattern, $teste1[0].$teste2[0], $aux_cifra1, 1); // Adiciona Disposition-Notification-To logo acima de MIME-Version 612 613 } 614 // Fim relocação dos headers 615 616 // Vai partir em duas partes a msg. A primeira parte he a dos headers, e a segunda vai ser criptografada ... 617 $pos_content_type = strpos($aux_cifra1,'Content-Type:'); 618 $pos_MIME_Version = strpos($aux_cifra1,'MIME-Version: 1.0' . chr(0x0D) . chr(0x0A)); 619 $valx_len = 19; 620 if($pos_MIME_Version === False) 621 { 622 $pos_MIME_Version = strpos($aux_cifra1,'MIME-Version: 1.0' . chr(0x0A)); 623 $valx_len = 18; 624 } 625 626 if($pos_MIME_Version >= $pos_content_type) 627 { 628 // nao deve enviar a msg..... O header MIME-Version com posicao invalida ...... 629 $this->SetError('Formato dos headers da msg estao invalidos.(CD-17) - A'); 630 $this->smtp->Reset(); 631 return false; 632 } 633 634 $aux_cifra2 = array(); 635 $aux_cifra2[] = substr($aux_cifra1,0,$pos_MIME_Version - 1); 636 $aux_cifra2[] = substr($aux_cifra1,$pos_MIME_Version + $valx_len); 637 638 /* 639 // este explode pode ser fonte de problemas ....... 640 $aux_cifra2 = explode('MIME-Version: 1.0' . chr(0x0A), $aux_cifra1); 641 // Pode ocorrer um erro se nao tiver o header MIME-Version ..... 642 if(count($aux_cifra2) != 2 ) 643 { 644 $aux_cifra2 = explode('MIME-Version: 1.0' . chr(0x0D) . chr(0x0A), $aux_cifra1); 645 if(count($aux_cifra2) != 2 ) 646 { 647 // nao deve enviar a msg..... nao tem o header MIME-Version ...... 648 $this->SetError('Formato dos headers da msg estao invalidos.(CD-17) - ' . count($aux_cifra2)); 649 $this->smtp->Reset(); 650 return false; 651 } 652 } 653 */ 654 $certificado = new certificadoB(); 655 $h = array(); 656 $aux_body = $certificado->encriptar($aux_cifra2[1], $this->Certs_crypt, $h); 657 if(!$aux_body) 658 { 659 $this->SetError('Ocorreu um erro. A msg nao foi enviada. (CD-18)'); 660 $this->smtp->Reset(); 661 return false; 662 } 663 // salvar sem cifra...... 664 //$smtpSent = $this->smtp->Data($aux_cifra2[0] . $aux_body); 665 666 // salva a msg sifrada. neste caso deve ter sido adicionado o certificado do autor da msg...... 667 $header = $aux_cifra2[0]; 668 $body = $aux_body; 526 669 $smtpSent = $this->smtp->Data($header . $body); 670 } 671 else 672 { 673 $smtpSent = $this->smtp->Data($header . $body); 674 } 675 527 676 if(!$smtpSent) 528 677 { … … 563 712 $header = substr($header, 0, $target) . $this->AddrAppend("Bcc", $this->bcc) . substr($header, $target); 564 713 } 565 566 $new_header = str_replace("\n", "\r\n", $header); 567 $new_body = str_replace("\n", "\r\n", $body); 714 $new_headerx = str_replace(chr(0x0A),chr(0x0D).chr(0x0A), $header); 715 $new_bodyx = str_replace(chr(0x0A),chr(0x0D).chr(0x0A), $body); 716 $new_header = str_replace(chr(0x0D).chr(0x0D).chr(0x0A), chr(0x0D).chr(0x0A),$new_headerx); 717 $new_body = str_replace(chr(0x0D).chr(0x0D).chr(0x0A), chr(0x0D).chr(0x0A), $new_bodyx); 568 718 569 719 if ($this->SaveMessageAsDraft){ … … 576 726 577 727 return $smtpSent; 728 } 729 730 function valEm($email) 731 { 732 $mail_retorno = FALSE; 733 if ((strlen($email) >= 6) && (substr_count($email,"@") == 1) && (substr($email,0,1) != "@") && (substr($email,strlen($email)-1,1) != "@")) 734 { 735 if ((!strstr($email,"'")) && (!strstr($email,"\"")) && (!strstr($email,"\\")) && (!strstr($email,"\$")) && (!strstr($email," "))) 736 { 737 //testa se tem caracter . 738 if (substr_count($email,".")>= 1) 739 { 740 //obtem a terminação do dominio 741 $term_dom = substr(strrchr ($email, '.'),1); 742 //verifica se terminação do dominio esta correcta 743 if (strlen($term_dom)>1 && strlen($term_dom)<5 && (!strstr($term_dom,"@")) ) 744 { 745 $antes_dom = substr($email,0,strlen($email) - strlen($term_dom) - 1); 746 $caracter_ult = substr($antes_dom,strlen($antes_dom)-1,1); 747 if ($caracter_ult != "@" && $caracter_ult != ".") 748 { 749 $mail_retorno = TRUE; 750 } 751 } 752 } 753 } 754 } 755 return $mail_retorno; 578 756 } 579 757 … … 885 1063 $result .= $this->HeaderLine("MIME-Version", "1.0"); 886 1064 1065 $result .= $this->write_message_type(); 1066 1067 if($this->Mailer != "mail") 1068 $result .= $this->LE.$this->LE; 1069 1070 return $result; 1071 } 1072 1073 1074 function write_message_type() 1075 { 1076 $result = ""; 887 1077 switch($this->message_type) 888 1078 { … … 891 1081 $result .= sprintf("Content-Type: %s; charset=\"%s\"", 892 1082 $this->ContentType, $this->CharSet); 893 break;1083 return $result; 894 1084 case "attachments": 895 1085 // fall through … … 906 1096 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 907 1097 } 908 break;1098 return $result; 909 1099 case "alt": 910 1100 $result .= $this->HeaderLine("Content-Type", "multipart/alternative;"); 911 1101 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 912 break;1102 return $result; 913 1103 } 914 1104 -
trunk/expressoMail1_2/inc/hook_settings.inc.php
r1005 r1035 13 13 $type = $_GET['type']; // FIX ME 14 14 15 //if ($type == 'user' || $type == ''){ 16 create_html_code('<script language="JavaScript" type="text/javascript"> 17 function exibir_ocultar() 18 { 19 var type = ("'.$type.'" == "") ? "user" : "'.$type.'"; 20 var use_signature_digital_cripto = document.getElementsByName(type+"[use_signature_digital_cripto]")[0]; 21 var default_signature_digital_cripto = "'.$GLOBALS['phpgw_info']['default']['preferences']['expressoMail']['use_signature_digital_cripto'].'"; 22 23 if (use_signature_digital_cripto) 24 { 25 var element_signature_digital = document.getElementById(type+"[use_signature_digital]"); 26 var element_signature_cripto = document.getElementById(type+"[use_signature_cripto]"); 27 28 switch (use_signature_digital_cripto[use_signature_digital_cripto.selectedIndex].value){ 29 30 case "1": 31 element_signature_digital.style.display=""; 32 element_signature_cripto.style.display=""; 33 break; 34 case "0": 35 element_signature_digital.style.display="none"; 36 element_signature_cripto.style.display="none"; 37 break; 38 case "": 39 if (default_signature_digital_cripto){ 40 element_signature_digital.style.display=""; 41 element_signature_cripto.style.display=""; 42 } 43 else 44 { 45 element_signature_digital.style.display="none"; 46 element_signature_cripto.style.display="none"; 47 } 48 49 } 50 51 } 52 53 } 54 55 </script>'); 56 //} 57 15 58 $default = array( 16 59 '25' => '25', … … 20 63 ); 21 64 22 create_select_box( lang('What is the maximum number of messages per page?'),'max_email_per_page',$default,65 create_select_box('What is the maximum number of messages per page?','max_email_per_page',$default, 23 66 'What is the maximum number of messages per page?'); 24 create_check_box( lang('Save deleted messages in trash folder?'),'save_deleted_msg','Save deleted messages in trash folder?');67 create_check_box('Save deleted messages in trash folder?','save_deleted_msg','Save deleted messages in trash folder?'); 25 68 $default = array( 26 69 '1' => lang('1 day'), … … 31 74 ); 32 75 33 create_select_box( lang('Delete trash messages after how many days?'),'delete_trash_messages_after_n_days',$default,lang('Delete trash messages after how many days?'));34 create_check_box( lang('Would you like to use local messages?'),'use_local_messages','');35 create_check_box( lang('Would you like to keep archived messages?'),'keep_archived_messages','');36 create_check_box( lang('Show previous message, after delete actual message?'),'delete_and_show_previous_message','');37 create_check_box( lang('Do you wanna receive an alert for new messages?'),'alert_new_msg','');38 create_check_box( lang('Show default view on main screen?'),'mainscreen_showmail','');39 create_check_box( lang('Do you want to use remove attachments function?'),'remove_attachments_function','');40 create_check_box( lang('Do you want to use important flag in email editor?'),'enable_important_flag','');76 create_select_box('Delete trash messages after how many days?','delete_trash_messages_after_n_days',$default,lang('Delete trash messages after how many days?')); 77 create_check_box('Would you like to use local messages?','use_local_messages',''); 78 create_check_box('Would you like to keep archived messages?','keep_archived_messages',''); 79 create_check_box('Show previous message, after delete actual message?','delete_and_show_previous_message',''); 80 create_check_box('Do you wanna receive an alert for new messages?','alert_new_msg',''); 81 create_check_box('Show default view on main screen?','mainscreen_showmail',''); 82 create_check_box('Do you want to use remove attachments function?','remove_attachments_function',''); 83 create_check_box('Do you want to use important flag in email editor?','enable_important_flag',''); 41 84 42 85 //TODO use default folders from email admin … … 47 90 'INBOX/'.lang('Trash') => lang('Trash') 48 91 ); 49 create_select_box( lang('Save sent messages in folder'),'save_in_folder',$default,'');50 create_check_box( lang('Hide menu folders?'),'check_menu','');92 create_select_box('Save sent messages in folder','save_in_folder',$default,''); 93 create_check_box('Hide menu folders?','check_menu',''); 51 94 52 95 $default = array( … … 56 99 ); 57 100 58 create_select_box( lang('What is the height of the lines in the list of messages?'),'line_height',$default,'');101 create_select_box('What is the height of the lines in the list of messages?','line_height',$default,''); 59 102 $default = array( 60 103 '10' => lang('small'), … … 63 106 ); 64 107 65 create_select_box( lang('What the font size in the list of messages?'),'font_size',$default,'');66 create_check_box( lang('Use dynamic contacts?'),'use_dynamic_contacts','');67 create_check_box( lang('Use shortcuts?'),'use_shotcuts','');68 create_check_box( lang('Auto save draft'),'auto_save_draft','');108 create_select_box('What the font size in the list of messages?','font_size',$default,''); 109 create_check_box('Use dynamic contacts?','use_dynamic_contacts',''); 110 create_check_box('Use shortcuts?','use_shotcuts',''); 111 create_check_box('Auto save draft','auto_save_draft',''); 69 112 $default = array( 70 113 '65536' => lang('unlimited'), … … 76 119 ); 77 120 78 create_select_box(lang('What is the maximum size of embedded images')."?",'image_size',$default,''); 121 create_select_box('What is the maximum size of embedded images'."?",'image_size',$default,''); 122 123 if($GLOBALS['phpgw_info']['server']['use_assinar_criptografar']) 124 { 125 create_check_box('Enable digitally sign/cipher the message?','use_signature_digital_cripto','','',True,'onchange="javascript:exibir_ocultar();"'); 126 if ($GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto']) 127 { 128 create_check_box('Always sign message digitally?','use_signature_digital',''); 129 create_check_box('Always cipher message digitally?','use_signature_cripto',''); 130 } 131 else 132 { 133 create_check_box('Always sign message digitally?','use_signature_digital','','',True,'',False); 134 create_check_box('Always cipher message digitally?','use_signature_cripto','','',True,'',False); 135 } 136 } 79 137 80 138 $default = array( … … 83 141 ); 84 142 85 create_select_box( lang('Signature Type'),'type_signature',$default,'','','','onchange="javascript:changeType(this.value);" onload="javascript:alert(this.value);"');143 create_select_box('Signature Type','type_signature',$default,'','','','onchange="javascript:changeType(this.value);" onload="javascript:alert(this.value);"'); 86 144 87 145 if ($type == 'user' || $type == ''){
Note: See TracChangeset
for help on using the changeset viewer.