mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
9e7d6b85b7
transferring the data only once. we only do this when the recipient domains are the same. when queuing, we now take care to set the same NextAttempt timestamp, so queued messages are actually eligable for combined delivery. this adds a DeliverMultiple to the smtp client. for pipelined requests, it will send all RCPT TO (and MAIL and DATA) in one go, and handles the various responses and error conditions, returning either an overal error, or per recipient smtp responses. the results of the smtp LIMITS extension are also available in the smtp client now. this also takes the "LIMITS RCPTMAX" smtp extension into account: if the server only accepts a single recipient, we won't send multiple. if a server doesn't announce a RCPTMAX limit, but still has one (like mox does for non-spf-verified transactions), we'll recognize code 452 and 552 (for historic reasons) as temporary error, and try again in a separate transaction immediately after. we don't yet implement "LIMITS MAILMAX", doesn't seem likely in practice.
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package smtpserver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/mjl-/mox/dsn"
|
|
"github.com/mjl-/mox/mlog"
|
|
"github.com/mjl-/mox/mox-"
|
|
"github.com/mjl-/mox/queue"
|
|
"github.com/mjl-/mox/smtp"
|
|
"github.com/mjl-/mox/store"
|
|
)
|
|
|
|
// compose dsn message and add it to the queue for delivery to rcptTo.
|
|
func queueDSN(ctx context.Context, log mlog.Log, c *conn, rcptTo smtp.Path, m dsn.Message, requireTLS bool) error {
|
|
buf, err := m.Compose(c.log, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
bufDKIM, err := mox.DKIMSign(ctx, c.log, m.From, false, buf)
|
|
log.Check(err, "dkim signing dsn")
|
|
buf = append([]byte(bufDKIM), buf...)
|
|
|
|
var bufUTF8 []byte
|
|
if c.smtputf8 {
|
|
bufUTF8, err = m.Compose(c.log, true)
|
|
if err != nil {
|
|
c.log.Errorx("composing dsn with utf-8 for incoming delivery for unknown user, continuing with ascii-only dsn", err)
|
|
} else {
|
|
bufUTF8DKIM, err := mox.DKIMSign(ctx, log, m.From, true, bufUTF8)
|
|
log.Check(err, "dkim signing dsn with utf8")
|
|
bufUTF8 = append([]byte(bufUTF8DKIM), bufUTF8...)
|
|
}
|
|
}
|
|
|
|
f, err := store.CreateMessageTemp(c.log, "smtp-dsn")
|
|
if err != nil {
|
|
return fmt.Errorf("creating temp file: %w", err)
|
|
}
|
|
defer store.CloseRemoveTempFile(c.log, f, "smtpserver dsn message")
|
|
|
|
if _, err := f.Write([]byte(buf)); err != nil {
|
|
return fmt.Errorf("writing dsn file: %w", err)
|
|
}
|
|
|
|
// Queue DSN with null reverse path so failures to deliver will eventually drop the
|
|
// message instead of causing delivery loops.
|
|
// ../rfc/3464:433
|
|
const has8bit = false
|
|
const smtputf8 = false
|
|
var reqTLS *bool
|
|
if requireTLS {
|
|
reqTLS = &requireTLS
|
|
}
|
|
qm := queue.MakeMsg(smtp.Path{}, rcptTo, has8bit, smtputf8, int64(len(buf)), m.MessageID, nil, reqTLS, time.Now())
|
|
qm.DSNUTF8 = bufUTF8
|
|
if err := queue.Add(ctx, c.log, "", f, qm); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|