Index: branches/2.2/expressoMail1_2/index.php
===================================================================
--- branches/2.2/expressoMail1_2/index.php	(revision 3414)
+++ branches/2.2/expressoMail1_2/index.php	(revision 3493)
@@ -76,5 +76,5 @@
 	$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] = $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0";
 	$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['notification_domains'] = $current_config['expressoMail_notification_domains'];
-	$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['googlegears_url'] = $current_config['expressoMail_googlegears_url'];	
+	$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['googlegears_url'] = $current_config['expressoMail_googlegears_url'];
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_assinar_criptografar'] = $GLOBALS['phpgw_info']['server']['use_assinar_criptografar'] ?  $GLOBALS['phpgw_info']['server']['use_assinar_criptografar'] : "0";
     $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_signature_digital_cripto'] : "0";
@@ -178,11 +178,16 @@
 
 	$obj = createobject("expressoMail1_2.functions");
+
+        // setting timezone preference
+        $zones = $obj->getTimezones();
+        $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['timezone'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['timezone'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['timezone'] : sprintf("%s", array_search("America/Sao_Paulo", $zones));
+
 	// este arquivo deve ser carregado antes que
 	// os demais pois nele contem a função get_lang
 	// que é utilizada em diversas partes
 	echo $obj -> getFilesJs("js/common_functions.js");
-	include("inc/load_lang.php"); 
-
-	// INCLUDE these JS Files:
+	include("inc/load_lang.php");
+
+        // INCLUDE these JS Files:
 	if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_local_messages']) 
 		echo "<script src='js/gears_init.js'></script>";
Index: branches/2.2/expressoMail1_2/setup/phpgw_en.lang
===================================================================
--- branches/2.2/expressoMail1_2/setup/phpgw_en.lang	(revision 3441)
+++ branches/2.2/expressoMail1_2/setup/phpgw_en.lang	(revision 3493)
@@ -362,4 +362,5 @@
 The size of the message is	expressoMail1_2	en	The size of the message is
 The size of this message has exceeded  the limit (%1B).	expressoMail1_2	en	The size of this message has exceeded  the limit (%1B).
+The Timezone you're in.	expressoMail1_2	en	The Timezone you're in.
 This mail box is empty	expressoMail1_2	en	This mail box is empty.
 This message is already opened!	expressoMail1_2	en	This message is already opened!
@@ -399,4 +400,5 @@
 What is the maximum number of results in an e-mail search?	expressoMail1_2	en	What is the maximum number of results in an e-mail search?
 What is the minimum number of characters in searching contacts?	expressoMail1_2	en	What is the minimum number of characters in searching contacts?
+What is your timezone?	expressoMail1_2	en	What is your timezone?
 Who	expressoMail1_2	en	Who
 With all	expressoMail1_2	en	With all
Index: branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3441)
+++ branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3493)
@@ -506,4 +506,5 @@
 The size of the message is	expressoMail1_2	pt-br	O tamanho da mensagem seja
 The size of this message has exceeded  the limit (%1B).	expressoMail1_2	pt-br	O tamanho desta mensagem excedeu o limite (maior que %1B).
+The Timezone you're in.	expressoMail1_2	pt-br	O fuso-horário em que você está.
 This is the number of messages shown in your mailbox per page	expressoMail1_2	pt-br	Este é o número de mensagens mostradas na sua caixa de correio por página
 This list has no participants	expressoMail1_2	pt-br	Esta lista nao possui nenhum participante.
@@ -556,4 +557,5 @@
 What is the maximum size of embedded images?	expressoMail1_2	pt-br	Qual o tamanho máximo das imagens inseridas nos emails?
 What is the minimum number of characters in searching contacts?	expressoMail1_2	pt-br	Qual é o número mínimo de caracteres ao pesquisar contatos?
+What is your timezone?	expressoMail1_2	pt-br	Qual o seu fuso-horário?
 When delete message, send it automatically to trash folder	expressoMail1_2	pt-br	Ao excluir um mensagem, mover automaticamente esta mensagem para a pasta lixeira
 When user send an email with image in body message, it changes the size	expressoMail1_2	pt-br	Quando o usuário envia um e-mail com a imagem no corpo da mensagem, ela muda o tamanho
Index: branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3427)
+++ branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3493)
@@ -109,8 +109,10 @@
 		$search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false;
 
-		if(!$this->mbox || !is_resource($this->mbox))
+                if(!$this->mbox || !is_resource($this->mbox))
 			$this->mbox = $this->open_mbox($folder);
 
 		$return = array();
