[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Initial Developer of the Original Code is FOSS Labs. 6 * Portions created by FOSS Labs are Copyright (C) FOSS Labs. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 include_once ('config.php'); 13 require_once ('include/logging.php'); 14 require_once ('include/database/PearDatabase.php'); 15 require_once ('include/utils/utils.php'); 16 17 class MailBox { 18 19 var $mbox; 20 var $db; 21 var $boxinfo; 22 var $readonly='false'; 23 var $enabled; 24 25 var $login_username; 26 var $secretkey; 27 var $imapServerAddress; 28 var $ssltype; 29 var $sslmeth; 30 var $box_refresh; 31 var $mails_per_page; 32 var $mail_protocol; 33 var $account_name; 34 var $display_name; 35 var $mailbox; 36 var $mailList; 37 38 function MailBox($mailbox = '') { 39 global $current_user; 40 $this->db = new PearDatabase(); 41 $this->db->println("Entering MailBox($mailbox)"); 42 43 $this->mailbox = $mailbox; 44 $tmp = getMailServerInfo($current_user); 45 46 if($this->db->num_rows($tmp) < 1) 47 $this->enabled = 'false'; 48 else 49 $this->enabled = 'true'; 50 51 $this->boxinfo = $this->db->fetch_array($tmp); 52 53 $this->login_username=trim($this->boxinfo["mail_username"]); 54 $this->secretkey=trim($this->boxinfo["mail_password"]); 55 $this->imapServerAddress=gethostbyname(trim($this->boxinfo["mail_servername"])); 56 $this->mail_protocol=$this->boxinfo["mail_protocol"]; 57 $this->ssltype=$this->boxinfo["ssltype"]; 58 $this->sslmeth=$this->boxinfo["sslmeth"]; 59 $this->box_refresh=trim($this->boxinfo["box_refresh"]); 60 $this->mails_per_page=trim($this->boxinf["mails_per_page"]); 61 if($this->mails_per_page < 1) 62 $this->mails_per_page=20; 63 64 $this->mail_protocol=$this->boxinfo["mail_protocol"]; 65 $this->account_name=$this->boxinfo["account_name"]; 66 $this->display_name=$this->boxinfo["display_name"]; 67 //$this->imapServerAddress=$this->boxinfo["mail_servername"]; 68 69 $this->db->println("Setting Mailbox Name"); 70 if($this->mailbox != "") 71 $this->mailbox=$mailbox; 72 73 $this->db->println("Opening Mailbox"); 74 if(!$this->mbox && $this->mailbox != "") 75 $this->getImapMbox(); 76 77 $this->db->println("Loading mail list"); 78 if($this->mbox) 79 $this->mailList = $this->fullMailList(); 80 81 $this->db->println("Exiting MailBox($mailbox)"); 82 } 83 84 function fullMailList() { 85 $mailHeaders = @imap_headers($this->mbox); 86 $numEmails = sizeof($mailHeaders); 87 $mailOverviews = @imap_fetch_overview($this->mbox, "1:$numEmails", 0); 88 $out = array("headers"=>$mailHeaders,"overview"=>$mailOverviews,"count"=>$numEmails); 89 return $out; 90 } 91 92 function isBase64($iVal){ 93 $_tmp=preg_replace("/[^A-Z0-9\+\/\=]/i","",$iVal); 94 return (strlen($_tmp) % 4 == 0 ) ? "y" : "n"; 95 } 96 97 function getImapMbox() { 98 $this->db->println("Entering getImapMbox()"); 99 $mods = parsePHPModules(); 100 $this->db->println("Parsing PHP Modules"); 101 102 // first we will try a regular old IMAP connection: 103 if($this->ssltype == "") {$this->ssltype = "notls";} 104 if($this->sslmeth == "") {$this->sslmeth = "novalidate-cert";} 105 106 if($this->mail_protocol == "pop3") 107 $port = "110"; 108 else { 109 if($mods["imap"]["SSL Support"] == "enabled" && $this->ssltype == "ssl") 110 $port = "993"; 111 else 112 $port = "143"; 113 } 114 115 $this->db->println("Building connection string"); 116 if(preg_match("/@/",$this->login_username)) { 117 $mailparts = split("@",$this->login_username); 118 $user="".trim($mailparts[0]).""; 119 $domain="".trim($mailparts[1]).""; 120 121 // This section added to fix a bug when connecting as user@domain.com 122 if($this->readonly == "true") { 123 if($mods["imap"]["SSL Support"] == "enabled") 124 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/".$this->ssltype."/".$this->sslmeth."/user={$user}@{$domain}/readonly}".$this->mailbox; 125 else 126 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/notls/novalidate-cert/user={$user}@{$domain}/readonly}".$this->mailbox; 127 } else { 128 if($mods["imap"]["SSL Support"] == "enabled") 129 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/".$this->ssltype."/".$this->sslmeth."/user={$user}@{$domain}}".$this->mailbox; 130 else 131 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/notls/novalidate-cert/user={$user}@{$domain}}".$this->mailbox; 132 } 133 } else { 134 if($this->readonly == "true") { 135 if($mods["imap"]["SSL Support"] == "enabled") 136 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/".$this->ssltype."/".$this->sslmeth."/readonly}".$this->mailbox; 137 else 138 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/notls/novalidate-cert/readonly}".$this->mailbox; 139 } else { 140 if($mods["imap"]["SSL Support"] == "enabled") 141 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/".$this->ssltype."/".$this->sslmeth."}".$this->mailbox; 142 else 143 $connectString = "{".$this->imapServerAddress."/".$this->mail_protocol.":".$port."/notls/novalidate-cert}".$this->mailbox; 144 } 145 } 146 $this->db->println("Done Building Connection String.. Connecting to box"); 147 $this->mbox = imap_open($connectString, $this->login_username, $this->secretkey); 148 $this->db->println("Done connecting to box"); 149 } 150 } // END CLASS 151 152 153 function parsePHPModules() { 154 ob_start(); 155 phpinfo(INFO_MODULES); 156 $s = ob_get_contents(); 157 ob_end_clean(); 158 159 $s = strip_tags($s,'<h2><th><td>'); 160 $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s); 161 $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s); 162 $vTmp = preg_split('/(<h2>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE); 163 $vModules = array(); 164 for ($i=1;$i<count($vTmp);$i++) { 165 if (preg_match('/<h2>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) { 166 $vName = trim($vMat[1]); 167 $vTmp2 = explode("\n",$vTmp[$i+1]); 168 foreach ($vTmp2 AS $vOne) { 169 $vPat = '<info>([^<]+)<\/info>'; 170 $vPat3 = "/$vPat\s*$vPat\s*$vPat/"; 171 $vPat2 = "/$vPat\s*$vPat/"; 172 if (preg_match($vPat3,$vOne,$vMat)) { // 3cols 173 $vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3])); 174 } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols 175 $vModules[$vName][trim($vMat[1])] = trim($vMat[2]); 176 } 177 } 178 } 179 } 180 return $vModules; 181 } 182 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |