From: Johannes Thyssen Tishman Subject: Re: smtpd: fix using modifiers with partial expansion in format specifiers To: Omar Polo Cc: tech@openbsd.org Date: Fri, 3 Apr 2026 10:21:37 +0000 2026-04-03T11:32:22+0200 Omar Polo : > Hello, > > Johannes Thyssen Tishman wrote: > > As described in smtpd.conf(5), format specifiers, e.g. '%{sender.user}', > > support partial expansion using bracket notation (%{sender.user[n:m]}), > > as well as modifiers (%{sender.user:strip}). However using both at the > > same time (%{sender.user[n:m]:strip}) gives the following error: > > > > "smtpd: mda command line could not be expanded" > > > > This occurs because the leading colon from the modifier is not stripped, > > resulting in a "modifier not found" error. The diff below fixes this. I > > also added a comment to smtpd.conf(5) to clarify that modifiers and > > partial expansion *can* be used together and that, when used together, > > modifiers are applied before partial expansion. > > > > For those interested, a good example of how this can be used is sorting > > emails from OpenBSD mailing lists into their own maildirs, e.g.: > > > > action "obsd_sort" maildir "~/mail/.OpenBSD.%{sender.user[6:]:strip}" > > match from mail-from regex "^owner-[^@]*@example\.org$" \ > > for local action "obsd_sort" > > nice =) > > I have sieve filters for this, but it's nice that it can be done also > with just the modifiers! > > diffs make sense to me, nits on the manpage: > > > [...] > > --- usr.sbin/smtpd/smtpd.conf.5 > > +++ usr.sbin/smtpd/smtpd.conf.5 > > @@ -1144,6 +1144,13 @@ For example, with recipient > > .It %{rcpt:lowercase|strip} Ta expands to Dq user@example.org > > .El > > .Pp > > +Modifiers and partial expansion can be used together. In such cases, the > > new sentence, new line > > > +modifiers are applied before the partial expansion. For example, with sender > > ditto > > > +.Dq owner-tech+M123456@openbsd.org : > > +.Bl -column %{sender.user[6:]:strip} -offset indent > > +.It %{sender.user[6:]:strip} Ta expands to Dq tech > > +.El > > +.Pp > > For security concerns, expanded values are sanitized and potentially > > dangerous characters are replaced with > > .Sq \&: . > > please run this through `man -Tlint -l smtpd.conf.5' to verify :P > > with this fixed, the diff is okay op@, thanks! Thanks op@, committed!