Mailing List Archive

Equivalent of Envelope-to as variables in pipe transport
How do I access the equivalent of "Envelope-to" header in transport
variables?

I'm trying to call dovecot-lda in a manner that enables its "envelope"
rule.

To do so requires the MTA to pass information about the envelope recipient
using the -a flag.

Documentation [1] suggests:

dovecot_delivery:
driver = pipe
command = /usr/local/libexec/dovecot/deliver -k \
-a "$original_local_part@$original_domain"
envelope_to_add

But these variables are considered tainted and I cannot see an equivalent.

What is available is $local_part_data and $domain_data, but these diverge
from Envelope-to (eg. on /etc/alias changing the destination)

Or, since I'm merely passing this information down the pipeline (not
deriving a name for files/folders etc.), is it safe to use the tainted
variables and is there some way to safely escape them?

There's a workaround of asking Dovecot to pick up from the header (using
lda_original_recipient_header), but a tidy and proper solution would seem
to avoid modifying the message with a new header.

Exim is v4.97.1 on FreeBSD 13.2

[1] https://doc.dovecot.org/3.0/configuration_manual/howto/dovecot_lda_exim/

--
Mark



--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On 2024-04-23 Mark Hills via Exim-users <exim-users@lists.exim.org> wrote:
> How do I access the equivalent of "Envelope-to" header in transport
> variables?

> I'm trying to call dovecot-lda in a manner that enables its "envelope"
> rule.
[...]

Hello,

Iirc think the easiest way to combine dovecot and exim is nowadays to
use the LMTP server instead of dovecot-lda.

cu Andreas
--
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
I would second this approach - it is how I managed to resolve (well,
sidestep) this issue with dovecot delivery once my Exim went to the latest
Debian Stable packaged version (4.96-15+deb12u4).

Graeme


On Tue, 23 Apr 2024, 18:12 Andreas Metzler via Exim-users, <
exim-users@lists.exim.org> wrote:

> On 2024-04-23 Mark Hills via Exim-users <exim-users@lists.exim.org> wrote:
> > How do I access the equivalent of "Envelope-to" header in transport
> > variables?
>
> > I'm trying to call dovecot-lda in a manner that enables its "envelope"
> > rule.
> [...]
>
> Hello,
>
> Iirc think the easiest way to combine dovecot and exim is nowadays to
> use the LMTP server instead of dovecot-lda.
>
> cu Andreas
> --
> `What a good friend you are to him, Dr. Maturin. His other friends are
> so grateful to you.'
> `I sew his ears on from time to time, sure'
>
> --
> ## subscription configuration (requires account):
> ##
> https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
> ## unsubscribe (doesn't require an account):
> ## exim-users-unsubscribe@lists.exim.org
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On 23/04/2024 18:09, Andreas Metzler via Exim-users wrote:
> On 2024-04-23 Mark Hills via Exim-users <exim-users@lists.exim.org> wrote:
>> How do I access the equivalent of "Envelope-to" header in transport
>> variables?
>
>> I'm trying to call dovecot-lda in a manner that enables its "envelope"
>> rule.

> Iirc think the easiest way to combine dovecot and exim is nowadays to
> use the LMTP server instead of dovecot-lda.

If you don't want to use LMTP, then you'll need to record
de-tainted versions of the pre-aliasing variables, and use those
in that command-line.

The usual, documented, methods for de-tainting apply. All boil
down to using the tainted values as keys for lookup in a local store.
You can set variables in a router, and those can be used in the
eventual transport.
--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On Tue, Apr 23, 2024 at 8:11?PM Andreas Metzler via Exim-users <
exim-users@lists.exim.org> wrote:

> On 2024-04-23 Mark Hills via Exim-users <exim-users@lists.exim.org> wrote:
> > How do I access the equivalent of "Envelope-to" header in transport
> > variables?
>
> > I'm trying to call dovecot-lda in a manner that enables its "envelope"
> > rule.
> [...]
>
> Hello,
>
> Iirc think the easiest way to combine dovecot and exim is nowadays to
> use the LMTP server instead of dovecot-lda
>

Any ideas on how to implement the same with virtual users?

I have been using dovecot-lda successfully with virtual users with the
following transport:

dovecot_virtual_delivery:
driver = pipe
return_output
command = /usr/local/libexec/dovecot/deliver -d
${extract{username}{$address_data}}
message_suffix =
delivery_date_add
envelope_to_add
return_path_add
log_output
user = mailnull

Now I am trying to translate the above into an lmtp delivery and I am stuck:

