3

I have a normal sendmail installation. A user has a .forward like this:

# cat ~elrond/.forward
elrond@somewhere
# sendmail -bv elrond+extra@localhost
elrond@somewhere...  deliverable: mailer esmtp, host somewhere., user elrond@somewhere

Note that the +extra is lost.

What do I need to change to make the +extra be preserved? The usual %3 for hashmaps does not work in the .forward.

Anthon
  • 79,293
Elrond
  • 556
  • Could you post results of sendmail -bv elrond+extra@localhost without ~elrond/.forward file? [There are some special cases] – AnFi May 22 '13 at 17:20
  • Gives a nice and easy elrond+extra@this.box... deliverable: mailer local, host extra, user elrond. But please give all variants in your hopefully upcoming answer, so that others with other variants will love that answer too. – Elrond May 22 '13 at 17:46
  • Could you post also which program your sendmail uses as local mailer? P=xxx after Mlocal line in your sendmail.cf. I have hoped for host extra because it most likely will simplify things a lot. I am not too good at brief explanations of advanced sendmailing ;-) – AnFi May 22 '13 at 19:22
  • Well, does the Mlocal have any effect when .forward is in effect? I highly doubt that. For the record: I have FEATURE(local_procmail). So it's procmail in the Mlocal line. – Elrond May 22 '13 at 19:24
  • Is there indeed a usernamed 'elrond+extra' in your system????? Also, I strongly recommend reading the document concerning creation of the *.mc file for sendmail. – mdpc May 22 '13 at 19:51
  • @mdpc: There's only a user elrond. The +detail is a feature of sendmail. If you have a user elrond, you will receive any mail on elrond+FOOBAR for any FOOBAR. And I am writing .mc files for about 15 years now. :-) – Elrond May 22 '13 at 20:59

3 Answers3

1

Try FEATURE(preserve_local_plus_detail) in your .mc file, and rebuild your .cf. This modifies ruleset 5 (localaddr). It may cause side-effects (i.e. if your local mailer doesn't support +detail).

If this adversely effects your aliases lookup, then perhaps _FFR_ALIAS_DETAIL is for you, this is a build time (i.e. not .cf) option, I can't say I've tested it though. Not recommended ;-)

Failing that, the only way I can see of doing anything like you require with just user-controlled .forward files is to check your confFORWARD_PATH includes a path that has a $h component. This should be the default since at least 8.12:

O ForwardPath=$z/.forward.$w+$h:$z/.forward+$h:$z/.forward.$w:$z/.forward

This will allow a users to create say, ~/.forward.extra to control where "user+extra" addressed email goes:

$ sendmail -v -d27.2  -bv elrond+foo 
alias(elrond+foo)
alias(elrond+*)
alias(elrond)
alias(elrond)
forward(elrond+foo)
include(/home/elrond/.forward.thishost+foo)
include(/home/elrond/.forward+foo)
include(/home/elrond/.forward.thishost)
include(/home/elrond/.forward)
elrond+foo... deliverable: mailer local, host foo, user elrond

(You can see the forward files being handled by the include() function ‒ it has no notion of expansion when it reads the files.)

FEATURE(virtusertable) as suggested elsewhere is probably a better way to go, if you're the scripting kind you could collect user ~/.xforward files periodically and build a master virtusertable.

mr.spuratic
  • 9,901
  • Good idea! I haven't seen that option. BUT: From the docs "Preserve the +detail portion of the address when passing address to local delivery agent. Disables alias and .forward +detail stripping (e.g., given user+detail, only that address will be looked up in the alias file; user+* and user will not be looked up)" -- Well, this basicly means, that sendmail -bv elrond+extra@localhost gives a "user unknown". And I wonder, if it really would forward to elrond+extra@somewhere in that case? – Elrond May 22 '13 at 17:43
1

You use procmail as sendmail's local mailer program [FEATURE(local_procmail)]
=> you may redirect/forward messages in ~elrond/.procmailrc with $1 holding the detail part.

Sorry but my procmail knowledge is insufficient to provide RELIABLE recipe e.g. some sanity checks of $1.

WARNING: message to both elrond+1 and elrond+2 will be passed as two separate messages to procmail.

AnFi
  • 1,546
  • Okay, that would be an option. But I would like to keep the envelope sender of the mail (.forward would do that). Yes, I could extract the envelope sender in procmail (I actually have that for very specific things working). But really, I would like something for all my system user's to work. So that I can tell them "If you want to forward with detail, put {yourname}%3@{yourhost} in your own .forward. – Elrond May 22 '13 at 21:02
  • Are you interested in postmaster level solutions? e.g. virtusertable entry. – AnFi May 23 '13 at 12:13
  • virtusertable is the one place, where this whole thing works nicely: elrond@this.box elrond%3@other.box. I have that in place for some of my users without system accounts (also I find it stupid, that virtuser can't take entries without domain, as this box has multiple domains and adding them all to virtusertable is ugly). For system users I would really prefer them being able to easily edit their own forwarding. That said, I will probably resort to letting users tell me, what they want and me adding multiple entries to virtusertable. – Elrond May 23 '13 at 12:58
0

Have you considered allowing users use (dovecot) sieve?

It seems that you may use example below with redirect instead of fileinto http://wiki2.dovecot.org/Pigeonhole/Sieve/Examples#Plus_Addressed_mail_filtering

AnFi
  • 1,546