From cead5c727147faac362e742aa7bcecf07f68cd99 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 18 May 2006 17:24:42 -0400
Subject: [PATCH] Updated CHANGELOG

---
 program/lib/imap.inc |  104 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 73 insertions(+), 31 deletions(-)

diff --git a/program/lib/imap.inc b/program/lib/imap.inc
index 48b2cd1..51db669 100644
--- a/program/lib/imap.inc
+++ b/program/lib/imap.inc
@@ -36,7 +36,14 @@
 		- Parse charset from content-type in iil_C_FetchHeaders()
 		- Enhanced heaer sorting
 		- Pass message as reference in iil_C_Append (to save memory)
-		- Added BCC to the list of headers to fetch in iil_C_FetchHeaders()
+		- Added BCC and REFERENCE to the list of headers to fetch in iil_C_FetchHeaders()
+		- Leave messageID unchanged in iil_C_FetchHeaders()
+		- Avoid stripslahes in iil_Connect()
+		- Added patch to iil_SortHeaders() by Richard Green
+		- Removed <br> from error messages (better for logging)
+		- Added patch to iil_C_Sort() enabling UID SORT commands
+		- Added function iil_C_ID2UID()
+		- Casting date parts in iil_StrToTime() to avoid mktime() warnings
 		- Removed some debuggers (echo ...)
 
 ********************************************************/
@@ -207,7 +214,7 @@
         $conn->errorNum = 0;
         return $conn->fp;
     }else{
-        $conn->error .= 'Authentication failed (AUTH): <br>"'.htmlspecialchars($line)."\"";
+        $conn->error .= 'Authentication for '.$user.' failed (AUTH): "'.htmlspecialchars($line)."\"";
         $conn->errorNum = -2;
         return false;
     }
@@ -228,7 +235,7 @@
     }else{
         $result=false;
         fclose($conn->fp);
-        $conn->error .= 'Authentication failed (LOGIN):<br>"'.htmlspecialchars($line)."\"";
+        $conn->error .= 'Authentication for '.$user.' failed (LOGIN): "'.htmlspecialchars($line)."\"";
         $conn->errorNum = -2;
     }
     return $result;
@@ -303,8 +310,8 @@
 	$iil_errornum = 0;
 	
 	//strip slashes
-	$user = stripslashes($user);
-	$password = stripslashes($password);
+	// $user = stripslashes($user);
+	// $password = stripslashes($password);
 	
 	//set auth method
 	$auth_method = "plain";
@@ -333,9 +340,9 @@
 	//echo '<!-- conn sort_field: '.$my_prefs['sort_field'].' //-->';
 	
 	//check input
-	if (empty($host)) $iil_error .= "Invalid host<br>\n";
-	if (empty($user)) $iil_error .= "Invalid user<br>\n";
-	if (empty($password)) $iil_error .= "Invalid password<br>\n";
+	if (empty($host)) $iil_error .= "Invalid host\n";
+	if (empty($user)) $iil_error .= "Invalid user\n";
+	if (empty($password)) $iil_error .= "Invalid password\n";
 	if (!empty($iil_error)) return false;
 	if (!$ICL_PORT) $ICL_PORT = 143;
 	
@@ -607,15 +614,15 @@
 	//$month_a=array("Jan"=>1,"Feb"=>2,"Mar"=>3,"Apr"=>4,"May"=>5,"Jun"=>6,"Jul"=>7,"Aug"=>8,"Sep"=>9,"Oct"=>10,"Nov"=>11,"Dec"=>12);
 	$month_str=$a[1];
 	$month=$IMAP_MONTHS[$month_str];
-	$day=$a[0];
-	$year=$a[2];
+	$day=(int)$a[0];
+	$year=(int)$a[2];
 	$time=$a[3];
 	$tz_str = $a[4];
 	$tz = substr($tz_str, 0, 3);
-	$ta=explode(":",$time);
+	$ta = explode(":",$time);
 	$hour=(int)$ta[0]-(int)$tz;
-	$minute=$ta[1];
-	$second=$ta[2];
+	$minute=(int)$ta[1];
+	$second=(int)$ta[2];
 	
 	//make UNIX timestamp
 	$time2 = mktime($hour, $minute, $second, $month, $day, $year);
@@ -623,7 +630,7 @@
 	return $time2;
 }
 