+                // Para enviar o offset entre o timezone definido pelo usuário e GMT
+                $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
 		
 		if(!$search_box_type || $search_box_type=="UNSEEN" || $search_box_type=="SEEN") {
@@ -531,8 +533,8 @@
 			//return $return;
 		}else{
-            $return['body'] 		= $body;
-            $return['attachments'] 	= $return_get_body['attachments'];
-            $return['thumbs'] 		= $return_get_body['thumbs'];
-            $return['signature']	= $return_get_body['signature'];
+                    $return['body'] 		= $body;
+                    $return['attachments'] 	= $return_get_body['attachments'];
+                    $return['thumbs'] 		= $return_get_body['thumbs'];
+                    $return['signature']	= $return_get_body['signature'];
 		}
 
@@ -562,24 +564,26 @@
 		$return['msg_folder'] = $msg_folder;
 
-		$date_msg = gmdate("d/m/Y",$header->udate);
+                $offset = $this->functions->CalculateDateOffset();
+                $msgTimestamp = $header->udate + $offset;
+
+		$date_msg = gmdate("d/m/Y",$msgTimestamp);
 		if (date("d/m/Y") == $date_msg)
-			$return['udate'] = gmdate("H:i",$header->udate);
+			$return['udate'] = gmdate("H:i",$msgTimestamp);
 		else
 			$return['udate'] = $date_msg;
 
 		$return['msg_day'] = $date_msg;
-		$return['msg_hour'] = gmdate("H:i",$header->udate);
+		$return['msg_hour'] = gmdate("H:i",$msgTimestamp);
 
 		if (date("d/m/Y") == $date_msg) //no dia
 		{
-			$return['fulldate'] = gmdate("d/m/Y H:i",$header->udate);
-			$return['smalldate'] = gmdate("H:i",$header->udate);
+			$return['fulldate'] = gmdate("d/m/Y H:i",$msgTimestamp);
+			$return['smalldate'] = gmdate("H:i",$msgTimestamp);
 
 			$timestamp_now = strtotime("now");
-			$timestamp_msg_time = $header->udate;
-			// $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ.
+			$timestamp_msg_time = $msgTimestamp;
+			// $timestamp_now and $timestamp_msg_time are GMT.
 			// The variable $timestamp_diff is calculated without MailDate TZ.
-			$pdate = date_parse($header->MailDate);
-			$timestamp_diff = $timestamp_now - $timestamp_msg_time  + ($pdate['zone']*(-60));
+			$timestamp_diff = $timestamp_now - $timestamp_msg_time;
 
 			if (gmdate("H",$timestamp_diff) > 0)
@@ -601,6 +605,6 @@
 		}
 		else{
-			$return['fulldate'] = gmdate("d/m/Y H:i",$header->udate);
-			$return['smalldate'] = gmdate("d/m/Y",$header->udate);
+			$return['fulldate'] = gmdate("d/m/Y H:i",$msgTimestamp);
+			$return['smalldate'] = gmdate("d/m/Y",$msgTimestamp);
 		}
 
@@ -1620,4 +1624,5 @@
 		$return['new_msgs'] = imap_num_recent($this->mbox);
 		$return['msgs_to_delete'] = $msg_to_delete;
+                $return['offsetToGMT'] = $this->functions->CalculateDateOffset();
 		if($this->mbox && is_resource($this->mbox))
 			imap_close($this->mbox);
@@ -3293,4 +3298,6 @@
 		}
 
+                $offsetToGMT = $this->functions->CalculateDateOffset();
+
 		if($search){
 			$search_criteria = '';
@@ -3459,5 +3466,5 @@
 		if($header->from[0]->personal != "")
 			$from = $header->from[0]->personal;
-		$ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ."--". $flag;
+		$ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate + $this->functions->CalculateDateOffset())."--". $this->size_msg($header->Size) ."--". $flag;
 		return $ret_msg;
 	}
