Created
October 7, 2014 19:49
-
-
Save pbruna/ea84b0d4937ed58a5c61 to your computer and use it in GitHub Desktop.
Un script para obtener los archivos de un usuario de su maletín de Zimbra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'savon' | |
require 'nokogiri' | |
client = Savon.client do | |
wsdl "https://mail.example.com/service/wsdl/ZimbraUserService.wsdl" | |
namespaces("xmlns:urn" => "urn:zimbra", "xmlns:urn1" => "urn:zimbraAccount") | |
env_namespace :soapenv | |
namespace_identifier "urn1" | |
end | |
response = client.call :auth_request, message: {"account" => "pbruna@itlinux.cl", "password" => "---------------"} | |
auth_token = response.to_hash[:auth_response][:auth_token] | |
# Seteamos el auth_token para pedir resultados | |
client.globals[:soap_header]={"urn:context" => {"urn:authToken" => auth_token}} | |
# Cambiamos el Namespace a donde preguntamos urn:zimbraMail | |
client.globals[:namespaces]["xmlns:urn1"]="urn:zimbraMail" | |
# Obtenemos todas las carpetas | |
response = client.call :get_folder_request, :attributes => {:view => "document", :depth => 10} | |
xml_doc = Nokogiri::XML response.to_xml | |
xml_doc.remove_namespaces! | |
folders = xml_doc.xpath("//folder") | |
folders.each do |f| | |
puts f['name'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment