Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4955)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5085)
@@ -15,5 +15,6 @@
 		'import_msgs'					=> True,
 		'msgs_to_archive'				=> True,
-                'get_offset_gmt'                                => True
+                'get_offset_gmt'                                => True,
+                'get_msg_flags'                                 => True
 	);
 
@@ -4145,4 +4146,48 @@
         return($this->functions->CalculateDateOffset());
     }
+    
+    //MailArchiver -> get message flags only, invoked at archive operation
+    function get_msg_flags($args){       
+        $msg_folder = $args['folder'];
+        $msg_n = $args['msg_number'];
+        
+        $arr_msg = explode(",", $msg_n);
+       
+        for($i=0; $i<count($arr_msg); $i++){
+                        
+            if(!$this->mbox || !is_resource($this->mbox))
+                $this->mbox = $this->open_mbox($msg_folder);
+        
+            if(!is_resource($this->mbox))
+                return(false);
+                       
+            $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $arr_msg[$i]), 80, 255);
+                
+            if (!is_object($header))
+                return false;
+
+            $taglist[$i]["msgid"] = $msg_n;
+            $taglist[$i]["unseen"] = $header->Unseen;
+            $taglist[$i]["recent"] = $header->Recent;
+            $taglist[$i]["flagged"] = $header->Flagged;
+            $taglist[$i]["draft"] = $header->Draft;
+            $taglist[$i]["answered"] = $header->Answered;
+            $taglist[$i]["deleted"] = $header->Deleted;
+        
+            if($header->Answered =='A' && $header->Draft == 'X')
+                $taglist[$i]['forwarded'] = 'F';
+            else
+                $taglist[$i]['forwarded'] = ' ';
+        
+            if($header->Flagged != "F" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) {
+                $flag = preg_match('/importance *: *(.*)\r/i',
+                        imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number))
+                        ,$importance);
+                $taglist[$i]["flagged"] = $flag==0?false:strtolower($importance[1])=="high"?"F":false;
+            }
+        }
+        
+	return $taglist;        
+    }
 }
 ?>
Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 5073)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/mail_archiver.js	(revision 5085)
@@ -170,5 +170,5 @@
     this.unarchievefolder = null;
     this.unarchievenewfolder = null;
-                          
+    this.taglist = null;                          
 }
 
@@ -351,4 +351,10 @@
 
 MailArchiver.prototype.CreateMessageList = function(msg_list){
+    //window.alert('criando messagelist de arquivamento.');
+    
+//    for(var j=0; j<expresso_mail_archive.messageslisted.length; j++){
+//        window.alert('\nAnswered = ' + expresso_mail_archive.messageslisted[j]["Answered"] + '\nFlagged = ' + expresso_mail_archive.messageslisted[j]["Flagged"] + '\nUnseen = ' + expresso_mail_archive.messageslisted[j]["Unseen"] + '\nDraft = ' + expresso_mail_archive.messageslisted[j]["Draft"]);
+//    }
+    
     if((msg_list != null) && (msg_list != "") && (msg_list != " ")){
         if (expresso_mail_archive.message_list.length == 0){
@@ -360,6 +366,10 @@
                 }
             }
+            
             //Push message list to process the only one
-            else expresso_mail_archive.message_list.push(msg_list);
+            else {
+                //window.alert('testando marcadores default...\n->Answered = ' +expresso_mail_archive.messageslisted[i]["Answered"] + '\n->Unseen = '+expresso_mail_archive.messageslisted[i]["Unseen"]);
+                expresso_mail_archive.message_list.push(msg_list);
+            }
         }
     }
@@ -367,4 +377,5 @@
     else expresso_mail_archive.message_list = new Array();
 }
+
 
 //Archive Operation
@@ -374,6 +385,18 @@
         document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages");
         expresso_mail_archive.CreateMessageList(msgs_id);
+        
+        var tagsHandler = function(data){
+            if(data){
+                var datah = eval(data);
+                //window.alert('unseen = ' +datah["unseen"] + '\nrecent = ' + datah["recent"] + '\nflagged = ' + datah["flagged"] + '\ndraft = ' + datah["draft"] + '\nanswered = ' + datah["answered"] + '\ndeleted = ' + datah["deleted"] + '\nforwarded = ' + datah["forwarded"]);
+                expresso_mail_archive.taglist = datah;
+            }
+        }
 
         if((expresso_mail_archive.message_list.length > 0) && (expresso_mail_archive.message_list[0] != '')){
+
+            //Get all tags from current archiving message
+            var pardata = "&folder=" + url_encode(current_folder)+ "&msg_number="+ expresso_mail_archive.message_list[0];
+            cExecute("$this.imap_functions.get_msg_flags", tagsHandler, pardata);
 
             //Sets the message counter
@@ -386,5 +409,5 @@
                 expresso_mail_archive.folder_destination = destination_folder.substr(6,destination_folder.length);
             else
-                expresso_mail_archive.folder_destination = destination_folder;
+                expresso_mail_archive.folder_destination = destination_folder;          
             
             var fcaption = expresso_mail_archive.folder_destination;
@@ -418,5 +441,5 @@
     }
     catch(e){
-        window.alert('Archive error: %1', e);
+        window.alert(get_lang("Archive error: %1", (e.description)?e.description:e));
     }
 }
