Ignore:
Timestamp:
06/20/09 01:07:18 (15 years ago)
Author:
rafaelraymundo
Message:

Ticket #558 - Adicionada funcionalidade de assinatura e criptografia de e-mails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.imap_functions.inc.php

    r1012 r1035  
    404404                $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); 
    405405 
    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        } 
    411420                $pattern = '/^[ \t]*Disposition-Notification-To(^:)*:(.+)*@(.+)*$/isUm'; 
    412421                if (preg_match($pattern, $header_, $fields)) 
     
    661670                if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece 
    662671                { 
     672            if(strtolower($msg->structure[$msg_number]->subtype) == 'x-pkcs7-mime'){ 
     673                $return['body']='isCripted'; 
     674                return $return; 
     675            } 
     676 
    663677                        $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 
    665684                        $content = ''; 
    666685                        if (strtolower($msg->structure[$msg_number]->subtype) == "plain") 
     
    10071026 
    10081027        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"); 
    10101031                foreach ($msg->file_type[$msg_number] as $index => $file_type) 
    10111032                { 
     1033            $sign = array(); 
     1034                        $temp = $this->get_info_head_msg($msg_number); 
     1035                        if($temp['ContentType'] =='normal') return $sign; 
    10121036                        $file_type = strtolower($file_type); 
    10131037                        if(strtolower($msg->encoding[$msg_number][$index]) == 'base64')  
     
    10151039                                if ($file_type == 'application/x-pkcs7-signature' || $file_type == 'application/pkcs7-signature')  
    10161040                                { 
    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) 
    10241053                                        { 
    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; 
    10321058                                        } 
    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                                        } 
    10361154                                     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                    } 
    10381160                                } 
    10391161                        } 
     
    11731295                        * a perda em performance é insignificante. 
    11741296                        */ 
    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); 
    11781299                        $return[$i]['Importance'] = $flag==0?"Normal":$importance[1]; 
    11791300                         
     
    11861307                         
    11871308                        $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); 
    11881311                        $return[$i]['Recent']           = $header->Recent; 
    11891312                        $return[$i]['Unseen']           = $header->Unseen; 
     
    12361359        } 
    12371360 
     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 
    12381385        function get_folders_list($params = null) 
    12391386        { 
     
    12481395                if (is_array($folders_list)) { 
    12491396                        reset($folders_list); 
     1397            $this->ldap = new ldap_functions(); 
    12501398                         
    12511399                        $i = 0; 
    12521400                        while (list($key, $val) = each($folders_list)) { 
    12531401                                $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 
    1254                                 $result[$i]['folder_unseen'] = $status->unseen; 
    1255                          
     1402 
    12561403                                //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 
    12571404                                $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; 
    12581411                                $folder_id = $tmp_folder_id[1]; 
    12591412                                $result[$i]['folder_id'] = $folder_id; 
     
    12631416                                $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 
    12641417                                if (is_numeric($result[$i]['folder_name']))     { 
    1265                                         $this->ldap = new ldap_functions(); 
     1418                                        //$this->ldap = new ldap_functions(); 
    12661419                                        if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){ 
    12671420                                                $result[$i]['folder_name'] = $cn; 
     
    14281581                $return_receipt = $params['input_return_receipt']; 
    14291582                $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        } 
    14311626                //echo "<script language=\"javascript\">javascript:alert('".$body."');</script>"; 
    14321627                $attachments = $params['FILES']; 
     
    14471642//////////////////////////////////////////////////////////////////////////////////////////////////// 
    14481643                $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             
    14511653                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
    14521654                $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; 
     
    14651667                $mail->Subject = $subject; 
    14661668                $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        } 
    14681762 
    14691763//////////////////////////////////////////////////////////////////////////////////////////////////// 
     
    15891883                else 
    15901884                { 
     1885            if ($signed && !$params['smime']) 
     1886                        { 
     1887                                return $sent; 
     1888                        } 
    15911889                        if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True")  
    15921890                        { 
     
    16061904                        return array("success" => true); 
    16071905                } 
     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); 
    16081926        } 
    16091927 
     
    23672685                        $folder_id = "INBOX"; 
    23682686                 
    2369                 if(!$this->mbox) 
     2687                if(!$this->mbox || !is_resource($this->mbox)) 
    23702688                        $this->mbox = $this->open_mbox(); 
    23712689 
     
    29583276    } 
    29593277 
     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     
    29603325//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 
    29613326//Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. 
Note: See TracChangeset for help on using the changeset viewer.