Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/draw_api.js	(revision 4644)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/draw_api.js	(revision 4664)
@@ -18,5 +18,5 @@
 	}
 var currentTab,numBox = 0; // Open Tab and num of mailboxes opened at context
-// Objeto Map, talvez o ideal fosse adicionar este objeto à Api do egroupware, e carregá-lo
+// Objeto Map, talvez o ideal fosse adicionar este objeto ï¿œ Api do egroupware, e carregï¿œ-lo
 // aqui no expressoMail.
 function Map()
@@ -110,9 +110,60 @@
 			cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, update_tree_folders);
 		}
-
+                //MAILARCHIVE_14
+                //Create local folders main structure tree
+                if(preferences.use_local_messages=="1"){
+                    var disabled_local_span = document.getElementById('llocal_disabledtree_folders');
+
+                    //Services are disabled: because Mail Archiver is not running/installed or have just crashed. Link activation is created here
+                    if(!expresso_mail_archive.enabled){
+                        tree_folders.getNodeById("local_disabled").alter({caption:get_lang('Offline'), onClick: "retry_local_folders()"});
+                        tree_folders.getNodeById("local_disabled")._refresh();
+
+                        if((disabled_local_span) && (!document.getElementById('services_retry'))){
+                            disabled_local_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_services.png)";
+
+                            var service_retry = document.createElement("SPAN");
+                            service_retry.id = 'services_retry';
+                            service_retry.className = 'clean_trash';
+                            service_retry.style.cursor = 'pointer';
+                            service_retry.onclick = function () {services_retry();};
+                            service_retry.innerHTML = "["+get_lang("Retry")+"]";
+                            service_retry.title="Reconectar ao Mail Archiver";
+                            service_retry.onmouseover = function() {service_retry.style.color="red";};
+                            service_retry.onmouseout= function() {service_retry.style.color="#666666";}; //#114FA4
+                            disabled_local_span.parentNode.appendChild(service_retry);
+                        }
+                    }
+                    //Services enabled: list folders service must be invoqued
+                    else{
+                        var services_retry_span = document.getElementById('services_retry');
+
+                        if(services_retry_span){
+                            //window.alert('Tem services_retry -> vai remover o disabled_local_span');
+                            var node_disabled_to_remove = document.getElementById('nlocal_disabledtree_folders');
+                            //document.getElementById('chlocal_roottree_folders').removeChild('nlocal_disabledtree_folders');
+                            //services_retry_span.parentNode.removeChild(services_retry_span);
+                            node_disabled_to_remove.parentNode.removeChild(node_disabled_to_remove);
+                        }
+                        //else
+                          //  window.alert('Sem services retry');
+
+                        //tree_folders.getNodeById("local_disabled").alter({caption:get_lang('List_Folders')});
+                                                
+                       //expresso_mail_archive.getFoldersList('FERNANDAO22', "");
+                       var drawinginfo = {treeObject: tree_folders, treeName: 'tree_folders'};
+                       expresso_mail_archive.drawdata = drawinginfo;
+                       //expresso_mail_archive.getFoldersList("");                        
+                        
+                        //tree_folders.getNodeById("local_root")._refresh();
+
+                        if(disabled_local_span)
+                            disabled_local_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_folder.png)";                       
+                    }      
+                }
 		return;
 	}
 	else{
-		if (!expresso_offline) {
+                if (!expresso_offline) {
 			tree_folders = new dFTree({name: 'tree_folders'});
 
@@ -154,4 +205,28 @@
 			}
 		}
+                //MAILARCHIVER
+                //Create local folders main structure tree
+                if(preferences.use_local_messages=="1"){                    
+                    //Add the local_root node
+                    var root_local = new dNode({id: "local_root", caption: get_lang('local folders'), plusSign: true});
+                    tree_folders.add(root_local, "root");   
+                    
+                    //Services are disabled: because Mail Archiver is not running/installed or have just crashed. Link activation is created here
+                    if(!expresso_mail_archive.enabled){
+                        var n_LocalDisabled = new dNode({id: "local_disabled", caption: get_lang('Offline'), onClick: "services_retry()", plusSign:false});
+                        tree_folders.add(n_LocalDisabled, 'local_root');
+                    }
+                    
+                    //Services enabled: list folders service must be invoqued
+                    else{
+                        var drawinginfo = {treeObject: tree_folders, treeName: 'tree_folders'};
+                        expresso_mail_archive.drawdata = drawinginfo;
+                        //expresso_mail_archive.getFoldersList("");
+                    }
+                    
+                    //Opens the local folders tree view
+                    //tree_folders.getNodeById("local_root").open();
+                    
+                }                
 
 
@@ -183,63 +258,5 @@
 //		cExecute('$this.rss.getChannels',handlerChannel);
 
-
-		/**
-		 * Pastas locais
-		 */
-		if (preferences.use_local_messages==1 || expresso_offline) {
-			if (!window.google || !google.gears) {
-				if (!expresso_local_messages.installGears())
-					preferences.use_local_messages=0;
-			}
-			else{
-				if (!window.google || !google.gears) {
-				temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
-				if (temp) {
-					location.href = "http://gears.google.com/?action=install&message="+
-					"Para utilizar o recurso de mensagens locais, instale o google gears&return=" +
-					document.location.href;
-				}
-				else {
-					preferences.use_local_messages=0;
-				}
-			}
-			else{
-				if (expresso_offline)
-					tree_folders = new dFTree({
-						name: 'tree_folders'
-					});
-				var root_local = new dNode({
-					id: "local_root",
-					caption: get_lang('local folders')
-				});
-				tree_folders.add(root_local, "root"); //coloca root local
-				var local_folders = expresso_local_messages.list_local_folders();
-				for (var i in local_folders) { //Coloca as pastas locais.
-					var node_root = "local_root";
-					var new_caption = local_folders[i][0];
-					if (local_folders[i][0].indexOf("/") != "-1") {
-						final_pos = local_folders[i][0].lastIndexOf("/");
-						node_root = "local_" + local_folders[i][0].substr(0, final_pos);
-						new_caption = local_folders[i][0].substr(final_pos + 1);
-					}
-					if (local_folders[i][1] > 0)
-						var nodeLocal = new dNode({
-							id: "local_" + local_folders[i][0],
-							caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
-							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-							plusSign: local_folders[i][2]
-						});
-					else
-						var nodeLocal = new dNode({
-							id: "local_" + local_folders[i][0],
-							caption: lang_folder(new_caption),
-							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-							plusSign: local_folders[i][2]
-						});
-						tree_folders.add(nodeLocal, node_root);
-					}
-				}
-			}
-		}
+             
 
 		tree_folders.draw(Element('content_folders'));
@@ -265,4 +282,6 @@
 		var sent_span_default=document.getElementById('llocal_'+sentfolder+'tree_folders');
 
+                //MAILARCHIVER
+                var disabled_local_span = document.getElementById('llocal_disabledtree_folders');
 
 		if (trash_span)
@@ -290,4 +309,7 @@
 			sent_span_default.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_sent.png)";
 