@@ -424,4 +447,15 @@
 //Archive callback OK
 MailArchiver.prototype.getArchiveOperationOK = function(status_message){
+    //message must be tagged
+    var arcid = status_message.getReturn().getId();
+    var tlist = expresso_mail_archive.pattern.tagConfig(expresso_mail_archive.taglist, arcid);
+    if(tlist != null){
+        try{
+            ArchiveServices.tagMessages(expresso_mail_archive.tagMessagesOperationOK, expresso_mail_archive.tagMessagesOperationFailure, sessid, tlist);
+        }catch (e){
+            window.alert('ArchiveServices.tagMessages failed at: ' + (e.description)?e.description:e);
+        }
+    }
+    //archivement allready done, update controll data and interface
     expresso_mail_archive.messages_processed++;
     if(expresso_mail_archive.message_list.length > 1){
@@ -674,5 +708,5 @@
             //Store folder data at this format: {folder name, number of messages contained, folder has child nodes, folder id, folder parent id, folder full path}
             //var folderData = new Array(folderlist.getReturn()[i].getName(), folderlist.getReturn()[i].getMessageCount(), folderChild, folderlist.getReturn()[i].getId(), folderlist.getReturn()[i].getParentId(), folderlist.getReturn()[i].getPath());
-            var folderData = {name: folderlist.getReturn()[i].getName(), messages: folderlist.getReturn()[i].getMessageCount(), haschild: folderChild, id: folderlist.getReturn()[i].getId(), parentid: folderlist.getReturn()[i].getParentId(), path: folderlist.getReturn()[i].getPath()};
+            var folderData = {name: folderlist.getReturn()[i].getName(), messages: folderlist.getReturn()[i].getMessageCount(), haschild: folderChild, id: folderlist.getReturn()[i].getId(), parentid: folderlist.getReturn()[i].getParentId(), path: folderlist.getReturn()[i].getPath(), unseen: folderlist.getReturn()[i].getUnseenCount()};
             //window.alert('folder ' + folderData.name + ' tem ' + folderData.messages + ' mensagens.');
             lfolders.push(folderData);
@@ -735,6 +769,12 @@
                 folder_caption = expresso_mail_archive.folders[i]["name"];
             }
-            var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["id"], caption: folder_caption, onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["id"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["id"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]});
-            //var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["name"], caption: folder_caption, onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["name"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["name"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]});
+            
+            if(expresso_mail_archive.folders[i]["unseen"] == "0")           
+                var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["id"], caption: folder_caption, onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["id"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["id"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]});
+            else
+               //var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+data[i].folder_id+"','"+data[i].folder_name+"')", plusSign:data[i].folder_hasChildren}); 
+               var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["id"], caption: folder_caption + '<font style=color:red>&nbsp(</font><span id="dftree_'+expresso_mail_archive.folders[i]["id"]+'_unseen" style=color:red>'+expresso_mail_archive.folders[i]["unseen"]+'</span><font style=color:red>)</font>', onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["id"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["id"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]});    
+         
+         //var n_demo = new dNode({id: localBaseName + expresso_mail_archive.folders[i]["name"], caption: folder_caption, onClick: "change_folder('"+ localBaseName + expresso_mail_archive.folders[i]["name"] +"','"+ localBaseName + expresso_mail_archive.folders[i]["name"]+"', '" + expresso_mail_archive.drawdata.treeName + "')", plusSign:expresso_mail_archive.folders[i]["haschild"]});
             
             //Adjust the id node names
@@ -872,5 +912,5 @@
 //getFolderInfo callback OK
 MailArchiver.prototype.getFolderInfoOperationOK = function(returnService){
-   var folder_info = {id : returnService.getReturn().getId(), name : returnService.getReturn().getName(), parent : returnService.getReturn().getParentId(), numfolders: returnService.getReturn().getFolderCount(), nummessages: returnService.getReturn().getMessageCount()};
+   var folder_info = {id : returnService.getReturn().getId(), name : returnService.getReturn().getName(), parent : returnService.getReturn().getParentId(), numfolders: returnService.getReturn().getFolderCount(), nummessages: returnService.getReturn().getMessageCount(), unseen: returnService.getReturn().getUnseenCount()};
    expresso_mail_archive.folder = folder_info;
 }
@@ -936,4 +976,5 @@
     }
     msglist["num_msgs"] = returnService.getReturn().length;
