From 583f1c8d80c42195d0ee41f30a885e13d777b79f Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 08 Nov 2005 15:18:56 -0500
Subject: [PATCH] Added reply-to-all function (submitted by Julien Brette)

---
 program/lib/imap.inc |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/program/lib/imap.inc b/program/lib/imap.inc
index 7d225c6..6ca5220 100644
--- a/program/lib/imap.inc
+++ b/program/lib/imap.inc
@@ -52,6 +52,7 @@
 	var $recent;
 	var $rootdir;
 	var $delimiter;
+	var $capability = array();
 }
 
 class iilBasicHeader{
@@ -246,6 +247,9 @@
 function iil_C_NameSpace(&$conn){
 	global $my_prefs;
 	
+	if (!in_array('NAMESPACE', $conn->capability))
+	  return false;
+	
 	if ($my_prefs["rootdir"]) return true;
 	
 	fputs($conn->fp, "ns1 NAMESPACE\r\n");
@@ -325,7 +329,7 @@
 	}
 	
 	//open socket connection
-	$conn->fp = @fsockopen($host, $ICL_PORT, &$errno, &$errstr, 10);
+	$conn->fp = @fsockopen($host, $ICL_PORT, $errno, $errstr, 10);
 	if (!$conn->fp){
         $iil_error = "Could not connect to $host at port $ICL_PORT: $errstr";
         $iil_errornum = -1;
@@ -334,7 +338,7 @@
 
 	$iil_error.="Socket connection established\r\n";
 	$line=iil_ReadLine($conn->fp, 300);
-						
+
 	if (strcasecmp($auth_method, "check")==0){
 		//check for supported auth methods
 		
@@ -349,6 +353,8 @@
 			$a = explode(" ", $line);
 			if ($line[0]=="*"){
 				while ( list($k, $w) = each($a) ){
+				    if ($w!='*' && $w!='CAPABILITY')
+    					$conn->capability[] = $w;
 					if ((strcasecmp($w, "AUTH=CRAM_MD5")==0)||
 						(strcasecmp($w, "AUTH=CRAM-MD5")==0)){
 							$auth_method = "auth";
@@ -1214,8 +1220,10 @@
 					$i++;
 					$lines[$i] = trim(chop($line));
 				}
-			}while($line[0]!=")");
+			}while($line[0]!=")" && strncmp($line, $key, strlen($key)));  // patch from "Maksim Rubis" <siburny@hotmail.com>
 			
+            if(strncmp($line, $key, strlen($key)))
+            { 
 			//process header, fill iilBasicHeader obj.
 			//	initialize
 			if (is_array($headers)){
@@ -1239,12 +1247,21 @@
 			$result[$id]->cc = str_replace("\n", " ", $headers["cc"]);
 			$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']);
-			list($result[$id]->ctype,$foo) = explode(";", $headers["content-type"]);
+			$result[$id]->in_reply_to = ereg_replace("[\n<>]",'', $headers['in-reply-to']);
+			
+			list($result[$id]->ctype, $ctype_add) = explode(";", $headers["content-type"]);
+
+			if (preg_match('/charset="?([a-z0-9\-]+)"?/i', $ctype_add, $regs))
+				$result[$id]->charset = $regs[1];
+
 			$messageID = $headers["message-id"];
 			if ($messageID) $messageID = substr(substr($messageID, 1), 0, strlen($messageID)-2);
 			else $messageID = "mid:".$id;
 			$result[$id]->messageID = $messageID;
+			}
+            else {
+            $a=explode(" ", $line);
+            } 
 			
 		}
 	}while(strcmp($a[0], $key)!=0);
@@ -1360,6 +1377,7 @@
 	if ($field=="date"||$field=='internaldate') $field="timestamp";
 	if (empty($flag)) $flag="ASC";
 	$flag=strtoupper($flag);
+	$stripArr = ($field=='subject') ? array('Re: ','Fwd: ','Fw: ',"\"") : array("\"");
 	
 	$c=count($a);
 	if ($c>0){
@@ -1375,7 +1393,7 @@
 		reset($a);
 		while (list($key, $val)=each($a)){
 			$data=$a[$key]->$field;
-			if (is_string($data)) $data=strtoupper(str_replace("\"", "", $data));
+			if (is_string($data)) $data=strtoupper(str_replace($stripArr, "", $data));
 			$index[$key]=$data;
 		}
 		
@@ -1388,7 +1406,7 @@
 		$result=array();
 		reset($index);
 		while (list($key, $val)=each($index)){
-			$result[$i]=$a[$key];
+			$result[$key]=$a[$key];
 			$i++;
 		}
 	}
@@ -1874,7 +1892,7 @@
 	}
 }
 
-function iil_C_Append(&$conn, $folder, $message){
+function iil_C_Append(&$conn, $folder, &$message){
 	if (!$folder) return false;
 	$fp = $conn->fp;
 

--
Gitblit v1.9.1