"Rupa Schomaker (list)" <rupa-list(_at_)rupa(_dot_)com> writes:
I deliver to a cyrus mailbox. If I have a "extension"
(user+extension(_at_)domain) I want to use a different call to deliver than
if there is no extension. The extension (and user) is passed to
procmail in an environment variable. If there is no extension, then
extension is either undefined or set to nothing (defined, but not
value).
I don't see any way to do a conditional based on the value of an
environment variable. For now, I first try delivery to the folder
with extension and if that fails deliver to the main mailbox for the
user. I trap the failure with w and then use an "e" in the next
recipe.
The standard sendmail.cf setup passes the extension (sans plus) to
procmail via the -a flag. This can be accessed by referencing "$1":
ARG = $1
I'll note that with this setup, procmail has no way to tell apart
user+(_at_)domain
and user(_at_)domain
they both set $1 to nothing, and $# to 1. If you need to differentiate
those two then you'll need to more advanced sendmail.cf changes.
Otherwise, just expand $1 into some other variable and check it's value
with the "var ??" syntax. If you just want to check whether it's set,
the fastest means are to use a condition of
* ! $ ${var:+!}
That expands to just "!" if var is not-set or empty, or "! !" if it
is set to a non-empty value. Therefore, it'll 'match' if and only if
the variable is set to a non-empty value.
How should I be doing this?
===== sample stuff =======
:0W
| $DELIVERMAIL -a $LOGNAME -m user.$LOGNAME.$EXTENSION
:0we
| $DELIVERMAIL -a $LOGNAME -m user.$LOGNAME
:0 e
{
EXITCODE=$?
HOST
}
That would be:
EXTENSION = $1
# Only do this recipe if EXTENSION is set to a non-empty action.
:0 w
* ! $ ${EXTENSION:+!}
| $DELIVERMAIL -a $LOGNAME -m user.$LOGNAME.$EXTENSION
:0 wE
| $DELIVERMAIL -a $LOGNAME -m user.$LOGNAME
EXITCODE=$?
HOST
Philip Guenther