Index | Thread | Search

From:
Philipp <philipp+openbsd@bureaucracy.de>
Subject:
smtpd mda set ORIGINAL_RECIPIENT
To:
tech@openbsd.org
Date:
Wed, 13 Mar 2024 19:27:08 +0100

Download raw body.

Thread
Hi

Someone asked for the ORIGINAL_RECIPIENT environment variable for mdas.
This is set by postfix[0] and some mda (i.e. public-inbox[1]) use them
to handle there mails.

I have implemented this and also add some documentation for the mda
interface.

Philippp

[0] https://www.postfix.org/local.8.html
[1] https://public-inbox.org/public-inbox-mda.html

diff --git a/usr.sbin/smtpd/mda_unpriv.c b/usr.sbin/smtpd/mda_unpriv.c
index 1d59550aead..d2e67f66164 100644
--- a/usr.sbin/smtpd/mda_unpriv.c
+++ b/usr.sbin/smtpd/mda_unpriv.c
@@ -28,7 +28,7 @@ mda_unpriv(struct dispatcher *dsp, struct deliver *deliver,
     const char *pw_name, const char *pw_dir)
 {
 	int		idx;
-	char	       *mda_environ[11];
+	char	       *mda_environ[12];
 	char		mda_exec[LINE_MAX];
 	char		mda_wrapper[LINE_MAX];
 	const char     *mda_command;
@@ -54,6 +54,7 @@ mda_unpriv(struct dispatcher *dsp, struct deliver *deliver,
 	xasprintf(&mda_environ[idx++], "PATH=%s", _PATH_DEFPATH);
 	xasprintf(&mda_environ[idx++], "DOMAIN=%s", deliver->rcpt.domain);
 	xasprintf(&mda_environ[idx++], "HOME=%s", pw_dir);
+	xasprintf(&mda_environ[idx++], "ORIGINAL_RECIPIENT=%s@%s", deliver->rcpt.user, deliver->rcpt.domain);
 	xasprintf(&mda_environ[idx++], "RECIPIENT=%s@%s", deliver->dest.user, deliver->dest.domain);
 	xasprintf(&mda_environ[idx++], "SHELL=/bin/sh");
 	xasprintf(&mda_environ[idx++], "LOCAL=%s", deliver->rcpt.user);
diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5
index 257ad172dc4..cf5e7b261f6 100644
--- a/usr.sbin/smtpd/smtpd.conf.5
+++ b/usr.sbin/smtpd/smtpd.conf.5
@@ -1113,6 +1113,30 @@ For example, with recipient
 .It %{rcpt}     Ta expands to Dq user+t:g@example.org
 .It %{rcpt:raw} Ta expands to Dq user+t?g@example.org
 .El
+.Ss MDA ENVIRONMENT
+When a MDA is invoced smtpd will create a new process.
+Only the uid and gid of the destination user is set.
+The following environment variables will be set:
+.Bl -tag -width "ORIGINAL_RECIPIENT"
+.It Ev DOMAIN
+The recipient domain
+.It Ev HOME
+The home directory of the destination user
+.It Ev RECIPIENT
+The address of the final recipient
+.It Ev ORIGINAL_RECIPIENT
+The address of the original recipient
+.It Ev EXTENSION
+The sub address of the recipient (only set when the recipient has a sub address)
+.It Ev SENDER
+The address of the sender (might be empty)
+.El
+.Pp
+This process gets the mail piped to
+.Xr stdin 3 .
+A mail is considered as deliverd when the mda exit with EX_OK and
+.Xr stdin 3
+is completly read.
 .Sh FILES
 .Bl -tag -width "/etc/mail/smtpd.confXXX" -compact
 .It Pa /etc/mail/smtpd.conf