Es imprescindible que los buzones de correo existan antes de su uso. Por este motivo, cada vez que se añada un usuario de correo, se ha de crear su directorio HOME y el buzón de correo asociado, así como el archivo de recursos para procmail.
Para automatizar esta operación se ha creado el siguiente script:
#!/bin/sh
#
# Copyright (C) 2004 Sergio González González <sergio.gonzalez@hispalinux.es>
#
# Depends on:
# - ldapsearch
# - maildirmake ( from courier )
#
# Based on http://jeroen.protheus.com/postfix-courier-ldap-howto.html
# (c) J.Vriesman
#
# and
#
# Based on http://bulma.net/body.phtml?nIdNoticia=2013
# (c) Jesús Roncero Franco
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Password to bind to ldap server
systempass="1"
# Bind dn
binddn="ou=postfix,dc=gsr,dc=pt"
# Acount leave
accountleave="ou=people,dc=gsr,dc=pt"
# ldap host
ldaphost="gsr.pt"
# Maildir name
maildir="Maildir/"
# Mail users home name
homedir="/home/vmail"
# Mail user's group
group="vmail"
usernames=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
-b "$accountleave" "(!(quota=-1))" uid \
| grep "^[^#]" | grep "^[^dn]" | grep uid | awk '{ print $2 }'`
# create personal mailfolders
for username in $usernames
do
homedirectory=`ldapsearch -h $ldaphost -x -w $systempass -D "$binddn" \
-b "$accountleave" "(uid=$username)" homeDirectory \
| grep "^[^#]" | grep homeDirectory | grep "$homedir" \
| awk '{ print $2 }'`
if [ ! -d $homedirectory/$maildir ] && [ ! -z $homedirectory ]
then
mkdir -p -m 2750 $homedirectory
maildirmake $homedirectory/$maildir
if [ ! -f $homedirectory/.procmailrc ]
then
echo -ne "PATH=/usr/bin:/bin:/usr/local/bin:.\nMAILDIR=\$HOME/Maildir\n\
DEFAULT=\$MAILDIR/" > $homedirectory/.procmailrc
fi
chown -R $username.$group $homedirectory
fi
done |
El script anterior creará el HOME de los usuarios de correo que no lo tuviesen ya creado, el directorio Maildir en el que se almacenarán los correos enviados al usuario y el archivo .procmailrc, que se encargará de decirle a procmail como se ha de comportar.
![]() | Nota |
|---|---|
Para la correcta ejecución del script se necesita la herramienta maildirmake. Esta herramienta, utilizada para crear un directorio tipo Maildir, viene junto al paquete courier-base. | |
![]() | Importante |
|---|---|
Recuerde que cada vez que se añada un usuario al sistema, se ha de ejecutar este script como root. | |