+    msglist["tot_unseen"] = expresso_mail_archive.folder.unseen;
     //window.alert('print_r\n\n' + print_r(msglist));
     
@@ -986,4 +1027,5 @@
     draw_paging(folder_num_msgs);
     Element("tot_m").innerHTML = folder_num_msgs;
+    Element('new_m').innerHTML = data_to_draw['tot_unseen'] ? '<font color="RED">'+data_to_draw['tot_unseen']+'</font>' : 0;
     //update_menu();
     
Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 5070)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAQueryConfig.js	(revision 5085)
@@ -110,5 +110,5 @@
   //window.alert('setbounds low = ' + low + ' high = ' + high);
   this.lowerIndex = '"@lowerIndex":"'+(parseInt(low)-1)+'",';
-  this.upperIndex = '"@upperIndex":"'+(parseInt(high)-1)+'",';
+  this.upperIndex = '"@upperIndex":"'+(parseInt(high))+'",';
 }
 //From receives a array of structutred data, by the model
Index: sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAExpressoPattern.js
===================================================================
--- sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAExpressoPattern.js	(revision 5049)
+++ sandbox/expressoMail1_2/MailArchiver/2.2/expressoMail1_2/js/MAExpressoPattern.js	(revision 5085)
@@ -71,5 +71,5 @@
 
 MAPattern.prototype.toExpressoAttachmentsHeader = function(data){
-    if((typeof(data) != 'undefined') && (data.length > 0)){
+    if((typeof(data) != 'undefined') && (data.length > 2)){
         var Attdata = eval("(" + data + ")");
         if(typeof(Attdata.attachment) != 'undefined'){                    
@@ -185,5 +185,5 @@
 
 MAPattern.prototype.toExpressoHeader = function(data){   
-    var tplHeader = 'a:16:{'
+    var tplHeader = 'a:26:{'
 +           's:11:"ContentType";'
 +           's:' + data.getContentType().length + ':"' + data.getContentType() + '";'
@@ -382,5 +382,6 @@
     var objTag = eval('(' + tagData + ')');
     var tplHMail = "";
-
+    
+    if(objTag.tag){
     //More than 1 attachment - because length will be 'undefined' if just one exists
     if(objTag.tag.length >= 0){
@@ -423,4 +424,5 @@
             tplHMail += 's:7:"Flagged";s:1:" ";';                      
     }
+    }
     
     //No header to tag
@@ -442,11 +444,8 @@
     var srlData = "";
 
-    //There are attacments, map them
+    //There are attacments, map all them
     if(typeof(objAtt.attachment) != 'undefined'){
         srlData = 's:12:"array_attach";a:' + objAtt.attachment.length + ':{';
         for(var m=0; m<objAtt.attachment.length; m++){
-            //TODO "download" parametr at webservice => var urllink = 'http://10.200.242.186:4333/part/'+objAtt.attachment[m]["@id"]+'/download';
-            //var urllink = 'http://10.200.242.186:4333/part/'+objAtt.attachment[m]["@id"];
-            //var urllink = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/part/'+objAtt.attachment[m]["@id"];
             var urllink = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/part/download/'+objAtt.attachment[m]["@id"];
             srlData += 's:1:"' + m + '";'
@@ -468,6 +467,4 @@
 MAPattern.prototype.toExpressoMailURLExportFile = function(path, file){
     var srlData = 's:15:"url_export_file";';
-    //var urllink = 'http://10.200.242.186:4333/mail/'+path+'/'+file+'/download';
-    //var urllink = 'http://10.200.242.186:4333/mail/'+path+'/'+file;
     var urllink = mail_archive_protocol+'://'+mail_archive_host+':'+mail_archive_port+'/mail/'+path+'/'+file;
     srlData += 's:' + urllink.length + ':"' + urllink + '";'
@@ -578,5 +575,38 @@
 	retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder
 	retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid
- **/    
+ **/ 
+}
+
+MAPattern.prototype.tagConfig = function(taglist, arcidmsg){
+    if(taglist != null){
+        var tagdata = "";
+        
+        //Draft folder, are "draft"
+        if(expresso_mail_archive.folder_destination == 'drafts'){
+            tagdata += '<add value="draft"/>';
+        }
+        
+        //Trash folder, are "deleted""
+        if(expresso_mail_archive.folder_destination == 'trash'){
+            tagdata += '<add value="deleted"/>';
+        }
+        
+        for(var x in taglist[0]){
+            if((taglist[0][x] != '') && (taglist[0][x] != ' ') && (taglist[0][x] != null) && (x != 'msgid'))
+                tagdata += '<add value="'+x+'"/>';
+        }
+
+        if(tagdata != ""){
+        
+            var tobject = '<tag>'
+            +              '<message id="'+arcidmsg+'">'
+            +              tagdata
+            +              '</message>'
+            +             '</tag>';
+            return(tobject);
+        }
+        return(null);
+    }
+    return(null);
 }
 -->