-function iil_C_Sort(&$conn, $mailbox, $field, $add=''){
+function iil_C_Sort(&$conn, $mailbox, $field, $add='', $is_uid=FALSE, $encoding='US-ASCII'){
 	/*  Do "SELECT" command */
 	if (!iil_C_Select($conn, $mailbox)) return false;
 	
@@ -631,10 +638,16 @@
 	if ($field=='INTERNALDATE') $field='ARRIVAL';
 	$fields = array('ARRIVAL'=>1,'CC'=>1,'DATE'=>1,'FROM'=>1,'SIZE'=>1,'SUBJECT'=>1,'TO'=>1);
 	
-	if (!$fields[$field]) return false;
+	if (!$fields[$field])
+	  return false;
 	
+	$is_uid = $is_uid ? 'UID ' : '';
+	
+	if (!empty($add))
+	  $add = " $add";
+
 	$fp = $conn->fp;
-	$command = 's SORT ('.$field.') US-ASCII ALL '."$add\r\n";
+	$command = 's '. $is_uid .'SORT ('.$field.') '.$encoding.' ALL'."$add\r\n";
 	$line = $data = '';
 	
 	if (!fputs($fp, $command)) return false;
@@ -652,7 +665,7 @@
 	return $out;
 }
 
-function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field,$normalize=true){
+function iil_C_FetchHeaderIndex(&$conn, $mailbox, $message_set, $index_field, $normalize=true){
 	global $IMAP_USE_INTERNAL_DATE;
 	
 	$c=0;
@@ -1208,7 +1221,7 @@
 
 	/* FETCH date,from,subject headers */
 	$key="fh".($c++);
-	$request=$key." FETCH $message_set (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID)])\r\n";
+	$request=$key." FETCH $message_set (BODY.PEEK[HEADER.FIELDS (DATE FROM TO SUBJECT REPLY-TO IN-REPLY-TO CC BCC CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID REFERENCE)])\r\n";
 
 	if (!fputs($fp, $request)) return false;
 	do{
@@ -1263,6 +1276,7 @@
 			$result[$id]->encoding = str_replace("\n", " ", $headers["content-transfer-encoding"]);
 			$result[$id]->ctype = str_replace("\n", " ", $headers["content-type"]);
 			$result[$id]->in_reply_to = ereg_replace("[\n<>]",'', $headers['in-reply-to']);
+			$result[$id]->reference = $headers["reference"];
 			
 			list($result[$id]->ctype, $ctype_add) = explode(";", $headers["content-type"]);
 
@@ -1270,8 +1284,7 @@
 				$result[$id]->charset = $regs[1];
 
 			$messageID = $headers["message-id"];
-			if ($messageID) $messageID = substr(substr($messageID, 1), 0, strlen($messageID)-2);
-			else $messageID = "mid:".$id;
+			if (!$messageID) "mid:".$id;
 			$result[$id]->messageID = $messageID;
 			}
             else {
@@ -1393,7 +1406,7 @@
 	if (empty($flag)) $flag="ASC";
 	$flag=strtoupper($flag);
 	$stripArr = ($field=='subject') ? array('Re: ','Fwd: ','Fw: ',"\"") : array("\"");
-	
+
 	$c=count($a);
 	if ($c>0){
 		/*
@@ -1403,12 +1416,22 @@
 			and use that to sort the main array.
 		*/
                 
-                // create "index" array
+		// create "index" array
 		$index=array();
 		reset($a);
 		while (list($key, $val)=each($a)){
-			$data=$a[$key]->$field;
-			if (is_string($data)) $data=strtoupper(str_replace($stripArr, "", $data));
+
+			if ($field=="timestamp"){
+				$data = @strtotime($val->date);
+				if ($data == false)
+					$data = $val->timestamp;
+				}
+			else {
+				$data = $val->$field;
+				if (is_string($data))
+					$data=strtoupper(str_replace($stripArr, "", $data));
+				}
+
 			$index[$key]=$data;
 		}
 		
@@ -1556,6 +1579,25 @@
 	return false;
 }
 
+function iil_C_ID2UID(&$conn, $folder, $id){
+	$fp = $conn->fp;
+	$result=-1;
+	if ($id > 0) {
+		if (iil_C_Select($conn, $folder)){
+			$key = "FUID";
+			if (fputs($fp, "$key FETCH $id (UID)\r\n")){
+				do{
+					$line=chop(iil_ReadLine($fp, 1024));
+					if (eregi("^\* $id FETCH \(UID (.*)\)", $line, $r)){
+						$result = $r[1];
+					}
+				} while (!preg_match("/^$key/", $line));
+			}
+		}
+	}
+	return $result;
+}
+
 function iil_C_Search(&$conn, $folder, $criteria){
 	$fp = $conn->fp;
 	if (iil_C_Select($conn, $folder)){
@@ -1574,12 +1616,12 @@
 		$result_code=iil_ParseResult($line);
 		if ($result_code==0) return $messages;
 		else{
-			$conn->error = "iil_C_Search: ".$line."<br>\n";
+			$conn->error = "iil_C_Search: ".$line."\n";
 			return false;
 		}
 		
 	}else{
-		$conn->error = "iil_C_Search: Couldn't select \"$folder\" <br>\n";
+		$conn->error = "iil_C_Search: Couldn't select \"$folder\"\n";
 		return false;
 	}
 }
@@ -1927,11 +1969,11 @@
 		}while($line[0]!="A");
 	
 		$result = (iil_ParseResult($line)==0);
-		if (!$result) $conn->error .= $line."<br>\n";
+		if (!$result) $conn->error .= $line."\n";
 		return $result;
 	
 	}else{
-		$conn->error .= "Couldn't send command \"$request\"<br>\n";
+		$conn->error .= "Couldn't send command \"$request\"\n";
 		return false;
 	}
 }
@@ -1944,7 +1986,7 @@
 	$in_fp = false;				
 	if (file_exists(realpath($path))) $in_fp = fopen($path, "r");
 	if (!$in_fp){ 
-		$conn->error .= "Couldn't open $path for reading<br>\n";
+		$conn->error .= "Couldn't open $path for reading\n";
 		return false;
 	}
 	
@@ -1974,11 +2016,11 @@
 		}while($line[0]!="A");
 			
 		$result = (iil_ParseResult($line)==0);
-		if (!$result) $conn->error .= $line."<br>\n";
+		if (!$result) $conn->error .= $line."\n";
 		return $result;
 	
 	}else{
-		$conn->error .= "Couldn't send command \"$request\"<br>\n";
+		$conn->error .= "Couldn't send command \"$request\"\n";
 		return false;
 	}
 }

--
Gitblit v1.9.1