qpsmtpd Wiki


You are here: start » plugins » auth » auth_imap


You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.


You don't have an account yet? Just get one: Register

Forgotten your password? Get a new one: Set new password

#!/usr/bin/perl -w 
=head1 NAME auth_imap - Authenticate to an IMAP server 
=head1 DESCRIPTION This plugin authenticates against any IMAP server you wish (it also supports SSL). You need to specify the IMAP server and port number in the plugins configuration file like so:
auth/auth_imap 143
Without any options, it defaults to connecting to the IMAP server on localhost on port 143. 
Requires the Net::IMAP::Simple::SSL CPAN module.
=head1 AUTHOR Christopher Heschong 
Edits to add SSL support and updated for latest qpsmtpd version  - James Turnbull <james@lovedthanlost.net>
=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. 
sub register { 
my ($self, $qp, @args) = @_;  
if (@args > 0) {
    if ($args[0] =~ /^([\.\w_-]+)$/) {
      $self->{_imap_server} = $1;
    else {
      die "Bad data in imap server: $args[0]";
    $self->{_imap_port} = 143;
    if (@args > 1 and $args[1] =~ /^(\d+)$/) {
      $self->{_imap_port} = $1;
    $self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if
(@args > 2);
  } else {
    die("No IMAP server specified in plugins file.");
 # set any values that are not already
  $self->{_imap_server} ||= "";
  $self->{_imap_port} ||= 143;
$self->register_hook( "auth-plain", "auth_imap" );  
$self->register_hook( "auth-login", "auth_imap" );
sub auth_imap { 
use Net::IMAP::Simple::SSL; 
my ($self, $transaction, $mechanism, $user, $clearPassword, $hashPassword, $ticket) = @_; 
my ($imaphost, $imapport, $imapserver);
# pull values in from config
  $imaphost = $self->{_imap_server};
  $imapport = $self->{_imap_port};
  $imapserver = "$imaphost:$imapport";
$self->log(LOGINFO, "Authentication via IMAP: $user"); 
my $server = Net::IMAP::Simple::SSL->new( 
       $imapserver ) 
          or return ( DENY, "auth_imap - could not connect to server" ); 
       $server->login( $user, $clearPassword ) 
          or return ( DENY, "auth_imap - invalid username or password" ); 
       return ( OK, "auth_imap/$mechanism" );