Re: [Exim] Delivering mails into a IMAPD-mailbox

Top Page
Delete this message
Reply to this message
Author: Jan Schreckenbach
Date:  
To: exim-users
Subject: Re: [Exim] Delivering mails into a IMAPD-mailbox
Bernard Stern wrote:
>
> On Thu, 16 Nov 2000 13:40:58 +0100 "Oliver Fischer" wrote:
>
> > Hi,
>
> > I would like to deliver the mails of some users via imapd with
> > this filter
>
> > local_delivery:
> >        driver          = pipe
> >        command         = "/usr/local/cyrus/bin/deliver
> > ${local_part}"
> >        prefix          = ""
> >        user            = cyrus
> >        return_path_add
> >        return_output
> >        envelope_to_add
> >        delivery_date_add

>

[snipp]
> > How could I do this. I would like to do this by managing a file
> > with the names of all users which are imap-users....
>
> I'm doing this with a lsearch on a file. Since I have not many
> users it's ok. You could 'upgrade' to cdb search if needed.
>
> This is my director for shell users (in which IMAP users
> are a subset):
>
> shell_users:
> driver = aliasfile
> require_files = EXIM_CFG/shell-users
> file = EXIM_CFG/shell-users
> search_type = lsearch
> no_rewrite
> transport = shell_users_delivery
>
> And the transport:
>
> shell_users_delivery:
> driver = pipe
> use_shell
> command = ${lookup{${lc:$local_part}}lsearch{EXIM_CFG/shell-users}{$value}fail}
> return_output
> prefix = ""
> from_hack
> user = exim
> group = mail
>
> The file looks like:
>
> user-a: /usr/local/bin/deliver user-a
> user-b: /usr/local/bin/deliver user-b
> #
> some-local-part: /path/to/some/command -with -options

Hi,

sounds very complicated. I wrote two Q&D scripts to fetch
the local_parts from the Cyrus imapd via Perl. The first
uses the IMAP-Admin package from CPAN:

---
use IMAP::Admin;
use strict;

sub imapusers {
        my $server      = shift;
        my $port        = shift;
        my $user        = shift;
        my $pass        = shift;
        my $mailbox     = Exim::expand_string('$local_part');


        if ( $server && $port && $user && $pass ) {
                my ($imap, @list);


                $imap = IMAP::Admin->new( 'Server'    => $server,
                                             'Port'      => $port,
                                             'Separator' => ".",
                                             'Login'     => $user,
                                             'Password'  => $pass
                                        );


                @list = $imap->list("user.$mailbox");
                $list[0] =~ s/user\.//g;


                $imap->close;
                return $list[0] || "";
        }
        else {
                die "missing parameter\n";
        }
}
---


The second uses the perl Interface that comes with Cyrus 2.0:
---
use Cyrus::IMAP::Admin;
use strict;

sub imapusers {
        my $server      = shift;
        my $mech        = shift;
        my $user        = shift;
        my $pass        = shift;
        my $mailbox     = Exim::expand_string('$local_part');


        if ( $server && $mech && $user && $pass ) {
                my ($imap, $lasterror, @list);


                my $imap = Cyrus::IMAP::Admin->new($server);
                $imap->authenticate( -user      => $user,
                                     -mechanism => $mech,
                                     -password  => $pass
                ) or die "cyradm: cannot authenticate to server with
$mech as $user\n";
                @list = $imap->list("user.","$mailbox");
                if ( defined($lasterror = $imap->error()) ) {
                        die "$lasterror\n";
                }
                my $list = ${$list[0]}[0];
                $list =~ s/user\.//g;


                return $list || "";
        }
        else {
                die "missing parameter\n";
        }
}
---


My transport is like:
cyrus_pipe:
    driver            = pipe
    bsmtp             = none
    command           = /usr/cyrus/bin/deliver -q -e ${local_part} -a
${local_part}
...


My director is like:
cyrus_director:
    driver        = localuser
    transport     = cyrus_pipe
#   local_parts   = lsearch;/etc/exim/imapuser
    local_parts   =
${perl{imapusers}{localhost}{143}{admin}{admin_pass}}


For the latter case of script replace 143 (the port) with login (the
mechanism
used to connect to the cyrus imapd).

Maybe the Perl code could be improved. You need to load the Perl code
with
something like
perl_startup = do '/etc/exim/imapusers.pl'

cu,
Jan

--
Jan Schreckenbach                      email: Jan.Schreckenbach@???
SAP AG Walldorf/Baden, Germany         Phone: +49 6227  7-47474
LinuxLab                               Fax  : +49 6227 78-31414


SAP LinuxLab support address: linux@???