[Dovecot] Auto create folder(s)

"Fábio M. Catunda" catunda at contactnet.com.br
Thu Sep 27 01:01:15 EEST 2007


Bill Landry wrote:
> Fábio M. Catunda wrote:
>   
>> Charles Marcus escreveu:
>>     
>>> On 9/26/2007, Bill Landry (bill at inetmsg.com) wrote:
>>>       
>>>>> But with maildrop you still run the process of creating/checking on
>>>>> every delivery, same thing as dovecot, right?
>>>>>           
>>>> Correct. If the folder does not exist, maildrop will create it on
>>>> first delivery. If the end user deletes the folder, maildrop will
>>>> recreate the folder on the next message delivery to that account.
>>>>         
>>> Could it could be written to simply create the folder if the target
>>> folder doesn't exist (ie, if the initial save fails due to
>>> non-existent folder)? Then there would be no performance hit...
>>>
>>>       
>> There will be a performance hit couse you have to check if the folder
>> exists or not.
>> With maildrop its pretty easy to do that, but you will have an extra
>> access to your HD on every message delivery.
>> Maildrop can run shell commands it the user that runs it have a valid
>> shell (Debian-exim do NOT have a valid shell, I created another user
>> just to make the delivery), so, you can run something like
>>
>> /^Envelope-to:.*/
>> getaddr($MATCH) =~ /^.*/;
>> DEST = $MATCH
>> USER = `/bin/echo $DEST | /usr/bin/cut -f1 -d'@'`
>> DOMAIN = `/bin/echo $DEST | /usr/bin/cut -f2 -d'@'`
>>
>> DOEXIST=`[ -d /var/mail/$DOMAIN/$USER/Maildir ]; echo $?`
>>
>> if ($DOEXIST == 1){
>>    <RUN SOMETHING HERE TO CREATE MAILDIRS>
>> }
>>     
>
> I simply use this in the maildroprc:
>
> # Auto-Create new mailbox
> if (/^Received:/)
> {
>         `test -d $DEFAULT`
>         if ($RETURNCODE == 1)
>         {
>                 `/usr/local/bin/maildirmake $DEFAULT`
>                 `/usr/local/bin/maildirmake -f Spam $DEFAULT`
>                 `echo "Spam" >> $DEFAULT/subscriptions`
>         }
> }
>
> # Deliver to Inbox or Spam box (create spam box if it does not exist)
> if (/^X-Spam-Flag: YES/:h)
> {
>         `test -d $DEFAULT/.Spam`
>         if ($RETURNCODE == 1)
>         {
>                 `/usr/local/bin/maildirmake -f Spam $DEFAULT`
>                 `echo "Spam" >> $DEFAULT/subscriptions`
>         }
>         exception {
>                 to "$DEFAULT/.Spam"
>         }
>         # if all else fails, do regular delivery
>         exception {
>                 to "$DEFAULT"
>         }
> }
> else
> {
>         exception {
>                 to "$DEFAULT"
>         }
> }
>
> Maildrop automatically creates the maildir for new accounts if a valid e-mail
> address is found and the account has not already been created when the first
> message arrives for the new user.
>
> It also tests that the spam folder exists whenever a message is received that
> contains the spam x-header, so that the folder can be created prior to the spam
> message delivery (this test is very fast and does not seem to hinder performance
> since maildrop written in C++ and is highly optimized to support these kinds of
> functions).
>
> Bill
>
>   
I didnt know that maildrop generates a variable called RETURNCODE when 
you run some external commands, thanks for the advise!

Anyway, even if maildrop is written in C++, it have to start a bash and 
run the external command. It's realy fast, but if you take a heavy 
loaded system it might put you in a lot problems!

There are some tools to test a mailsystem, it generates a lot of 
messages and keep counting the mailqueue, in such situation you willl 
see hundreds of bashs started running what you have in maildroprc.

The case here is not courier-imap, but in this case maildirmake it not 
enought to create a user maildir, you have to install the quota file 
too, so, maildrop might do the wrong job in such situation.

I'm new with dovecot, still dont know how to use quota, but if you need 
to read some aditional information from some db at the time of create 
the maildir, you probably will have troubles with maildrop too!

I realy prefer to create mailboxes at the time of the account creation.

[]'s, FMC!

!DSPAM:46fad644211981503319954!



More information about the dovecot mailing list