diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index c7a9f92f565e622bda66a2365bde698222953f11..0109577e3b013b6bf330fa9299c8f35cef958b39 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -331,8 +331,47 @@ module SGXbwmsgsv2 } end - def self.validate_num(num) - EMPromise.resolve(num.to_s).then { |num_dest| + def self.validate_num(m) + # if sent to SGX domain use https://wiki.soprani.ca/SGX/GroupMMS + if m.to == ARGV[0] + an = m.children.find { |v| v.element_name == "addresses" + } + if not an + return EMPromise.reject([:cancel, + 'item-not-found']) + end + puts "ADRXEP: found an addresses node - iterate addrs.." + + nums = [] + an.children.each do |e| + num = '' + type = '' + e.attributes.each do |c| + if c[0] == 'type' + if c[1] != 'to' + # TODO: error + end + type = c[1].to_s + elsif c[0] == 'uri' + if !c[1].to_s.start_with? 'sms:' + # TODO: error + end + num = c[1].to_s[4..-1] + # TODO: confirm num validates + else + # TODO: error - unexpected name + end + end + if num.empty? or type.empty? + # TODO: error + end + nums << num + end + return nums + end + + # if not sent to SGX domain, then assume destination is in 'to' + EMPromise.resolve(m.to.node.to_s).then { |num_dest| if num_dest =~ /\A\+?[0-9]+(?:;.*)?\Z/ next num_dest if num_dest[0] == '+' shortcode = extract_shortcode(num_dest) @@ -384,7 +423,7 @@ module SGXbwmsgsv2 message :body do |m| EMPromise.all([ - validate_num(m.to.node), + validate_num(m), fetch_catapult_cred_for(m.from) ]).then { |(num_dest, creds)| jid_key = "catapult_jid-#{num_dest}"