1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

queue: Get the DSN domain from the message

Picking the domain used in the DSN message "From" header is more
complicated than it needs to be, causing confusing code paths and having
different uses for the hostname, which should be purely aesthetic.

This patch makes the queue pick the DSN "From" domain from the message
itself, by looking for a local domain in either the sender or the
original recipients. We should find at least one, otherwise it'd be
relaying.

This allows the code to be simplified, and we can narrow the scope of
the hostname option even further.
This commit is contained in:
Alberto Bertogli
2016-11-03 00:48:34 +00:00
parent 2da74c1758
commit fea808f8e3
6 changed files with 43 additions and 36 deletions

View File

@@ -105,14 +105,11 @@ type Queue struct {
// Aliases resolver.
aliases *aliases.Resolver
// Domain we use to send delivery status notifications from.
dsnDomain string
}
// New creates a new Queue instance.
func New(path string, localDomains *set.String, aliases *aliases.Resolver,
localC, remoteC courier.Courier, dsnDomain string) *Queue {
localC, remoteC courier.Courier) *Queue {
os.MkdirAll(path, 0700)
@@ -123,7 +120,6 @@ func New(path string, localDomains *set.String, aliases *aliases.Resolver,
localDomains: localDomains,
path: path,
aliases: aliases,
dsnDomain: dsnDomain,
}
}
@@ -434,7 +430,21 @@ func (item *Item) countRcpt(statuses ...Recipient_Status) int {
func sendDSN(tr *trace.Trace, q *Queue, item *Item) {
tr.Debugf("sending DSN")
msg, err := deliveryStatusNotification(q.dsnDomain, item)
// Pick a (local) domain to send the DSN from. We should always find one,
// as otherwise we're relaying.
domain := "unknown"
if item.From != "<>" && envelope.DomainIn(item.From, q.localDomains) {
domain = envelope.DomainOf(item.From)
} else {
for _, rcpt := range item.Rcpt {
if envelope.DomainIn(rcpt.OriginalAddress, q.localDomains) {
domain = envelope.DomainOf(rcpt.OriginalAddress)
break
}
}
}
msg, err := deliveryStatusNotification(domain, item)
if err != nil {
tr.Errorf("failed to build DSN: %v", err)
return