[Rt-commit] r9410 - rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/Elements

ruz at bestpractical.com ruz at bestpractical.com
Mon Oct 22 21:02:18 EDT 2007


Author: ruz
Date: Mon Oct 22 21:02:17 2007
New Revision: 9410

Modified:
   rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/Elements/GetEmailFromIP

Log:
* $query->can('...') fails, most probably the module uses AUTOLOAD
* $whois->query may return many parts and often email address is not
  in the first one, so scan all
* make field case insensetive
* localize error messages

Modified: rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/Elements/GetEmailFromIP
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/Elements/GetEmailFromIP	(original)
+++ rtir/branches/2.3-EXPERIMENTAL/html/RTIR/Tools/Elements/GetEmailFromIP	Mon Oct 22 21:02:17 2007
@@ -25,35 +25,41 @@
 <%INIT>
 # $address is passed by reference
 
-# Net::Whois::RIPE does this for its method names
-my $orig_field = $field;
-$field =~ tr/-/_/;
-
 $$address = loc("ADDRESS_UNKNOWN");
 
 use Net::Whois::RIPE;
 my $whois = Net::Whois::RIPE->new( $server, Debug => 1 );
 unless ( $whois ) {
-    $$error = "Unable to connect to whois server '$server'";
+    $$error = loc("Unable to connect to whois server '[_1]'", $server);
     return;
 }
 
-my $query = $whois->query($q);
-unless ( $query ) {
-    $$error = "Unable to connect to whois server '$server'";
+my @query = $whois->query($q);
+unless ( @query ) {
+    $$error = loc("Unable to connect to whois server '[_1]'", $server);
     return;
 }
-unless ($query->can($field)) {
-    $$error = "Whois server response did not include field '$orig_field'";
+
+$field ||= 'notify';
+
+my @res;
+foreach my $query ( @query ) {
+    foreach my $attr ( grep lc $_ eq lc $field, $query->attributes ) {
+        push @res, $query->$attr();
+    }
+}
+unless ( @res ) {
+    $$error = loc("Whois server response did not include field '[_1]'", $field);
+    return;
 }
 
-$$address = $query->$field();
+($$address) = grep defined && length, @res;
 </%INIT>
 
 <%ARGS>
 $server => undef
 $q => undef
 $field => "notify"
-$address => undef
-$error => undef
+$address
+$error
 </%ARGS>


More information about the Rt-commit mailing list