Any occurrences of $H are replaced with the portion of the host/domain specification that was not matched by the rule. Any occurrences of $D are replaced by the portion of the host/domain specification that was matched by the rewrite rule. $nH and $nD are variants that preserve the normal $H or $D portion from the nth leftmost part starting counting from 0. Or another way of putting it is that $nH and $nD omit the leftmost n parts (starting counting from 1) of what would normally be a $H or $D, substitution, respectively. In particular, $0H is equivalent to $H and $0D is equivalent to $D.
For example, suppose the address jdoe@host.acme.com matches the rewrite rule
host.acme.com $U%$1D@TCP-DAEMONThen the result of the rewrite rule will be jdoe@acme.com with TCP-DAEMON used as the outgoing channel. Here where $D would have substituted in the entire domain that matched, host.acme.com, the $1D instead substitutes in the portions of the match starting from part 1 (part 1 being acme), so substitutes in acme.com.
$L substitutes the portion of a domain literal that was not matched by the rewrite rule.