diff options
author | Guilhem Moulin <guilhem.moulin@fripost.org> | 2013-01-18 21:21:17 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@fripost.org> | 2013-01-18 21:21:17 +0100 |
commit | c70ea95c7e2e07cccbff9b7cce26e7bb506d1db6 (patch) | |
tree | d5254e9a7d23be58d3d2a9b81f02b154160b4a28 /lib/Fripost/Schema/Misc.pm | |
parent | bbf7a4b561414d43bedde682c9f7b041c6de88ad (diff) |
Factorized split_addr.
Diffstat (limited to 'lib/Fripost/Schema/Misc.pm')
-rw-r--r-- | lib/Fripost/Schema/Misc.pm | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Fripost/Schema/Misc.pm b/lib/Fripost/Schema/Misc.pm index 114e01b..9ae8cdc 100644 --- a/lib/Fripost/Schema/Misc.pm +++ b/lib/Fripost/Schema/Misc.pm @@ -13,7 +13,8 @@ use utf8; use Exporter 'import'; our @EXPORT_OK = qw /concat get_perms explode - must_attrs email_valid/; + must_attrs email_valid + split_addr/; use Email::Valid; use Net::IDN::Encode; use Encode; @@ -115,6 +116,25 @@ sub email_valid { return $addr; } +sub split_addr { + my $addr = shift; + my %options = @_; + + if (defined $options{'-encoding'}) { + if ($options{'-encoding'} eq 'ascii') { + $addr = Net::IDN::Encode::email_to_ascii($addr); + } + elsif ($options{'-encoding'} eq 'unicode') { + $addr = Net::IDN::Encode::email_to_unicode($addr); + } + else { + die "Unknown encoding: ". $options{'-encoding'}; + } + } + + split /\@/, $addr, 2; +} + =head1 AUTHOR @@ -122,7 +142,7 @@ Guilhem Moulin C<< <guilhem at fripost.org> >> =head1 COPYRIGHT -Copyright 2012 Guilhem Moulin. +Copyright 2012,2013 Guilhem Moulin. =head1 LICENSE |