Index: /sandbox/webservice/restclient/libs/jquery.json-2.3.min.js
===================================================================
--- /sandbox/webservice/restclient/libs/jquery.json-2.3.min.js	(revision 6312)
+++ /sandbox/webservice/restclient/libs/jquery.json-2.3.min.js	(revision 6312)
@@ -0,0 +1,23 @@
+
+(function($){var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};$.toJSON=typeof JSON==='object'&&JSON.stringify?JSON.stringify:function(o){if(o===null){return'null';}
+var type=typeof o;if(type==='undefined'){return undefined;}
+if(type==='number'||type==='boolean'){return''+o;}
+if(type==='string'){return $.quoteString(o);}
+if(type==='object'){if(typeof o.toJSON==='function'){return $.toJSON(o.toJSON());}
+if(o.constructor===Date){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;}
+if(day<10){day='0'+day;}
+if(hours<10){hours='0'+hours;}
+if(minutes<10){minutes='0'+minutes;}
+if(seconds<10){seconds='0'+seconds;}
+if(milli<100){milli='0'+milli;}
+if(milli<10){milli='0'+milli;}
+return'"'+year+'-'+month+'-'+day+'T'+
+hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
+if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i])||'null');}
+return'['+ret.join(',')+']';}
+var name,val,pairs=[];for(var k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
+type=typeof o[k];if(type==='function'||type==='undefined'){continue;}
+val=$.toJSON(o[k]);pairs.push(name+':'+val);}
+return'{'+pairs.join(',')+'}';}};$.evalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){return eval('('+src+')');};$.secureEvalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){var filtered=src.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)){return eval('('+src+')');}else{throw new SyntaxError('Error parsing JSON, source is not valid.');}};$.quoteString=function(string){if(string.match(escapeable)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c;}
+c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
+return'"'+string+'"';};})(jQuery);
Index: /sandbox/webservice/restclient/index.html
===================================================================
--- /sandbox/webservice/restclient/index.html	(revision 6311)
+++ /sandbox/webservice/restclient/index.html	(revision 6312)
@@ -3,4 +3,5 @@
 <HEAD>
 	<script type="text/javascript" src="./libs/jquery.js"></script>
+	<script type="text/javascript" src="./libs/jquery.json-2.3.min.js"></script>
 	<script type="text/javascript" src="./libs/jsonreport.js"></script>
 	<script type="text/javascript" src="./libs/Base64.js"></script>
@@ -70,4 +71,5 @@
 				<TD colspan=2><select id="folder_id" onchange="javascript:jExecute('Mail/Messages')"><option value="INBOX">Selecionar pasta</option></select>
 					<select id="message_id" onchange="javascript:jExecute('getMessage')"><option value="-1">Selecionar mensagem</option></select>
+					<select id="attachment_id" onchange="javascript:jExecute('getAttachment')"><option value="-1">Selecionar Anexo</option></select>
 				</TD>
 			</TR>
@@ -154,4 +156,5 @@
 				$('#folder_id').attr("disabled", true);
 				$('#message_id').attr("disabled", true);
+				$('#attachment_id').attr("disabled", true);
 				$('#sel_contacts').attr("disabled", true);
 				$('#sel_catalog').attr("disabled", true);
@@ -189,15 +192,30 @@
 				$('#bt_rename_folder').attr("disabled", false);
 			}
-			if(a_response.result.messages && a_response.result.messages.length > 1) {
-				$("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>");
-				for (var j in a_response.result.messages){
-					var value = a_response.result.messages[j].msgSubject.length > 20 ?
-						a_response.result.messages[j].msgSubject.substring(0, 20) : a_response.result.messages[j].msgSubject;
-
-					a_response.result.messages[j].msgBodyResume = (a_response.result.messages[j].msgBodyResume);
-					$("#message_id").append("<option value='"+a_response.result.messages[j].msgID+"'>"+
-							value+"</option>");
-				}
+			if(a_response.result.messages) {
 				$('#message_id').attr("disabled", false);
+				if(a_response.result.messages.length == 1) {
+					$("#attachment_id").find('option').remove().end().append("<option value='-1'>Selecionar Anexo</option>");
+					if(a_response.result.messages[0].msgHasAttachments > 0) {
+						$('#attachment_id').attr("disabled", false);
+						var attachments = a_response.result.messages[0].msgAttachments;
+						for (var j in attachments){
+							$("#attachment_id").append("<option value='"+attachments[j].pid+"'>"+attachments[j].name+"</option>");
+						}
+					}
+					else{
+						$('#attachment_id').attr("disabled", true);
+					}
+				}
+				else{
+					$("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>");
+					for (var j in a_response.result.messages){
+						var value = a_response.result.messages[j].msgSubject.length > 20 ?
+							a_response.result.messages[j].msgSubject.substring(0, 20) : a_response.result.messages[j].msgSubject;
+
+						a_response.result.messages[j].msgBodyResume = (a_response.result.messages[j].msgBodyResume);
+						$("#message_id").append("<option value='"+a_response.result.messages[j].msgID+"'>"+
+								value+"</option>");
+					}
+				}
 			}
 
@@ -259,4 +277,9 @@
 		}
 
+
+		if(_action == "getAttachment"){
+			downloadAttachment();
+			return;
+		}
 
 		switch(_action){
@@ -355,4 +378,23 @@
 	}
 
+	function downloadAttachment(){
+		var _server = getCookie('server') ? getCookie('server') : ($('#server').val() ? $('#server').val() : null);		
+		var form = document.createElement("form");		
+		$(form).attr({"action":_server+"Mail/Attachment","method":"POST"});		
+
+		var _params = {
+				auth:  getCookie('auth') != null ? getCookie('auth') : "",
+				folderID:  $('#folder_id').val(),
+				msgID:  $('#message_id').val(),
+				attachmentID: $('#attachment_id').val()
+			};
+
+		$(form).append($(document.createElement('input')).attr(	{"name":"params", "value": $.toJSON(_params)}));
+		var secretThing = $('<iframe id="IFrameToDownload"></iframe>', { css: { 'display': 'none' }});		
+		$('body').append(secretThing);
+		$("#IFrameToDownload").contents().find('body').append(form);		
+		$(form).submit();	
+	}
+
 	function getCookie(c_name)
 	{
@@ -393,9 +435,10 @@
 	$('#bt_logout').attr("disabled", isLoggedIn ? false : true);
 	$('#bt_listFolders').attr("disabled", isLoggedIn ? false : true);
-	$('#folder_id').attr("disabled", isLoggedIn ? false : true);
-	$('#message_id').attr("disabled", isLoggedIn ? false : true);
-	$('#contact_id').attr("disabled", isLoggedIn ? false : true);
-	$('#sel_contacts').attr("disabled", isLoggedIn ? false : true);
-	$('#sel_catalog').attr("disabled", isLoggedIn ? false : true);
+	$('#folder_id').attr("disabled", true);
+	$('#message_id').attr("disabled", true);
+	$('#attachment_id').attr("disabled", true);
+	$('#contact_id').attr("disabled",true);
+	$('#sel_contacts').attr("disabled", true);
+	$('#sel_catalog').attr("disabled", true);
 	$('#search_contacts').attr("disabled", isLoggedIn ? false : true);
 	$('#search_catalog').attr("disabled", isLoggedIn ? false : true);
