diff --git a/smtpd/expand.c b/smtpd/expand.c index 718d635..75d0a36 100644 --- a/smtpd/expand.c +++ b/smtpd/expand.c @@ -75,6 +75,14 @@ expand_insert(struct expand *expand, struct expandnode *node) expand); node->sameuser = 1; } + if (node->type == EXPAND_ADDRESS && + expand->parent && + expand->parent->type == EXPAND_ADDRESS && + mailaddr_match(&expand->parent->u.mailaddr, &node->u.mailaddr)) { + log_trace(TRACE_EXPAND, "expand: %p: setting sameaddr = 1", + expand); + node->sameaddr = 1; + } if (expand_lookup(expand, node)) { log_trace(TRACE_EXPAND, "expand: %p: node found, discarding", @@ -136,6 +144,10 @@ expand_cmp(struct expandnode *e1, struct expandnode *e2) return -1; if (e1->sameuser > e2->sameuser) return 1; + if (e1->sameaddr < e2->sameaddr) + return -1; + if (e1->sameaddr > e2->sameaddr) + return 1; if (e1->mapping < e2->mapping) return -1; if (e1->mapping > e2->mapping) diff --git a/smtpd/lka_session.c b/smtpd/lka_session.c index b6a385e..8636ae9 100644 --- a/smtpd/lka_session.c +++ b/smtpd/lka_session.c @@ -294,6 +294,13 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) "[depth=%d]", xn->u.mailaddr.user, xn->u.mailaddr.domain, xn->depth); + if (xn->sameaddr) { + log_trace(TRACE_EXPAND, "expand: lka_expand: same " + "address, submitting"); + lka_submit(lks, rule, xn); + break; + } + /* Pass the node through the ruleset */ ep = lks->envelope; ep.dest = xn->u.mailaddr; diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h index 5d16e3c..5ded1b4 100644 --- a/smtpd/smtpd.h +++ b/smtpd/smtpd.h @@ -453,6 +453,7 @@ struct expandnode { TAILQ_ENTRY(expandnode) tq_entry; enum expand_type type; int sameuser; + int sameaddr; int alias; struct rule *rule; struct expandnode *parent;