[Vtigercrm-commits] [vtiger-commits] r6825 - in /vtigercrm/trunk/modules/Webmails: ListView.php MailParse.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Wed May 31 03:26:18 EDT 2006


Author: mmbrich
Date: Wed May 31 01:26:16 2006
New Revision: 6825

Log:
check for IMAP and SSL support and either error out or handle connections different

Modified:
    vtigercrm/trunk/modules/Webmails/ListView.php
    vtigercrm/trunk/modules/Webmails/MailParse.php

Modified: vtigercrm/trunk/modules/Webmails/ListView.php
==============================================================================
--- vtigercrm/trunk/modules/Webmails/ListView.php (original)
+++ vtigercrm/trunk/modules/Webmails/ListView.php Wed May 31 01:26:16 2006
@@ -12,7 +12,7 @@
 if($_REQUEST["mailbox"] && $_REQUEST["mailbox"] != "") {$mailbox=$_REQUEST["mailbox"];} else {$mailbox="INBOX";}
 if($_REQUEST["start"] && $_REQUEST["start"] != "") {$start=$_REQUEST["start"];} else {$start="1";}
 
-global $current_user;
+global $current_user,$mods;
 require_once('Smarty_setup.php');
 require_once("data/Tracker.php");
 require_once('themes/'.$theme.'/layout_utils.php');
@@ -21,8 +21,10 @@
 require_once('include/utils/UserInfoUtil.php');
 require_once("modules/Webmails/MailParse.php");
 
+$mods = parsePHPModules();
 $mailInfo = getMailServerInfo($current_user);
-if($adb->num_rows($mailInfo) < 1) {
+
+if($adb->num_rows($mailInfo) < 1 || !isset($mods["imap"]) || $mods["imap"] == "") {
 	echo "<center><font color='red'><h3>Please configure your mail settings</h3></font></center>";
 	exit();
 }

Modified: vtigercrm/trunk/modules/Webmails/MailParse.php
==============================================================================
--- vtigercrm/trunk/modules/Webmails/MailParse.php (original)
+++ vtigercrm/trunk/modules/Webmails/MailParse.php Wed May 31 01:26:16 2006
@@ -21,7 +21,7 @@
 	return (strlen($_tmp) % 4 == 0 ) ? "y" : "n";
 }
 function getImapMbox($mailbox,$temprow,$readonly='') {
-	global $mbox; 
+	global $mbox,$mods; 
 	$login_username= $temprow["mail_username"]; 
 	$secretkey=$temprow["mail_password"]; 
 	$imapServerAddress=$temprow["mail_servername"]; 
@@ -33,10 +33,18 @@
 	// first we will try a regular old IMAP connection: 
 	if($ssltype == "") {$ssltype = "notls";} 
 	if($sslmeth == "") {$sslmeth = "novalidate-cert";} 
-	if($readonly == "true")
+
+	if($readonly == "true") {
+	    if($mods["imap"]["SSL Support"] == "enabled")
 		$mbox = @imap_open("{".$imapServerAddress."/".$mail_protocol."/".$ssltype."/".$sslmeth."/readonly}".$mailbox, $login_username, $secretkey); 
-	else
+	    else
+		$mbox = @imap_open("{".$imapServerAddress."/".$mail_protocol."/readonly}".$mailbox, $login_username, $secretkey); 
+	} else {
+	    if($mods["imap"]["SSL Support"] == "enabled")
 		$mbox = @imap_open("{".$imapServerAddress."/".$mail_protocol."/".$ssltype."/".$sslmeth."}".$mailbox, $login_username, $secretkey); 
+	    else
+		$mbox = @imap_open("{".$imapServerAddress."/".$mail_protocol."}".$mailbox, $login_username, $secretkey); 
+	}
 
 	// next we'll try to make a port specific connection to see if that helps.
 	// this may need to be updated to remove SSL/TLS since the c-client libs
@@ -44,14 +52,21 @@
 	if(!$mbox) {
 	 	if($mail_protocol == 'pop3') {
 			if($readonly == "true")
-	 	        	$connectString = "{".$imapServerAddress."/".$mail_protocol.":110/".$ssltype."/readonly}".$mailbox;
+	 	        	$connectString = "{".$imapServerAddress."/".$mail_protocol.":110/readonly}".$mailbox;
 			else
-	 	        	$connectString = "{".$imapServerAddress."/".$mail_protocol.":110/".$ssltype."}".$mailbox;
+	 	        	$connectString = "{".$imapServerAddress."/".$mail_protocol.":110/}".$mailbox;
 	 	} else { 
-			if($readonly == "true")
-	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."/".$ssltype."/readonly}".$mailbox; 
-			else
-	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."/".$ssltype."}".$mailbox; 
+			if($readonly == "true") { 
+	    		    if($mods["imap"]["SSL Support"] == "enabled")
+	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."/".$ssltype."/".$sslmeth."/readonly}".$mailbox; 
+			    else
+	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."/}".$mailbox; 
+			} else {
+	    		    if($mods["imap"]["SSL Support"] == "enabled")
+	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."/".$ssltype."/".$sslmeth."}".$mailbox;
+			    else
+	 	        	$connectString = "{".$imapServerAddress.":143/".$mail_protocol."}".$mailbox;
+			}
 	 	} 
 	 	$mbox = imap_open($connectString, $login_username, $secretkey) or die("Connection to server failed ".imap_last_error()); 
 	} 
@@ -103,4 +118,33 @@
        }
         return false;
 }
+function parsePHPModules() {
+ ob_start();
+ phpinfo(INFO_MODULES);
+ $s = ob_get_contents();
+ ob_end_clean();
+
+ $s = strip_tags($s,'<h2><th><td>');
+ $s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s);
+ $s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s);
+ $vTmp = preg_split('/(<h2>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
+ $vModules = array();
+ for ($i=1;$i<count($vTmp);$i++) {
+  if (preg_match('/<h2>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) {
+   $vName = trim($vMat[1]);
+   $vTmp2 = explode("\n",$vTmp[$i+1]);
+   foreach ($vTmp2 AS $vOne) {
+   $vPat = '<info>([^<]+)<\/info>';
+   $vPat3 = "/$vPat\s*$vPat\s*$vPat/";
+   $vPat2 = "/$vPat\s*$vPat/";
+   if (preg_match($vPat3,$vOne,$vMat)) { // 3cols
+     $vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3]));
+   } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols
+     $vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
+   }
+   }
+  }
+ }
+ return $vModules;
+}
 ?>





More information about the vtigercrm-commits mailing list