package Fripost::Schema; =head1 NAME Schema.pm - =cut =head1 DESCRIPTION Schema.pm abstracts the LDAP schema definition and provides methods to add, list or delete virtual domains, users, aliases or lists. =cut use 5.010_000; use strict; use warnings; use utf8; use parent 'Fripost::Schema::Auth'; use Net::LDAP; use Authen::SASL; use Fripost::Schema::Util qw/canonical_dn ldap_explode_dn split_addr/; use Fripost::Schema::Domain; use Fripost::Schema::User; use Fripost::Schema::Alias; use Fripost::Schema::List; use Fripost::Schema::Local; use Net::IDN::Encode 'email_to_ascii'; =head1 METHODS =over 4 =item B Bless the object to C, to access domain-specific methods. =cut sub domain { bless shift, 'Fripost::Schema::Domain'; } =item B Bless the object to C, to access user-specific methods. =cut sub user { bless shift, 'Fripost::Schema::User'; } =item B Bless the object to C, to access alias-specific methods. =cut sub alias { bless shift, 'Fripost::Schema::Alias'; } =item B Bless the object to C, to access list-specific methods. =cut sub list { bless shift, 'Fripost::Schema::List'; } =item B Bless the object to C, to access local-specific (users, aliases and lists) methods. =cut sub local { bless shift, 'Fripost::Schema::Local'; } =back =head1 AUTHOR Guilhem Moulin C<< >> =head1 COPYRIGHT Copyright 2012,2013 Guilhem Moulin. =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as perl itself. =cut sub _dn2fvu { my $self = shift; my $dn = ldap_explode_dn(shift); return '@'. $dn->[0]->{fvd} if exists $dn->[0]->{fvd}; return $dn->[0]->{fvu} .'@'. $dn->[1]->{fvd}; } sub _fvu2dn { my $self = shift; my $email = shift; my ($l,$d) = split_addr($email); my @dn = ({fvd => $d}, @{$self->suffix}); unshift @dn, {fvu => $l} if defined $l and $l ne ''; canonical_dn( @dn ); } 1; __END__