Index: sandbox/2.5.1-expresso1/prototype/services/ImapServiceAdapter.php
===================================================================
--- sandbox/2.5.1-expresso1/prototype/services/ImapServiceAdapter.php	(revision 7719)
+++ sandbox/2.5.1-expresso1/prototype/services/ImapServiceAdapter.php	(revision 7912)
@@ -178,5 +178,4 @@
                             $criteria[ $filter[$i][0] ] = array( 'criteria' => $filter[$i][2], 'filter' => $filter[$i][1] );
                         }
-
                         return $this->searchSieveRule($criteria);
 					}
Index: sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js
===================================================================
--- sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js	(revision 7904)
+++ sandbox/2.5.1-expresso1/prototype/modules/attach_message/attach_message.js	(revision 7912)
@@ -728,5 +728,4 @@
                     message['id'] = id;
                     msgs.push( message );
-
                 });
                 return msgs;
@@ -734,24 +733,67 @@
         }
         var search_imap_messages = function(param, folder){
-            var filters = [
-        		[
-        		 	'from',
-        			'*',
-        			param
-        		],       	
-        		[
-            		'OR',
-            		'to',
-            		'*',
-            		param
-            	],
-        		[
-            		'OR',
-            		'subject',
-            		'*',
-            		param
-            	]
-            ];
-
+        	var grid = $("#message_attacher_grid");
+
+        	DataLayer.storage.cache = {};
+        	if( $(".attach-message-search-checkbox:checked").length > 0 ){
+	            var filters = [
+	        		[
+	        		 	'from',
+	        			'*',
+	        			param
+	        		],       	
+	        		[
+	            		'OR',
+	            		'to',
+	            		'*',
+	            		param
+	            	],
+	        		[
+	            		'OR',
+	            		'subject',
+	            		'*',
+	            		param
+	            	],
+	            	[
+	            		'OR',
+	            		'folder',
+	            		'*',
+	            		folder
+	            	],
+	            	[
+	            		'OR',
+	            		'body',
+	            		'*',
+	            		param
+	            	]
+	            ];
+	        }else{
+	        	var filters = [
+	        		[
+	        		 	'from',
+	        			'*',
+	        			param
+	        		],       	
+	        		[
+	            		'OR',
+	            		'to',
+	            		'*',
+	            		param
+	            	],
+	        		[
+	            		'OR',
+	            		'subject',
+	            		'*',
+	            		param
+	            	],
+	            	[
+	            		'OR',
+	            		'folder',
+	            		'*',
+	            		folder
+	            	]
+	            ];
+	        }
+			
             var data = DataLayer.get( 'message', { filter: filters, criteria: { properties: { context: { folder: folder } } } }, true );
             var tmp = [DataLayer.get( 'message', {filter: [ "msgNumber", "IN", data ], criteria: { properties: { context: { folder: folder } } } })];
@@ -759,20 +801,38 @@
             msgs = [];
 
-            $.each(tmp, function(i, msg){
-                flag = msg['flag'];
-                id = msg['msg_number'];
-                var message = {};
-              
-                message['msg_number'] = id;
-                message['flags'] = flag;
-                message['from.name'] = msg['from'];
-                message['subject'] = msg['subject'];
-                message['timestamp'] = msg['timestamp'];
-                message['size'] = msg['size'];
-                message['id'] = id;
-                msgs.push( message );
-
-            });
-
+            if(tmp[0].rows){
+            	$.each(tmp[0].rows, function(i, msg){	            	
+	                flag = msg['flags'];
+	                id = msg['msg_number'];
+	                var message = {};
+	              
+	                message['msg_number'] = id;
+	                message['flags'] = flag;
+	                message['to'] = {
+	                	name: msg['toaddress2'],
+	                	email: msg['toaddress2']
+	                };
+
+	                if(msg['from'] != undefined &&  msg['header']['from'] != undefined){
+		                message['from'] = {
+		                	'email' : msg['from']['email'],
+		                	'name' : msg['header']['from']['name']
+		                }
+		            }else{
+		            	message['from'] = {
+		                	'email' : '',
+		                	'name' : 'Rascunho'
+		                }
+		            }
+	                //message['from']['name'] = msg['from']['name'];
+	                message['subject'] = msg['subject'] ? msg['subject'] : "(sem assunto)";
+	                message['timestamp'] = parseInt(msg['timestamp']);
+	                message['size'] = msg['size'];
+	                message['id'] = id;
+	                msgs.push( message );
+           		});
+            }else{
+            	grid.jqGrid("clearGridData", true);
+            }
             return msgs;
         }
@@ -781,11 +841,12 @@
             var grid = $("#message_attacher_grid");
             var folder = $("#foldertree li span.selected").parent().attr("id");
