Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 504)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 535)
@@ -82,5 +82,5 @@
 			$msg_number = $sort_array_msg[$msg_range_begin-1];
 
-			$header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255);
+			$header = $this->get_header($msg_number);
 			if (!is_object($header))
 				return false;			
@@ -101,7 +101,7 @@
 			//$return[$i]['msg_folder'] = $folder;
 			
-			$date_msg = date("d/m/Y",$header->udate);
-			if (date("d/m/Y") == $date_msg)
-				$return[$i]['udate'] = date("H:i",$header->udate);
+			$date_msg = gmdate("d/m/Y",$header->udate);
+			if (gmdate("d/m/Y") == $date_msg)
+				$return[$i]['udate'] = gmdate("H:i",$header->udate);
 			else
 				$return[$i]['udate'] = $date_msg;
@@ -171,9 +171,10 @@
 			$this->mbox = $this->open_mbox($msg_folder);		
 		
-		$header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255);
+		$header = $this->get_header($msg_number);
 		if (!$header) {
-			$return['status_get_msg_info'] = "false";
+			$return['status_get_msg_info'] = "false";			
 			return $return;
 		}
+		
 		$all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID));
 		$return_get_body = $this->get_body_msg($msg_number, $msg_folder);
@@ -198,4 +199,5 @@
 			$return['Forwarded'] = 'F';
 		}
+ 
 		else {
 			$return['Answered']	= $header->Answered;
@@ -206,21 +208,24 @@
 		$return['msg_folder'] = $msg_folder;
 	
-		$date_msg = date("d/m/Y",$header->udate);
+		$date_msg = gmdate("d/m/Y",$header->udate);
 		if (date("d/m/Y") == $date_msg)
-			$return['udate'] = date("H:i",$header->udate);
+			$return['udate'] = gmdate("H:i",$header->udate);
 		else
 			$return['udate'] = $date_msg;
 		
 		$return['msg_day'] = $date_msg; 
-		$return['msg_hour'] = date("H:i",$header->udate);
+		$return['msg_hour'] = gmdate("H:i",$header->udate);
 		
 		if (date("d/m/Y") == $date_msg) //no dia
 		{
-			$return['fulldate'] = date("d/m/Y H:i",$header->udate);
-			$return['smalldate'] = date("H:i",$header->udate);
-			
-			$timestamp_now = strtotime("now");
-			$timestamp_msg_time = $header->udate;
-			$timestamp_diff = $timestamp_now - $timestamp_msg_time;
+			$return['fulldate'] = gmdate("d/m/Y H:i",$header->udate);
+			$return['smalldate'] = gmdate("H:i",$header->udate);
+			
+			$timestamp_now = strtotime("now");  			
+            $timestamp_msg_time = $header->udate;
+			// $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. 
+			// The variable $timestamp_diff is calculated without MailDate TZ.
+			$pdate = date_parse($header->MailDate);
+			$timestamp_diff = $timestamp_now - $timestamp_msg_time  + ($pdate['zone']*(-60));
 			
 			if (gmdate("H",$timestamp_diff) > 0)
@@ -242,6 +247,6 @@
 		}
 		else{
-			$return['fulldate'] = date("d/m/Y H:i",$header->udate);
-			$return['smalldate'] = date("d/m/Y",$header->udate);
+			$return['fulldate'] = gmdate("d/m/Y H:i",$header->udate);
+			$return['smalldate'] = gmdate("d/m/Y",$header->udate);
 		}
 		
@@ -936,5 +941,5 @@
 		foreach($msgs_to_exec as $msg_number => $command)
 		{
-			$header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox , $msg_number), 80, 255);
+			$header = $this->get_header($msg_number);
 			if (!is_object($header))
 				return false;
@@ -951,7 +956,7 @@
 			$return[$i]['Flagged']		= $header->Flagged;
 
-			$date_msg = date("d/m/Y",$header->udate);
-			if (date("d/m/Y") == $date_msg)
-				$return[$i]['udate'] = date("H:i",$header->udate);
+			$date_msg = gmdate("d/m/Y",$header->udate);
+			if (gmdate("d/m/Y") == $date_msg)
+				$return[$i]['udate'] = gmdate("H:i",$header->udate);
 			else
 				$return[$i]['udate'] = $date_msg;
@@ -1415,5 +1420,5 @@
 		for ($i=1; $i<=$num_msgs; $i++)
 		{
-			$header = imap_headerinfo($this->mbox, $i, 80, 255);
+			$header = $this->get_header($i);
 			// List UNSEEN messages.
 			if($search_box_type == "UNSEEN" &&  (!trim($header->Recent) && !trim($header->Unseen))){
@@ -2113,5 +2118,5 @@
 			foreach($messages as $msg_number)
 			{
-				$header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $msg_number), 80, 255);
+				$header = $this->get_header($msg_number);
 				if (!is_object($header))
 					return false;
@@ -2126,7 +2131,7 @@
 				$return[$j][$i]['Flagged']		= $header->Flagged;
 	
-				$date_msg = date("d/m/Y",$header->udate);
-				if (date("d/m/Y") == $date_msg)
-					$return[$j][$i]['udate'] = date("H:i",$header->udate);
+				$date_msg = gmdate("d/m/Y",$header->udate);
+				if (gmdate("d/m/Y") == $date_msg)
+					$return[$j][$i]['udate'] = gmdate("H:i",$header->udate);
 				else
 					$return[$j][$i]['udate'] = $date_msg;
@@ -2285,10 +2290,10 @@
 	function get_msg($uid_msg,$name_box, $mbox_stream )
 	{
-		$header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255);         
+		$header = $this->get_header($uid_msg);         
 		$subject = $this->decode_string($header->fetchsubject);
 		$from = $header->from[0]->mailbox;
 		if($header->from[0]->personal != "")
 			$from = $header->from[0]->personal;
-		$ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size);
+		$ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size);
 		return $ret_msg;                    
 	}	
@@ -2531,4 +2536,13 @@
 		return false;
 	}
+	function get_header($msg_number){
+		$header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255);
+		if (!is_object($header))
+			return false;
+		// Prepare udate from mailDate (DateTime arrived with TZ) for fixing summertime problem.
+		$pdate = date_parse($header->MailDate);
+ 		$header->udate +=  $pdate['zone']*(-60);
+		return $header;
+	}
 }
 ?>
