8 "github.com/mjl-/mox/dsn"
9 "github.com/mjl-/mox/mlog"
10 "github.com/mjl-/mox/mox-"
11 "github.com/mjl-/mox/queue"
12 "github.com/mjl-/mox/smtp"
13 "github.com/mjl-/mox/store"
16// compose dsn message and add it to the queue for delivery to rcptTo.
17func queueDSN(ctx context.Context, log mlog.Log, c *conn, rcptTo smtp.Path, m dsn.Message, requireTLS bool) error {
18 buf, err := m.Compose(c.log, false)
22 bufDKIM, err := mox.DKIMSign(ctx, c.log, m.From, false, buf)
23 log.Check(err, "dkim signing dsn")
24 buf = append([]byte(bufDKIM), buf...)
28 bufUTF8, err = m.Compose(c.log, true)
30 c.log.Errorx("composing dsn with utf-8 for incoming delivery for unknown user, continuing with ascii-only dsn", err)
32 bufUTF8DKIM, err := mox.DKIMSign(ctx, log, m.From, true, bufUTF8)
33 log.Check(err, "dkim signing dsn with utf8")
34 bufUTF8 = append([]byte(bufUTF8DKIM), bufUTF8...)
38 f, err := store.CreateMessageTemp(c.log, "smtp-dsn")
40 return fmt.Errorf("creating temp file: %w", err)
42 defer store.CloseRemoveTempFile(c.log, f, "smtpserver dsn message")
44 if _, err := f.Write([]byte(buf)); err != nil {
45 return fmt.Errorf("writing dsn file: %w", err)
48 // Queue DSN with null reverse path so failures to deliver will eventually drop the
49 // message instead of causing delivery loops.
52 const smtputf8 = false
57 qm := queue.MakeMsg(smtp.Path{}, rcptTo, has8bit, smtputf8, int64(len(buf)), m.MessageID, nil, reqTLS, time.Now(), m.Subject)
59 if err := queue.Add(ctx, c.log, mox.Conf.Static.Postmaster.Account, f, qm); err != nil {