I currently have the following snippet for extracting the domain from a sender, untainting it and selecting the DKIM key.
FROM_DOMAIN_WITHOUT_WWW = ${sg{${lc:${domain:$h_from:}}}{^www\.}{}}
DKIM_DOMAIN_UNTAINTED = ${lookup{FROM_DOMAIN_WITHOUT_WWW} lsearch,ret=key {/etc/exim4/dkim/selector.map}}
DKIM_PRIVATE_KEY = ${lookup{DKIM_DOMAIN_UNTAINTED} lsearch {/etc/exim4/dkim/selector.map}}
Now I want to sign subdomains too, how can I extract the domain from ${domain:$h_from:} if it's a subdomain?