Configuring procmail delivery location
Hi all,
I use procmail as an MDA (as it seems it is automatically chosen by my
sendmail), which by default stores mail in /var/mail/$USER. What I want
to do is to change this to /home/$USER/mbox. The problem is that my
users' home directories are stored in 'group' directories. That is, my
tree structure is like this:
/home/group1/user1
/home/group2/user2
....
I posted in comp.mail.sendmail. The friend who has responded suggested
that I should do some sanity checks as well. Initially he gave me the
following procmailrc:
> :0
> * LOGNAME ?? ^[a-z0-9]+$
> * ? test "/home/$LOGNAME" = "$HOME"
> {
> ORGMAIL="$HOME/mail"
> DEFAULT="$ORGMAIL"
> }
But, because I forgot to mention it, this wasn't taking under
consideration my tree structure (ie. it seems it worked just for
/home/user1 and not /home/group1/user1). So then I got an improved version:
> :0
> * HOME ?? ^^/home/[a-z0-9]+/\/[a-z0-9]+^^
> * LOGNAME ?? ^^[a-z0-9]+^^
> * ? test "$MATCH" = "$LOGNAME"
> {
> ORGMAIL="$HOME/mail"
> DEFAULT="$ORGMAIL"
> }
However this doesn't work. Mail is still stored in the default location
/var/mail/$USER. Obviously there is something wrong with the
conditional, because ommiting it (ie. just using the DEFAULT statement)
seems to give the desired result.
I would appreciate some help.
Thank you
Re: Configuring procmail delivery location
On Mon, 05 Feb 2007 09:05:20 +0200, grpprod wrote:
>
> I would appreciate some help.
And, the folks who want to help you would appreciate the VERBOSE pmlog,
I'll bet.
Re: Configuring procmail delivery location
grpprod wrote:
> Hi all,
> I use procmail as an MDA (as it seems it is automatically chosen by my
> sendmail), which by default stores mail in /var/mail/$USER. What I want
> to do is to change this to /home/$USER/mbox. The problem is that my
> users' home directories are stored in 'group' directories. That is, my
> tree structure is like this:
>
> /home/group1/user1
> /home/group2/user2
> ...
>
> I posted in comp.mail.sendmail. The friend who has responded suggested
> that I should do some sanity checks as well. Initially he gave me the
> following procmailrc:
>
>> :0
>> * LOGNAME ?? ^[a-z0-9]+$
This will test to see that the LOGNAME variable contains one or more
alpha numeric characters. It's a good test to do for a sanity check.
>> * ? test "/home/$LOGNAME" = "$HOME"
This looks like you want to make sure the destination user account
exists by comparing strings. The HOME environment variable in procmail
will contain the home directory of the user name that is contained in
the LOGNAME variable. If your test mismatches, then this procmail recipe
will not execute.
A better way would be to just test that the destination file exists,
then maybe if the file does not exist, create it on the fly.
* ? test -f ${HOME}/mbox
>> {
>> ORGMAIL="$HOME/mail"
>> DEFAULT="$ORGMAIL"
This will have the DEFAULT variable expand to (in your case):
/home/groupname/username/mail
When what you probably want it to expand to is
/home/groupname/username/mbox
or
/home/groupname/username/mail/mbox
or
/home/groupname/username/mail/inbox
So, to fix that:
ORGMAIL=${HOME}/mbox
DEFAULT=${ORGMAIL}
But that could be simplified to just:
DEFAULT=${HOME}/mbox
No need from what I can see to have the extra ORGMAIL variable here.
>> }
>
> But, because I forgot to mention it, this wasn't taking under
> consideration my tree structure (ie. it seems it worked just for
> /home/user1 and not /home/group1/user1). So then I got an improved version:
>
>> :0
>> * HOME ?? ^^/home/[a-z0-9]+/\/[a-z0-9]+^^
>> * LOGNAME ?? ^^[a-z0-9]+^^
>> * ? test "$MATCH" = "$LOGNAME"
These tests are too complicated. It could be simplfied to just test for
the presents of the file and if it exists point the DEFAULT variable to it:
:0
* ? test -f ${HOME}/mbox
{ DEFAULT=${HOME}/mbox }
>> {
>> ORGMAIL="$HOME/mail"
>> DEFAULT="$ORGMAIL"
>> }
>
> However this doesn't work. Mail is still stored in the default location
> /var/mail/$USER. Obviously there is something wrong with the
> conditional, because ommiting it (ie. just using the DEFAULT statement)
> seems to give the desired result.
>
> I would appreciate some help.
> Thank you
This is how I would do this:
(Note: /etc/procmailrc normally runs with root privileges, so be careful)
This procedure was tested on a fedora linux system.
----File: /etc/procmailrc----
ALTDELIVERY=no
# Test for the presents of ${HOME}/mbox
# if found, set the default delivery for that user
# to point at that file.
:0
* ? test -f ${HOME}/mbox
{
DEFAULT=${HOME}/mbox
ALTDELIVERY=yes
}
# Test for the presents of ${HOME}/mail/inbox
# if found, set the default delivery for that user
# to point at that file instead.
:0
* ? test -f ${HOME}/mail/inbox
{
DEFAULT=${HOME}/mail/inbox
ALTDELIVERY=yes
}
# If ALTDELIVERY contains yes, then make sure the file
# has the correct ownerships and permissions set
:0
* ALTDELIVERY ?? ^yes$
{
# Set the correct user and group ownerships on the default delivery
# file. Also set the correct permissions on the file.
# Note the backticks here which launch an embedded shell script.
LOCALBUFFER=`chown ${LOGNAME}.mail ${DEFAULT} ; chmod 660 ${DEFAULT}`
}
# If the ${HOME}/mbox or ${HOME}/mail/inbox files do not exist then
# do nothing. DEFAULT will remain /var/mail/${LOGNAME}
----end of file----
Hope this helps.
--
Regards
Garen
Re: Configuring procmail delivery location
> This is how I would do this:
Thank you for your detailed explanation. However, for some strange
reason, it still doesn't work! Mail is still stored in /var/mail. Is
there a way to produce some debug log with procmail to see what is
happening?
The only procmailrc that seems to work so far is the following:
--- /etc/procmailrc
DEFAULT=$HOME/mbox
---EOF /etc/procmailrc