[Rt-commit] r6762 - in rt/branches/3.7-EXPERIMENTAL: .

ruz at bestpractical.com ruz at bestpractical.com
Thu Jan 18 10:52:21 EST 2007


Author: ruz
Date: Thu Jan 18 10:52:20 2007
New Revision: 6762

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm

Log:
 r4382 at cubic-pc:  cubic | 2007-01-18 04:31:31 +0300
 * add support for Mail::Address objects into RT::User->LoadOrCreateByEmail


Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/User_Overlay.pm	Thu Jan 18 10:52:20 2007
@@ -581,50 +581,45 @@
     my $self = shift;
     my $email = shift;
 
-        my ($val, $message);
-
-	my ( $Address, $Name ) =
-	RT::Interface::Email::ParseAddressFromHeader($email);
-	$email = $Address;
-
-        $self->LoadByEmail($email);
-        $message = $self->loc('User loaded');
-        unless ($self->Id) {
-		$self->Load($email);
-	}
-	unless($self->Id) {
-            ( $val, $message ) = $self->Create(
-                Name => $email,
-                EmailAddress => $email,
-                RealName     => $Name,
-                Privileged   => 0,
-                Comments     => 'Autocreated when added as a watcher');
-            unless ($val) {
-                # Deal with the race condition of two account creations at once
-                $self->LoadByEmail($email);
-                unless ($self->Id) {
-                    sleep 5;
-                    $self->LoadByEmail($email);
-                }
-                if ($self->Id) {
-                    $RT::Logger->error("Recovered from creation failure due to race condition");
-                    $message = $self->loc("User loaded");
-                }
-                else {
-                    $RT::Logger->crit("Failed to create user ".$email .": " .$message);
-                }
+    my ($message, $name);
+    if ( UNIVERSAL::isa( $email => 'Mail::Address' ) ) {
+        ($email, $name) = ($email->address, $email->phrase);
+    } else {
+	    ($email, $name) = RT::Interface::Email::ParseAddressFromHeader( $email );
+    }
+
+    $self->LoadByEmail( $email );
+	$self->Load( $email ) unless $self->Id;
+    $message = $self->loc('User loaded');
+
+	unless( $self->Id ) {
+        my $val;
+        ($val, $message) = $self->Create(
+            Name         => $email,
+            EmailAddress => $email,
+            RealName     => $Name,
+            Privileged   => 0,
+            Comments     => 'Autocreated when added as a watcher',
+        );
+        unless ( $val ) {
+            # Deal with the race condition of two account creations at once
+            $self->LoadByEmail( $email );
+            unless ( $self->Id ) {
+                sleep 5;
+                $self->LoadByEmail( $email );
+            }
+            if ( $self->Id ) {
+                $RT::Logger->error("Recovered from creation failure due to race condition");
+                $message = $self->loc("User loaded");
+            }
+            else {
+                $RT::Logger->crit("Failed to create user ". $email .": " .$message);
             }
         }
-
-        if ($self->Id) {
-            return($self->Id, $message);
-        }
-        else {
-            return(0, $message);
-        }
-
-
     }
+    return (0, $message) unless $self->id;
+    return ($self->Id, $message);
+}
 
 # }}}
 


More information about the Rt-commit mailing list