From f3704e18d89e4065cede8509256d7fbf483b7fe6 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 04 Apr 2006 17:46:27 -0400
Subject: [PATCH] Added labels for nextpage/previouspage

---
 program/lib/imap.inc |   83 ++++++++++++++++++++++++++---------------
 1 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/program/lib/imap.inc b/program/lib/imap.inc
index daacb03..97286c4 100644
--- a/program/lib/imap.inc
+++ b/program/lib/imap.inc
@@ -23,8 +23,28 @@
 		Function containing "_C_" in name require connection handler to be
 		passed as one of the parameters.  To obtain connection handler, use
 		iil_Connect()
+	VERSION:
+		IlohaMail-0.9-20050415
+	CHANGES:
+		File altered by Thomas Bruederli <roundcube@gmail.com>
+		to fit enhanced equirements by the RoundCube Webmail:
+		- Added list of server capabilites and check these before invoking commands
+		- Added junk flag to iilBasicHeader
+		- Enhanced error reporting on fsockopen()
+		- Additional parameter for SORT command
+		- Removed Call-time pass-by-reference because deprecated
+		- 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 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)
+		- Removed some debuggers (echo ...)
 
 ********************************************************/
+
 
 // changed path to work within roundcube webmail
 include_once("lib/icl_commons.inc");
@@ -191,7 +211,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;
     }
@@ -212,7 +232,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;
@@ -287,8 +307,8 @@
 	$iil_errornum = 0;
 	
 	//strip slashes
-	$user = stripslashes($user);
-	$password = stripslashes($password);
+	// $user = stripslashes($user);
+	// $password = stripslashes($password);
 	
 	//set auth method
 	$auth_method = "plain";
@@ -317,9 +337,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;
 	
@@ -619,7 +639,6 @@
 	
 	$fp = $conn->fp;
 	$command = 's SORT ('.$field.') US-ASCII ALL '."$add\r\n";
-	//$command = 's SORT ('.$field.') US-ASCII ALL UNDELETED'."\r\n";
 	$line = $data = '';
 	
 	if (!fputs($fp, $command)) return false;
@@ -1193,9 +1212,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 CONTENT-TRANSFER-ENCODING CONTENT-TYPE MESSAGE-ID)])\r\n";
-
-    // echo "// $request\n\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{
@@ -1246,9 +1263,11 @@
 			$result[$id]->subject = str_replace("\n", "", $headers["subject"]);
 			$result[$id]->replyto = str_replace("\n", " ", $headers["reply-to"]);
 			$result[$id]->cc = str_replace("\n", " ", $headers["cc"]);
+			$result[$id]->bcc = str_replace("\n", " ", $headers["bcc"]);
 			$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"]);
 
@@ -1256,8 +1275,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 {
@@ -1379,7 +1397,7 @@
 	if (empty($flag)) $flag="ASC";
 	$flag=strtoupper($flag);
 	$stripArr = ($field=='subject') ? array('Re: ','Fwd: ','Fw: ',"\"") : array("\"");
-	
+
 	$c=count($a);
 	if ($c>0){
 		/*
@@ -1389,12 +1407,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;
 		}
 		
@@ -1560,12 +1588,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;
 	}
 }
@@ -1904,24 +1932,20 @@
 	if (!$len) return false;
 	
 	$request="A APPEND \"".$folder."\" (\\Seen) {".$len."}\r\n";
-	// echo $request.'<br>';
 	if (fputs($fp, $request)){
-		$line=iil_ReadLine($fp, 100);
-		// echo $line.'<br>';
-		
+		$line=iil_ReadLine($fp, 100);		
 		$sent = fwrite($fp, $message."\r\n");
 		flush();
 		do{
 			$line=iil_ReadLine($fp, 1000);
-			//echo $line.'<br>';
 		}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;
 	}
 }
@@ -1934,7 +1958,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;
 	}
 	
@@ -1961,15 +1985,14 @@
 		//read response
 		do{
 			$line=iil_ReadLine($fp, 1000);
-			//echo $line.'<br>';
 		}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