Resolve recipent"s real user name from alias

Resolve recipent"s real user name from alias

am 18.01.2007 23:22:45 von Pet Farrari

Hi,

With using cyrus, procmail and formail for mail deliver, I have a
problem in dealing with email alias.

eg.

Let s say the email server received an incoming email with alias user
name (d.david) in the To: field, but its imap folder name is a real user
name (david). If the email is a Spam, I want to use cyrus deliver to
deliver the email to his imap folder david/Spam. But since the incoming
email is d.david, I don't know how to resolve this alias (d.david) to
the real name (david). I have this alias to real name mapping in
/etc/postfix/alias file, and in the database as well. If I don't care to
put this email in the specific folder Spam, I don't need to use cyrus
deliver , then I won't have the problem.

Here is the content of the procmail.rc file:

SHELL=/bin/sh
DROPPRIVS=yes
LINEBUF=32768
SENDMAILFLAGS="-oi"
LOGFILE="/var/log/spamkill/spamkill.log"
SPAMC="/usr/local/bin/spamc"
DELIVER=/usr/local/cyrus/bin/deliver

FROM="<$1>"
TO=$2
SHIFT=1


:0f
|$SPAMC -f -U /var/run/spamd.sock

:0
* ^X-Spam-Level: \*\*\*\*\*
{
TO_FIELD=`/usr/local/bin/formail -zxTo:`
REC_FIELD=`/usr/local/bin/formail -zxX-Recipient:`
USER=`echo $TO_FIELD | cut -d "@" -f1`
DOMAIN=`echo $TO_FIELD | cut -d "@" -f2`

# Debug statement. Comment out these Debug log lines later.
LOG="[$$]$_: Debug: TO_FIELD=$TO_FIELD${NL}\n"
LOG="[$$]$_: Debug: TO=$TO${NL}\n"
LOG="[$$]$_: Debug: USER=$USER${NL}\n"
LOG="[$$]$_: Debug: DOMAIN=$DOMAIN${NL}\n"

#OLDRECIPIENTS=|echo "$@"
LOG="[$$]$_: Debug: OLDRECIPIENTS=${REC_FIELD}${NL}"

# SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"

# File: procmail.global

# Make a backup copy of all incoming mail (comment the next entry
# out once you're finished testing procmail integration)
#:0 ic
#| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.backup

# Execute CYRUSUSER's personal rules
#INCLUDERC=/var/imap/procmail/user/procmail.$CYRUSUSER

# Example recipes

# All the mail that falls through to this point
# will be delivered into the user's INBOX
:0 wi
#| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER
| /usr/local/cyrus/bin/deliver -r $USER@$DOMAIN $USER/Trash

}

:0
! -f $FROM "$@"

Thanks
S

Re: Resolve recipent"s real user name from alias

am 19.01.2007 00:30:24 von Pet Farrari

OK, I just got this alias to real name mapping thing solved.
I just found out the postfix/master.cf has a "-o alias = " clause
written, this overwrite the alias mapping I defined in the main.cf file.
Postfix get the alias name resolved to real name before pass it onto
procmail, so procmail gets the real name and hand it down to cyrus
deliver for the final delivery.

I also tested cc mail, it also works.

Is there any other critical tests I missed?

Cheers
Sam

Pet Farrari wrote:
> Hi,
>
> With using cyrus, procmail and formail for mail deliver, I have a
> problem in dealing with email alias.
>
> eg.
>
> Let s say the email server received an incoming email with alias user
> name (d.david) in the To: field, but its imap folder name is a real user
> name (david). If the email is a Spam, I want to use cyrus deliver to
> deliver the email to his imap folder david/Spam. But since the incoming
> email is d.david, I don't know how to resolve this alias (d.david) to
> the real name (david). I have this alias to real name mapping in
> /etc/postfix/alias file, and in the database as well. If I don't care to
> put this email in the specific folder Spam, I don't need to use cyrus
> deliver , then I won't have the problem.
>
> Here is the content of the procmail.rc file:
>
> SHELL=/bin/sh
> DROPPRIVS=yes
> LINEBUF=32768
> SENDMAILFLAGS="-oi"
> LOGFILE="/var/log/spamkill/spamkill.log"
> SPAMC="/usr/local/bin/spamc"
> DELIVER=/usr/local/cyrus/bin/deliver
>
> FROM="<$1>"
> TO=$2
> SHIFT=1
>
>
> :0f
> |$SPAMC -f -U /var/run/spamd.sock
>
> :0
> * ^X-Spam-Level: \*\*\*\*\*
> {
> TO_FIELD=`/usr/local/bin/formail -zxTo:`
> REC_FIELD=`/usr/local/bin/formail -zxX-Recipient:`
> USER=`echo $TO_FIELD | cut -d "@" -f1`
> DOMAIN=`echo $TO_FIELD | cut -d "@" -f2`
>
> # Debug statement. Comment out these Debug log lines later.
> LOG="[$$]$_: Debug: TO_FIELD=$TO_FIELD${NL}\n"
> LOG="[$$]$_: Debug: TO=$TO${NL}\n"
> LOG="[$$]$_: Debug: USER=$USER${NL}\n"
> LOG="[$$]$_: Debug: DOMAIN=$DOMAIN${NL}\n"
>
> #OLDRECIPIENTS=|echo "$@"
> LOG="[$$]$_: Debug: OLDRECIPIENTS=${REC_FIELD}${NL}"
>
> # SWITCHRC="/usr/local/etc/procmailrcs/spamkill.rc"
>
> # File: procmail.global
>
> # Make a backup copy of all incoming mail (comment the next entry
> # out once you're finished testing procmail integration)
> #:0 ic
> #| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER.backup
>
> # Execute CYRUSUSER's personal rules
> #INCLUDERC=/var/imap/procmail/user/procmail.$CYRUSUSER
>
> # Example recipes
>
> # All the mail that falls through to this point
> # will be delivered into the user's INBOX
> :0 wi
> #| $DELIVER -e -a $CYRUSUSER -m user.$CYRUSUSER
> | /usr/local/cyrus/bin/deliver -r $USER@$DOMAIN $USER/Trash
>
> }
>
> :0
> ! -f $FROM "$@"
>
> Thanks
> S