@@ -3706,11 +3713,7 @@
 	}
 	function get_header($msg_number){
-		$header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255);
+                $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.
-                $header->udate_original = $header->udate;
-		$pdate = date_parse($header->MailDate);
- 		$header->udate +=  $pdate['zone']*(-60);
 
 		if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) {
Index: branches/2.2/expressoMail1_2/inc/class.functions.inc.php
===================================================================
--- branches/2.2/expressoMail1_2/inc/class.functions.inc.php	(revision 3018)
+++ branches/2.2/expressoMail1_2/inc/class.functions.inc.php	(revision 3493)
@@ -1,4 +1,35 @@
 <?php
 	class Functions{
+
+                // get the offset against GMT.
+                function CalculateDateOffset()
+                {
+
+                    $timezone_index = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['timezone'];
+                    $zones = $this->getTimezones();
+                    $user_timezone = $zones[$timezone_index];
+                    $tz = new DateTimeZone($user_timezone);
+                    $gmt = new DateTimeZone("Etc/GMT+0");
+                    $gmttime = new DateTime("now", $gmt);
+                    $offset = $tz->getOffset($gmttime);
+                    return $offset;
+
+                }
+
+                function getTimezones()
+                {
+                    $zones = timezone_identifiers_list();
+                    $friendly_zones = array();
+                    foreach ($zones as $zone)
+                    {
+                        if (preg_match("/^(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)\/.*$/", $zone))
+                        {
+                            array_push($friendly_zones,  $zone);
+                        }
+
+                    }
+                    return $friendly_zones;
+                }
+
 		function CallVoipConnect($params){
 			$fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'];
Index: branches/2.2/expressoMail1_2/inc/hook_settings.inc.php
===================================================================
--- branches/2.2/expressoMail1_2/inc/hook_settings.inc.php	(revision 3414)
+++ branches/2.2/expressoMail1_2/inc/hook_settings.inc.php	(revision 3493)
@@ -20,4 +20,5 @@
 	\**************************************************************************/
 include_once("fckeditor.php");
+include_once("class.functions.inc.php");
 $type = isset($_GET['type']) ? $_GET['type']:$GLOBALS['type']; // FIX ME
 
@@ -211,4 +212,11 @@
 create_check_box('Use shortcuts?','use_shortcuts','n key (Open new message)<br>ESC key (Close tab)<br>i key (print)<br>e key (forward)<br>r key (reply)<br>DELETE key (delete the current message)<br>Ctrl + up (go to previous message)<br>Ctrl + down (go to next message)<br>Shift + up or down (select multiple messages)<br>F9  key (search at catalog)<br>');
 create_check_box('Auto save draft','auto_save_draft','When you are away from computer it saves automatically the message you are writing');
+
+unset($default);
+$functions = new functions();
+$zones = $functions->getTimezones();
+$default = array(sprintf("%s", array_search('America/Sao_Paulo', $zones)) => 'America/Sao_Paulo');
+create_select_box('What is your timezone?', 'timezone', $zones, 'The Timezone you\'re in.', $default);
+
 $default = array(
 	'65536' => lang('unlimited'),
Index: branches/2.2/expressoMail1_2/js/main.js
===================================================================
--- branches/2.2/expressoMail1_2/js/main.js	(revision 3427)
+++ branches/2.2/expressoMail1_2/js/main.js	(revision 3493)
@@ -433,5 +433,5 @@
 				if (!existent)
 				{
-					var new_msg = this.make_tr_message(data[i], current_folder);
+					var new_msg = this.make_tr_message(data[i], current_folder, data.offsetToGMT);
 					_dragArea.makeDragged(new_msg, data[i].msg_number, data[i].subject, true);
 					if (data[i].Recent == 'N')
Index: branches/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3459)
+++ branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3493)
@@ -789,10 +789,8 @@
 			tbody_element.appendChild(td_info);
 		}
-
-
 	for (var i=0; i < headers_msgs.length; i++){
 			if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
 				f_unseen++;
-			tr_element = make_tr_message(headers_msgs[i], msg_folder);
+                        tr_element = make_tr_message(headers_msgs[i], msg_folder, headers_msgs.offsetToGMT);
 			if (tr_element){
 				tbody_element.appendChild(tr_element);
@@ -838,5 +836,10 @@
 }
 
-function make_tr_message(headers_msgs, msg_folder){
+// Passar o parâmetro offset para esta função
+function make_tr_message(headers_msgs, msg_folder, offsetToGMT){
+                if (typeof offsetToGMT == 'undefined')
+                {
+                    offsetToGMT = 0;
+                }
 		var tr_element = document.createElement('tr');
 		if(typeof(preferences.line_height) != 'undefined')
@@ -1052,9 +1055,15 @@
 		var norm = function (arg) {return (arg < 10 ? '0'+arg : arg);};
 		var weekDays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
-		var date_msg = new Date(headers_msgs.udate*1000);
-		var today = new Date();
+
+                var today = new Date();
 		today.setHours(0);
 		today.setMinutes(0);
-		if (today.getTime() - date_msg.getTime() < 86400000)
+
+                 // Using offset between user defined timezone and GMT
+                 // Date object converts time to local timezone, so we have to adjust it
+                var udate_local = headers_msgs.udate*1000 + offsetToGMT*1000 + today.getTimezoneOffset()*60*1000;
+                var date_msg = new Date(udate_local);
+
+                if (today.getTime() - date_msg.getTime() < 86400000)
 			td_element5.innerHTML = norm(date_msg.getHours()) + ':' + norm(date_msg.getMinutes());
 		else
@@ -2891,4 +2900,5 @@
 	var tbody = Element('tbody_box');
 	for (var i=0; i<(headers_msgs.length); i++){
+            // passa parâmetro offset
 		var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
 		if (tr)
