corecode / dma

The DragonFly Mail Agent, a small Mail Transport Agent (MTA), designed for home and office use.
Other
235 stars 51 forks source link

dma.c: Improve override of 'from' host by MASQUERADE config setting #116

Closed ian-abbott closed 1 year ago

ian-abbott commented 1 year ago

This allows a MASQUERADE config setting containing only a host name to override any host name set by the -f command line option or by the EMAIL environment variable. Previously, that only worked if the MASQUERADE config setting also overrode the user name.

Fixes #114

corecode commented 1 year ago

There is a bit too much pointer arithmetic and confusing logic flow in there for my current taste.

I think we should start by stating what behavior we want regarding masquerade and address.

Clearly the current code (and the proposed change) are agglomerated ad-hoc code, which makes it hard to reason about.

emaste commented 1 year ago

I think we should start by stating what behavior we want regarding masquerade and address.

I think what's documented already in dma.8 is reasonable.

corecode commented 1 year ago
 -f sender
         Set sender address (envelope-from) to sender.  This over‐
         rides the value of the EMAIL environment variable, but is
         overridden by the ‘MASQUERADE’ config file setting.

and

       If ‘MASQUERADE’ does not contain a @ sign, the string is
       interpreted as a host name.  For example, setting ‘MASQUERADE’ to
       ‘john@’ on host ‘hamlet’ will send all mails as ‘john@hamlet’;
       setting it to ‘percolator’ will send all mails as
       ‘username@percolator’.

We could do this (and I think the PR does something very similar):

select (incomplete) address (highest priority first):

  1. from -f arg
  2. EMAIL env
  3. just username, set elsewhere

Now split this address into user and host components.

If host is empty, use hostname, set elsewhere

Now apply masquerade:

Now reassemble address and return it.

It feels more intuitive to apply the masquerade last ("overriding") than interspersed with the user and host selection.

What do you think?

ian-abbott commented 1 year ago

I have an improved PR #117 more in line with the comments above.

ian-abbott commented 1 year ago

This PR is stale now that PR #117 has been merged, so closing it.