dovecot_virtual_delivery_lmtp:
driver = lmtp
socket = /var/run/dovecot/lmtp
#allow suffixes/prefixes (default unset)
rcpt_include_affixes
#maximum number of deliveries per batch, default 1
batch_max = 100
delivery_date_add
envelope_to_add
return_path_add
user = mailnull
group = mailnull

Testing the lmtp transport I get the following error:
```
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

save to /var/spool/virtual/domain.name/johndoe/Maildir
generated by johndoe@domain.name
LMTP error after RCPT TO:</var/spool/virtual/domain.name/johndoe/Maildir
>:
550 5.1.1 < /var/spool/virtual/domain.name/johndoe/Maildir> User
doesn't exist:
/var/spool/virtual/domain.name/johndoe/Maildir
```

The router involved is this:
virtual_domains:
driver = redirect
domains = +local_domains
condition = ${if < {SPAMREJECT}{1000}}
address_data = ${lookup mysql{ \
select smtp, username, users.sa_tag*10 AS sa_tag,
users.on_spamassassin AS on_spamassassin, \
domains.spamassassin AS spamassassin, \
users.uid AS uid, users.gid AS gid, users.quota AS
quota from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and domains.enabled = '1' \
and users.enabled = '1' \
and users.domain_id = domains.domain_id}{$value}fail}
data = ${extract{smtp}{$address_data}}
# exim4u headers_remove to remove subject if spam or X-Spam-Report if not
spam and SPAMHEADERTYPE=0.
headers_remove = ${if and {{
>={$acl_m_spamscore}{${extract{sa_tag}{$address_data}}}} \
{eq {1}{${extract{on_spamassassin}{$address_data}}}} \
{eq {1}{${extract{spamassassin}{$address_data}}}}} \
{Subject}{${if eq{SPAMHEADERTYPE}{0}{X-Spam-Report}}}
\
}
# exim4u headers_add to rewrite subject and set X-Spam-Report=YES if spam
and set X-Spam-Report=NO if not spam.
headers_add = ${if and {{ >=
{$acl_m_spamscore}{${extract{sa_tag}{$address_data}}}} \
{eq {1}{${extract{on_spamassassin}{$address_data}}}} \
{eq {1}{${extract{spamassassin}{$address_data}}}}} \
{X-Spam-Flag: YES\nSubject: [SPAMTAGTEXT]
$h_Subject:\n}{X-Spam-Flag: NO\n} \
}
# file_transport = virtual_delivery
#file_transport = dovecot_virtual_delivery
file_transport = dovecot_virtual_delivery_lmtp
reply_transport = address_reply
pipe_transport = address_pipe
retry_use_local_part
allow_fail
local_part_suffix = +*
local_part_suffix_optional


