Email address parsing
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($_); return undef unless scalar(@addresses) > 0; return $addresses->name; $$;