8 "github.com/mjl-/mox/dsn"
9 "github.com/mjl-/mox/queue"
10 "github.com/mjl-/mox/smtp"
11 "github.com/mjl-/mox/store"
14// compose dsn message and add it to the queue for delivery to rcptTo.
15func queueDSN(ctx context.Context, c *conn, rcptTo smtp.Path, m dsn.Message) error {
16 buf, err := m.Compose(c.log, false)
22 bufUTF8, err = m.Compose(c.log, true)
24 c.log.Errorx("composing dsn with utf-8 for incoming delivery for unknown user, continuing with ascii-only dsn", err)
28 f, err := store.CreateMessageTemp("smtp-dsn")
30 return fmt.Errorf("creating temp file: %w", err)
34 err := os.Remove(f.Name())
35 c.log.Check(err, "removing temporary dsn message file")
37 c.log.Check(err, "closing temporary dsn message file")
40 if _, err := f.Write([]byte(buf)); err != nil {
41 return fmt.Errorf("writing dsn file: %w", err)
44 // Queue DSN with null reverse path so failures to deliver will eventually drop the
45 // message instead of causing delivery loops.
48 const smtputf8 = false
49 if _, err := queue.Add(ctx, c.log, "", smtp.Path{}, rcptTo, has8bit, smtputf8, int64(len(buf)), m.MessageID, nil, f, bufUTF8, true); err != nil {
53 c.log.Check(err, "closing dsn file")