+                //MAILARCHIVER
+                if ((disabled_local_span) && (!expresso_mail_archive.enabled))
+                    disabled_local_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_services.png)";
 
 		draw_paging(Element('tot_m').innerHTML);
@@ -320,4 +342,18 @@
 			   }
 
+                //MAILARCHIVER
+		if(document.getElementById("nlocal_disabledtree_folders") && (!expresso_mail_archive.enabled) && (!document.getElementById('services_retry')))
+		{
+		    var service_retry = document.createElement("SPAN");
+		    service_retry.id = 'services_retry';
+		    service_retry.className = 'clean_trash';
+		    service_retry.style.cursor = 'pointer';
+		    service_retry.onclick = function () {services_retry();};
+		    service_retry.innerHTML = "["+get_lang("Retry")+"]";
+		    service_retry.title="Reconectar ao Mail Archiver";
+		    service_retry.onmouseover = function() {service_retry.style.color="red";};
+		    service_retry.onmouseout= function() {service_retry.style.color="#666666";}; //#114FA4
+		    document.getElementById("nlocal_disabledtree_folders").appendChild(service_retry);
+		}
 
 		if(!expresso_offline)
@@ -365,8 +401,16 @@
 
 function draw_tree_local_folders() {
+        //MAILARCHIVER    
+        if(preferences.use_local_messages=="1"){
+            //var local_folders_list = expresso_mail_archive.getFoldersList('JOAQUIM', "");
+            //var drawinginfo = {treeObject: tree_folders};
+            var local_folders_list = expresso_mail_archive.getFoldersList("");
+            //window.alert('Draw tree local folders data = ' + expresso_mail_archive.folders);
+        }
+    
 	/**
 	 * Pastas locais
 	 */
-	if(preferences.use_local_messages==1 || expresso_offline) {
+	/*if(preferences.use_local_messages==1 || expresso_offline) {
 		var local_folders = expresso_local_messages.list_local_folders();
 		var has_changes = false;
@@ -412,5 +456,5 @@
 			tree_folders.getNodeById("local_root").open();
 
-	}
+	}*/
 }
 
@@ -470,6 +514,7 @@
 
 // Action on change folders.
-function change_folder(folder, folder_name){
-	if (openTab.imapBox[0] != folder)
+function change_folder(folder, folder_name, tree_name){
+	window.alert('em change folder com folder='+folder+', folder_name='+folder_name+' e tree_name='+tree_name);
+        if (openTab.imapBox[0] != folder)
 	{
 		current_folder = folder;
@@ -486,5 +531,5 @@
 			return true;
 		}
-		proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
+		proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box,tree_name);
 	}
 	else
@@ -856,5 +901,5 @@
 }
 
