[Vmail-discuss] vmail-sql and Maildir

Manuel Giorgini Manuel Giorgini <giorgini at interlogica.net>
Fri, 6 Feb 2004 11:53:52 +0100


[2004-02-06 10:07:06] Donovan Craig,

>> does anyone know about any occurrence of Maildir-supporting VE-scripts?

DC> Deletion scripts would be great, but for creation, we use the following
DC> options in the vmail Exim transport:

DC> maildir_format
DC> create_directory

DC> The maildir is then automatically created as soon as mail hits the box.

Yes, I am aware of that (and that's a nifty feature, let me tell you!). Yet
I am a bit disappointed (well... our customers are disappointed) of the
fact that courier-imapd returns an authentication error even when the
mailbox is present/just created, just because it can't chdir to the user's
maildir.

>> I extended VE-popbox to create and delete Maildirs, but my perl is kind of
>> rough, and I wondered whether there is some sort of 'official' or
>> 'preferred' version.

DC> Again, this would be great for deletion..

Well I have no problem in sharing my own changes, yet I insist on the fact
that they are to be considered _very_ rough and _very_ simple, and I would
appreciate some refining by people more proficient in perl (and in Maildir
structure, all right) than I am. In particular I had very little will to
cycle properly in order to delete all the directories, so I went straight
for a much less secure approach...

However, here's what I did.
In VE-popbox, anywhere in the if-elsif-elsif structure, add this:


} elsif ($mode eq 'addmd') {
        $dd = $dbh->quote($domain);
        $foo = $dbh->selectall_arrayref("SELECT path, unix_user FROM domain WHERE domain_name = $dd");
        if (@{$foo} == 0) { Error("domain `$domain' does not exist"); }
        $path = $foo->[0]->[0];
        $user = $foo->[0][1];
        $ll = $dbh->quote($local);
        $foo = $dbh->selectall_arrayref("SELECT * FROM forwarder WHERE domain_name = $dd AND local_part = $ll");
        if (@{$foo} > 0) { Error("forwarder already exists for `$local\@$domain'"); }
        $foo = $dbh->selectall_arrayref("SELECT * FROM popbox WHERE domain_name = $dd AND local_part = $ll");
        if (@{$foo} > 0) { Error("POP3 maildrop already exists for `$local\@$domain'"); }
        $file = "$local";
        print "Will add Maildir maildrop for `$local\@$domain' under directory `$file'\n";
        if (-e "$path/$file") { Error("maildrop `$file' already exists"); }
        $ff = $dbh->quote($file);
        $pp = $dbh->quote("X");
        $stmt = "INSERT INTO popbox (domain_name, local_part, password_hash, mbox_name) VALUES ($dd, $ll, $pp, $ff)";
        $dbh->do($stmt) or Error("could not insert popbox record", $dbh->errstr());
        mkdir("$path/$file",0700);
        mkdir("$path/$file/Maildir",0700);
        mkdir("$path/$file/Maildir/cur",0700);
        mkdir("$path/$file/Maildir/new",0700);
        mkdir("$path/$file/Maildir/tmp",0700);
        print "Done\n";
} elsif ($mode eq 'removemd') {
        $dd = $dbh->quote($domain);
        $foo = $dbh->selectall_arrayref("SELECT path FROM domain WHERE domain_name = $dd");
        if (@{$foo} == 0) { Error("domain `$domain' does not exist"); }
        $path = $foo->[0]->[0];
        $ll = $dbh->quote($local);
        $foo = $dbh->selectall_arrayref("SELECT mbox_name FROM popbox WHERE domain_name = $dd AND local_part = $ll");
        if (@{$foo} == 0) { Error("POP3 maildrop does not exist for `$local\@$domain'"); }
        $file = $foo->[0]->[0];
        print "Will remove Maildir for `$local\@$domain'\n";
        if (-e "$path/$file") { system("rm -rf $path/$file"); }
        $stmt = "DELETE FROM popbox WHERE domain_name = $dd AND local_part = $ll\n";
        $dbh->do($stmt) or Error("could not delete row from popbox ", $dbh->errstr());
        print "Done.\n";






        
Cordialità / Best regards / Gxis la
------------------------------------------------------------------------
Manuel Giorgini <giorgini@interlogica.net>, Programmatore
INTERLOGICA e-business solutions -  http://www.interlogica.net
Via De Amicis, 2 - IT 30172 Mestre VE - Italia - Unione Europea
Tel +39 041 961392 - Fax +39 041 954201
------------------------------------------------------------------------