#!/usr/bin/perl -w =head1 NAME auth_imap - Authenticate to an IMAP server =head1 DESCRIPTION This plugin authenticates against any IMAP server you wish. Without any options, it defaults to connecting to the IMAP server on localhost. =head1 AUTHOR Christopher Heschong =head1 COPYRIGHT AND LICENSE Copyright (c) 2004 Christopher Heschong This plugin is licensed under the same terms as the qpsmtpd package itself. Please see the LICENSE file included with qpsmtpd for details. =cut use Qpsmtpd::Constants; use Net::IMAP::Simple; sub register { my ($self, $qp, @args) = @_; %{$self->{_args}} = @args; # Set the default server $self->{_args}->{server} or $self->{_args}->{server} = 'localhost'; $self->register_hook( "auth-plain", "authimap" ); } sub authimap { my ($self, $transaction, $method, $user, $passClear, $passHash, $ticket) = @_; $self->log(LOGINFO, "Authentication via IMAP: $user"); my $server = Net::IMAP::Simple->new( $self->{_args}->{server} ) or return ( DENY, "auth_imap - could not connect to server" ); $server->login( $user, $passClear ) or return ( DENY, "auth_imap - invalid username or password" ); return ( OK, "authimap/$method" ); }