-// Passar o parâmetro offset para esta função
+// Passar o parï¿œmetro offset para esta funï¿œï¿œo
 function make_tr_message(headers_msgs, msg_folder, offsetToGMT){
                 if (typeof offsetToGMT == 'undefined')
@@ -1225,5 +1270,5 @@
         var folder;
 
-        //Correção para fazer funcionar e-mails assinados no formato encapsulado.
+        //Correï¿œï¿œo para fazer funcionar e-mails assinados no formato encapsulado.
        // folder_id = info_msg.original_ID ? info_msg.original_ID: info_msg.msg_number;
         if ((folder = document.getElementById(info_msg.original_ID)) == null)
@@ -1526,4 +1571,23 @@
 
 	div_other_options.innerHTML = option_reply_to_all + option_reply_without_history + option_reply_to_all_without_history;
+        
+        //MAILARCHIVER
+        if(preferences.use_local_messages==1){
+            if(expresso_mail_archive.enabled){
+                //window.alert('Ativo, adicionar no footer');
+                /*TODO: CHECK LOCAL FOLDER TO ADD ARCHIVE OR UNARCHIEVE FOOTER LINK OPERATION*/
+                /*if(proxy_mensagens.is_local_folder(current_folder))
+                    span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
+                  else
+                    span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null,null)">'+get_lang("Archive")+'</span>';
+                */
+               span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null,null)">'+get_lang("Archive")+'</span>';
+            }
+            //else
+                //window.alert('Inativo. sem footer');
+        }
+        //else
+          //  window.alert('Sem a preferencia, nao faz nada');        
+        
 	if (use_spam_filter) {
 		if(info_msg.msg_folder == 'INBOX'+cyrus_delimiter+'Spam')
@@ -1958,5 +2022,5 @@
 					(url_decode(info_msg.attachments[i].name).indexOf(".vcard")!=-1))
 			{
-				//Link para importar calendário
+				//Link para importar calendï¿œrio
 				var link_import_attachment = new Image();
 				link_import_attachment.src = "templates/"+template+"/images/new.png";
@@ -2077,5 +2141,5 @@
 				
 				if ( ( links.item( i ).href.indexOf( 'javascript:' ) !== 0 ) && 
-					(links.item( i ).href.indexOf(anchor_pattern) !== 0) ) //se não for âncora
+					(links.item( i ).href.indexOf(anchor_pattern) !== 0) ) //se nï¿œo for ï¿œncora
 						links.item( i ).setAttribute( 'target', '_blank' );
 			}
@@ -2436,5 +2500,5 @@
 	td_to.appendChild(input_to);
 
-	var forwarded_local_message = document.createElement("INPUT"); //Hidden para indicar se é um forward de uma mensagem local
+	var forwarded_local_message = document.createElement("INPUT"); //Hidden para indicar se ï¿œ um forward de uma mensagem local
 	forwarded_local_message.id = "is_local_forward"+ID;
 	forwarded_local_message.name = "is_local_forward";
@@ -3095,5 +3159,5 @@
 	var tbody = Element('tbody_box');
 	for (var i=0; i<(headers_msgs.length); i++){
-            // passa parâmetro offset
+            // passa parï¿œmetro offset
 		var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
 		if (tr)
@@ -3314,6 +3378,6 @@
 
 		if(isOverLimit) {
-			alert("Esse campo possui muitos endereços ("+_address.length+" destinatários).\r\n"+
-			"Para evitar o travamento do navegador, o botão 'Adicionar Contato' foi desabilitado!");
+			alert("Esse campo possui muitos endereï¿œos ("+_address.length+" destinatï¿œrios).\r\n"+
+			"Para evitar o travamento do navegador, o botï¿œo 'Adicionar Contato' foi desabilitado!");
 		}
 
@@ -3351,9 +3415,31 @@
 		((expresso_offline)?" ":'<span class="message_options_export"><span ' + change_font_color + ' title="'+get_lang("Export")+'" class="message_options" onclick="proxy_mensagens.export_all_messages()">'+get_lang("Export")+'</span></span>') +
 		((expresso_offline)?" ":'<span class="message_options_import"><span ' + change_font_color + ' title="'+get_lang("Import")+'" class="message_options" onclick="import_window()">'+get_lang("Import")+'</span></span>');
-	if(preferences.use_local_messages==1 && !expresso_offline)
+	/*if(preferences.use_local_messages==1 && !expresso_offline)
 		if(proxy_mensagens.is_local_folder(current_folder))
 			span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
 		else
-			span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null)">'+get_lang("Archive")+'</span>';
+			span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null)">'+get_lang("Archive")+'</span>';*/
+    
+            //MAILARCHIVER
+        if(preferences.use_local_messages==1){
+            if(expresso_mail_archive.enabled){
+                //window.alert('Ativo, adicionar no footer');
+                /*TODO: CHECK LOCAL FOLDER TO ADD ARCHIVE OR UNARCHIEVE FOOTER LINK OPERATION*/
+                /*if(proxy_mensagens.is_local_folder(current_folder))
+                    span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
+                  else
+                    span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null,null)">'+get_lang("Archive")+'</span>';
+                */
+               span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null,null)">'+get_lang("Archive")+'</span>';
+            }
+            //else
+                //window.alert('Inativo. sem footer');
+        }
+        //else
+          //  window.alert('Sem a preferencia, nao faz nada');
+    
+    
+    
+    
 	if (use_spam_filter) {
 		if ( current_folder == 'INBOX'+cyrus_delimiter+'Spam' )	{
