[Dovecot] Maildir/mbox on a per-user basis
Jon Nathan
jon+dated+1102373234.77c0c9 at rupture.net
Tue Nov 30 00:47:12 EET 2004
* Timo Sirainen <tss at iki.fi> [11-28-2004 22:05]:
>
> On 20.11.2004, at 00:15, Jon Nathan wrote:
>
> >default_mail_env can be overridden in userdb for each user. This works
> >with userdbs supporting the "mail" attribute (eg. passwd-file, SQL,
> >LDAP).
> >
> >How exactly does one do this for passwd-file?
>
> user:password:uid:gid:(gecos):home:(shell):flags:mail
>
> It's the mail part there.
Thanks for your help, Timo. I now have this working. In case this is
helpful to anyone, the below script generates a passwd-file from the
system passwd/shadow file (this was on Solaris). It defaults users to
mbox, but assigns them to Maildir if their name is in a file of
maildir users. Fairly simplistic, but it does the job for me.
#!/usr/bin/perl
# generates a passwd-file format file for dovecot imapd.
# this allows users to choose either maildir or mbox
# defaults to mbox; maildir users go into $maildirusers
# passwd-file format:
# user:password:uid:gid:(gecos):home:(shell):flags:mail
# files
$syspass="/etc/passwd";
$sysshad="/etc/shadow";
$dovecotpass="/usr/local/etc/dovecot.passwd";
$maildirusers="/usr/local/etc/dovecot.maildirusers";
umask 0077;
if(-f $dovecotpass){
system("rm $dovecotpass"); # start fresh
}
open(SYSPASS,"<$syspass")||die("Can't open system passwd file $!\n");
while(<SYSPASS>){
chomp($_);
$syspassline=$_;
($user,$pass,$uid,$gid,$gecos,$home,$shell) = split(/:/,$syspassline);
if($uid>100){ # don't run on system accounts
$sysshadline=`grep '^$user:' $sysshad`;
($shaduser,$shadpass)=split(/:/,$sysshadline,3);
$maildiruser=`grep '^$user\$' $maildirusers`;
$flags=""; # for passwd-file format
open(OUT,">>$dovecotpass");
if($maildiruser){
$mailbox="maildir:/home/$user/Maildir";
}else{
$mailbox="mbox:~/mail/:INBOX=/home/$user/mail/inbox";
}
print OUT "$user:$shadpass:$uid:$gid:$gecos:$home:$shell:$flags:$mailbox\n";
close(OUT);
}
}
close(SYSPASS);
#FIN
-Jon
--
Jon Nathan
jon at rupture.net
More information about the dovecot
mailing list