Difference between revisions of "Email address parsing"

From PostgreSQL wiki
Jump to: navigation, search
(New page: {{SnippetInfo|Function to parse email addresses|depends=Email::Address|lang=PL/Perl}} This function extracts the real name from an email address. With slight variations, other components ...)
 
(category=Library)
 
Line 1: Line 1:
{{SnippetInfo|Function to parse email addresses|depends=Email::Address|lang=PL/Perl}}
+
{{SnippetInfo|Function to parse email addresses|depends=Email::Address|lang=PL/Perl|category=Library}}
 
This function extracts the real name from an email address.  With slight variations, other components such as local part or host name can be extracted.  Relying on a well-tested Perl module makes this function extremely robust, compared to say handcrafted pattern-matching approaches.
 
This function extracts the real name from an email address.  With slight variations, other components such as local part or host name can be extracted.  Relying on a well-tested Perl module makes this function extremely robust, compared to say handcrafted pattern-matching approaches.
 
<source lang="perl">
 
<source lang="perl">

Latest revision as of 13:48, 27 October 2009

Library Snippets

Function to parse email addresses

Works with PostgreSQL

Any version

Written in

PL/Perl

Depends on

Email::Address

This function extracts the real name from an email address. With slight variations, other components such as local part or host name can be extracted. Relying on a well-tested Perl module makes this function extremely robust, compared to say handcrafted pattern-matching approaches.

CREATE OR REPLACE FUNCTION email_name(email text) RETURNS text
LANGUAGE plperlu
AS $$
use Email::Address;

my @addresses = Email::Address->parse($_[0]);
return undef unless scalar(@addresses) > 0;
return $addresses[0]->name;
$$;