--
Best regards,
Odhiambo WASHINGTON,
Nairobi,KE
+254 7 3200 0004/+254 7 2274 3223
In an Internet failure case, the #1 suspect is a constant: DNS.
"Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(?)_/¯ :-)
[How to ask smart questions:
http://www.catb.org/~esr/faqs/smart-questions.html]

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On 24/04/2024 11:39, Odhiambo Washington via Exim-users wrote:
> LMTP error after RCPT TO:</var/spool/virtual/domain.name/johndoe/Maildir

First decide what recipient should have been used for the LMTP,
then work backwards to have the router that calls that transport
produce it. I'd expect to see something looking rather more
like "user@domain" than a directory path.
--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On Wed, Apr 24, 2024 at 1:57?PM Jeremy Harris via Exim-users <
exim-users@lists.exim.org> wrote:

> On 24/04/2024 11:39, Odhiambo Washington via Exim-users wrote:
> > LMTP error after RCPT TO:</var/spool/virtual/
> domain.name/johndoe/Maildir
>
> First decide what recipient should have been used for the LMTP,
> then work backwards to have the router that calls that transport
> produce it. I'd expect to see something looking rather more
> like "user@domain" than a directory path.


The user@domain is what the previous transport obtained by
'${extract{username}{$address_data}}"
How to pass this down to the lmtp transport is what I am blank about.

--
Best regards,
Odhiambo WASHINGTON,
Nairobi,KE
+254 7 3200 0004/+254 7 2274 3223
In an Internet failure case, the #1 suspect is a constant: DNS.
"Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(?)_/¯ :-)
[How to ask smart questions:
http://www.catb.org/~esr/faqs/smart-questions.html]

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On 24/04/2024 12:13, Odhiambo Washington via Exim-users wrote:
> On Wed, Apr 24, 2024 at 1:57?PM Jeremy Harris via Exim-users <
> exim-users@lists.exim.org> wrote:
>
>> On 24/04/2024 11:39, Odhiambo Washington via Exim-users wrote:
>>> LMTP error after RCPT TO:</var/spool/virtual/
>> domain.name/johndoe/Maildir
>>
>> First decide what recipient should have been used for the LMTP,
>> then work backwards to have the router that calls that transport
>> produce it. I'd expect to see something looking rather more
>> like "user@domain" than a directory path.
>
>
> The user@domain is what the previous transport obtained by
> '${extract{username}{$address_data}}"
> How to pass this down to the lmtp transport is what I am blank about.
>

Your redirect router needs to have a "data" or "file" option which
has the value you want.
--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On 2024-04-24 Odhiambo Washington <odhiambo@gmail.com> wrote:
[...]

> LMTP error after RCPT TO:</var/spool/virtual/domain.name/johndoe/Maildir
[...]
> virtual_domains:
[...]
> data = ${extract{smtp}{$address_data}}

Afaict you need to modify this to return johndoe@domain.name instead of
/var/spool/virtual/domain.name/johndoe/Maildir.

cu Andreas
--
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
Thanks to those suggesting LMTP.

I did a quick test and things got in a tangle with hostnames, but it does
seem to be the appropriate solution. I'll need to commit more time which
I'll do when I have some.

--
Mark

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Equivalent of Envelope-to as variables in pipe transport [ In reply to ]
On Wed, Apr 24, 2024 at 7:26?PM Andreas Metzler via Exim-users <
exim-users@lists.exim.org> wrote:

> On 2024-04-24 Odhiambo Washington <odhiambo@gmail.com> wrote:
> [...]
>
> > LMTP error after RCPT TO:</var/spool/virtual/
> domain.name/johndoe/Maildir
> [...]
> > virtual_domains:
> [...]
> > data = ${extract{smtp}{$address_data}}
>
> Afaict you need to modify this to return johndoe@domain.name instead of
> /var/spool/virtual/domain.name/johndoe/Maildir.
>

Sure. Changing that to "data = ${extract{username}{$address_data}}" yields
johndoe@domain.name.
But then I face the challenge of setting the appropriate transport for this
redirect router.
Looking at
https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_redirect_router.html,
I realized that what I'm trying to do is not possible with a redirect
router.

So I created a "accept" router which works:

virtual_domains_lmtp:
driver = accept
domains = +local_domains
condition = ${if < {SPAMREJECT}{1000}}
address_data = ${lookup mysql{ \
select smtp, username, users.sa_tag*10 AS sa_tag,
users.on_spamassassin AS on_spamassassin, \
domains.spamassassin AS spamassassin, \
users.uid AS uid, users.gid AS gid, users.quota AS
quota from users,domains \
where localpart = '${quote_mysql:$local_part}' \
and domain = '${quote_mysql:$domain}' \
and domains.enabled = '1' \
and users.enabled = '1' \
and users.domain_id = domains.domain_id}{$value}fail}
# exim4u headers_remove to remove subject if spam or X-Spam-Report if not
spam and SPAMHEADERTYPE=0.
headers_remove = ${if and {{
>={$acl_m_spamscore}{${extract{sa_tag}{$address_data}}}} \
{eq {1}{${extract{on_spamassassin}{$address_data}}}} \
{eq {1}{${extract{spamassassin}{$address_data}}}}} \
{Subject}{${if eq{SPAMHEADERTYPE}{0}{X-Spam-Report}}}
\
}
# exim4u headers_add to rewrite subject and set X-Spam-Report=YES if spam
and set X-Spam-Report=NO if not spam.
headers_add = ${if and {{ >=
{$acl_m_spamscore}{${extract{sa_tag}{$address_data}}}} \
{eq {1}{${extract{on_spamassassin}{$address_data}}}} \
{eq {1}{${extract{spamassassin}{$address_data}}}}} \
{X-Spam-Flag: YES\nSubject: [SPAMTAGTEXT]
$h_Subject:\n}{X-Spam-Flag: NO\n} \
}
transport = dovecot_virtual_delivery_lmtp
retry_use_local_part
local_part_suffix = +*
local_part_suffix_optional



Thanks, everyone.


--
Best regards,
Odhiambo WASHINGTON,
Nairobi,KE
+254 7 3200 0004/+254 7 2274 3223
In an Internet failure case, the #1 suspect is a constant: DNS.
"Oh, the cruft.", egrep -v '^$|^.*#' ¯\_(?)_/¯ :-)
[How to ask smart questions:
http://www.catb.org/~esr/faqs/smart-questions.html]

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/