NetBSD/gnu/dist/postfix/local/unknown.c

127 lines
3.4 KiB
C

/*++
/* NAME
/* unknown 3
/* SUMMARY
/* delivery of unknown recipients
/* SYNOPSIS
/* #include "local.h"
/*
/* int deliver_unknown(state, usr_attr)
/* LOCAL_STATE state;
/* USER_ATTR usr_attr;
/* DESCRIPTION
/* deliver_unknown() delivers a message for unknown recipients.
/* .IP \(bu
/* If an alternative message transport is specified via the
/* fallback_transport parameter, delivery is delegated to the
/* named transport.
/* .IP \(bu
/* If an alternative address is specified via the luser_relay
/* configuration parameter, mail is forwarded to that address.
/* .IP \(bu
/* Otherwise the recipient is bounced.
/* .PP
/* The luser_relay parameter is subjected to $name expansion of
/* the standard message attributes: $user, $home, $shell, $domain,
/* $recipient, $mailbox, $extension, $recipient_delimiter, not
/* all of which actually make sense.
/*
/* Arguments:
/* .IP state
/* Message delivery attributes (sender, recipient etc.).
/* Attributes describing alias, include or forward expansion.
/* A table with the results from expanding aliases or lists.
/* A table with delivered-to: addresses taken from the message.
/* .IP usr_attr
/* Attributes describing user rights and environment.
/* DIAGNOSTICS
/* The result status is non-zero when delivery should be tried again.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*--*/
/* System library. */
#include <sys_defs.h>
/* Utility library. */
#include <msg.h>
#include <stringops.h>
#include <mymalloc.h>
#include <vstring.h>
/* Global library. */
#include <been_here.h>
#include <mail_params.h>
#include <mail_proto.h>
#include <bounce.h>
/* Application-specific. */
#include "local.h"
/* deliver_unknown - delivery for unknown recipients */
int deliver_unknown(LOCAL_STATE state, USER_ATTR usr_attr)
{
char *myname = "deliver_unknown";
int status;
VSTRING *expand_luser;
/*
* Make verbose logging easier to understand.
*/
state.level++;
if (msg_verbose)
MSG_LOG_STATE(myname, state);
/*
* DUPLICATE/LOOP ELIMINATION
*
* Don't deliver the same user twice.
*/
if (been_here(state.dup_filter, "%s %s", myname, state.msg_attr.local))
return (0);
/*
* The fall-back transport specifies a delivery machanism that handles
* users not found in the aliases or UNIX passwd databases.
*/
if (*var_fallback_transport)
return (deliver_pass(MAIL_CLASS_PRIVATE, var_fallback_transport,
state.request, state.msg_attr.recipient, -1L));
/*
* Bounce the message when no luser relay is specified.
*/
if (*var_luser_relay == 0)
return (bounce_append(BOUNCE_FLAG_KEEP, BOUNCE_ATTR(state.msg_attr),
"unknown user: \"%s\"", state.msg_attr.local));
/*
* Subject the luser_relay address to $name expansion, disable
* propagation of unmatched address extension, and re-inject the address
* into the delivery machinery. Donot give special treatment to "|stuff"
* or /stuff.
*/
state.msg_attr.unmatched = 0;
expand_luser = vstring_alloc(100);
local_expand(expand_luser, var_luser_relay, &state, &usr_attr, (char *) 0);
status = deliver_resolve_addr(state, usr_attr, vstring_str(expand_luser));
vstring_free(expand_luser);
/*
* Done.
*/
return (status);
}