[Rt-commit] r17852 - in rt/3.999/trunk: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Jan 21 04:44:58 EST 2009


Author: sunnavy
Date: Wed Jan 21 04:44:58 2009
New Revision: 17852

Modified:
   rt/3.999/trunk/   (props changed)
   rt/3.999/trunk/lib/RT/EmailParser.pm

Log:
 r18950 at sunnavys-mb:  sunnavy | 2009-01-21 17:26:13 +0800
 merged lib/RT/EmailParser.pm


Modified: rt/3.999/trunk/lib/RT/EmailParser.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/EmailParser.pm	(original)
+++ rt/3.999/trunk/lib/RT/EmailParser.pm	Wed Jan 21 04:44:58 2009
@@ -464,6 +464,52 @@
 
 }
 
+=head2 parse_email_address string
+
+Returns a list of Email::Address objects
+Works around the bug that Email::Address 1.889 and earlier
+doesn't handle local-only email addresses (when users pass
+in just usernames on the RT system in fields that expect
+email Addresses)
+
+We don't handle the case of 
+bob, fred at bestpractical.com 
+because we don't want to fail parsing
+bob, "Falcone, Fred" <fred at bestpractical.com>
+The next release of Email::Address will have a new method
+we can use that removes the bandaid
+
+=cut
+
+sub parse_email_address {
+    my $self           = shift;
+    my $address_string = shift;
+
+    $address_string =~ s/^\s+|\s+$//g;
+
+    my @addresses;
+
+    # if it looks like a username / local only email
+    if ( $address_string !~ /@/ && $address_string =~ /^\w+$/ ) {
+        my $user = RT::Model::User->new( current_user => RT->system_user );
+        my ( $id, $msg ) = $user->load($address_string);
+        if ($id) {
+            push @addresses, Email::Address->new( $user->name, $user->email );
+        }
+        else {
+            Jifty->log->error(
+                "Unable to parse an email address from $address_string: $msg");
+        }
+    }
+    else {
+        @addresses = Email::Address->parse($address_string);
+    }
+
+    return @addresses;
+
+}
+
+
 sub DESTROY {
     my $self = shift;
     File::Path::rmtree( [ @{ $self->{'attachment_dirs'} } ], 0, 1 )


More information about the Rt-commit mailing list