+            
+            if(param == ""){
+                $('#foldertree [id="'+folder+'"]').trigger("click");
+                return;
+            }
 
             if(folder.indexOf("local_messages_") == 0){
                 // Pesquisa pelas mensagens locais...
-                if(param == ""){
-                    $("#foldertree #"+folder).trigger("click");
-                    return;
-                }
                 msgs = search_local_messsages(param, folder);
             } else {
@@ -797,6 +858,6 @@
             grid.jqGrid("clearGridData", true);
             grid.jqGrid('setGridParam',{datatype: "local",data: msgs})
-            .trigger("reloadGrid")
-            .jqGrid('setCaption', '<span class="'+child.attr('class')+'">'+child.attr('title')+'</span>');
+            .trigger("reloadGrid");
+            //.jqGrid('setCaption', '<span class="'+child.attr('class')+'">'+child.attr('title')+'</span>');
 		}
 
@@ -807,9 +868,25 @@
 		$("#last_message_attacher_grid_pager").attr("title",title[3]);
 		$("#mailgrid-container .ui-jqgrid-titlebar")
-		.append( DataLayer.render("../prototype/modules/mail/templates/attachment_search.ejs") ).find(".ui-jqgrid-titlebar-close").hide()
+		.append( DataLayer.render("../prototype/modules/attach_message/attachment_search.ejs") ).find(".ui-jqgrid-titlebar-close").hide()
 		.end().find(".attach-message-search-input").Watermark("Pesquisa...").keydown(function(e){
 			if($.ui.keyCode.ENTER == e.keyCode){
 				search_messages($(this).val());
 			}
+		});
+		$("#attach-message-search").button({
+			text: false,
+			icons: {
+				primary: "ui-icon-search"
+			}
+		}).next().button({
+			text: false,
+			icons: {
+				primary: "ui-icon-script"
+			}
+		});
+		$("#attach-message-search").parent().buttonset();
+
+		$("#attach-message-search").click(function(){
+			search_messages($(this).parents(".attach-message-search-div:first").find(".attach-message-search-input").val());
 		});
 	}
Index: sandbox/2.5.1-expresso1/prototype/modules/attach_message/attachment_search.ejs
===================================================================
--- sandbox/2.5.1-expresso1/prototype/modules/attach_message/attachment_search.ejs	(revision 7912)
+++ sandbox/2.5.1-expresso1/prototype/modules/attach_message/attachment_search.ejs	(revision 7912)
@@ -0,0 +1,18 @@
+<div class="attach-message-search-div" style="position: absolute;right: 0px;top: 50%;margin: -10px 0 0 0;padding: 1px;height: 18px;">
+	<fieldset class="attach-message-search-field ui-corner-all" style="border: 0;margin: -10px 0 0 0;padding: 1px;height: 18px;position: relative;top: 50%;">
+		<!--<span class="ui-icon ui-icon-search" style="position: absolute;right: 6px;top: 10%;"></span>
+		<input class="attach-message-search-checkbox" title="Selecione para buscar pelo conteudo da mensagem" type="checkbox" style="position: absolute;right: 20px;top: 10%;"> -->
+		<input class="attach-message-search-input" type="text" style="border-radius: 5px;border-right-color: white;border-right: 60px solid white;border-bottom: 1px solid white;border-top: 1px solid white;position: absolute;right: 9px;width: 170px;">
+		<span style="position: absolute; right: 5px; 
+		<% if(is_ie){ %>
+			top: 1px;">
+		<% }else if(is_webkit){ %>	
+			top: 4px;">
+		<% }else{ %>	
+			top: 2px;">
+		<% } %>	
+			<button id="attach-message-search" title="Buscar mensagens" class="ui-icon ui-icon-search" style="position: absolute; right: 28px;"></button>
+    		<input type="checkbox" id="attach-message-search-options" class="attach-message-search-checkbox"><label style="width: 26px; height: 14px;" for="attach-message-search-options">Considerar o corpo da mensagem como filtro na busca</label>
+    	</span>
+	</fieldset>
+</div>
Index: sandbox/2.5.1-expresso1/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- sandbox/2.5.1-expresso1/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 7888)
+++ sandbox/2.5.1-expresso1/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 7912)
@@ -5237,8 +5237,8 @@
 	function searchSieveRule( $params )
 	{
-		
-		$imap = $this->open_mbox( 'INBOX' );
+
+		$imap = $this->open_mbox( $params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX' );
 		$msgs = imap_sort( $imap , SORTDATE , 0 , SE_UID);
-		
+	
 		$rr = array();
 	
@@ -5307,6 +5307,6 @@
 			if(isset($params['body']))
 			{			
-				$this->mbox = $this->open_mbox( 'INBOX' );
-				$b = $this->get_body_msg( $v , 'INBOX' );
+				$this->mbox = $this->open_mbox( $params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX' );
+				$b = $this->get_body_msg( $v , $params['folder']['criteria'] ? $params['folder']['criteria'] : 'INBOX' );
 				
 				if( $this->filterCheck( $b['body'] , $params['body']['criteria'] , $params['body']['filter'] ))
