MCPcopy Create free account
hub / github.com/foxcpp/maddy / WriteTo

Method WriteTo

internal/dsn/dsn.go:55–104  ·  view source on GitHub ↗
(utf8 bool, w io.Writer)

Source from the content-addressed store, hash-verified

53}
54
55func (info ReportingMTAInfo) WriteTo(utf8 bool, w io.Writer) error {
56 // DSN format uses structure similar to MIME header, so we reuse
57 // MIME generator here.
58 h := textproto.Header{}
59
60 if info.ReportingMTA == "" {
61 return errors.New("dsn: Reporting-MTA field is mandatory")
62 }
63
64 reportingMTA, err := dns.SelectIDNA(utf8, info.ReportingMTA)
65 if err != nil {
66 return fmt.Errorf("dsn: cannot convert Reporting-MTA to a suitable representation: %w", err)
67 }
68
69 h.Add("Reporting-MTA", "dns; "+reportingMTA)
70
71 if info.ReceivedFromMTA != "" {
72 receivedFromMTA, err := dns.SelectIDNA(utf8, info.ReceivedFromMTA)
73 if err != nil {
74 return fmt.Errorf("dsn: cannot convert Received-From-MTA to a suitable representation: %w", err)
75 }
76
77 h.Add("Received-From-MTA", "dns; "+receivedFromMTA)
78 }
79
80 if info.XSender != "" {
81 sender, err := address.SelectIDNA(utf8, info.XSender)
82 if err != nil {
83 return fmt.Errorf("dsn: cannot convert X-Maddy-Sender to a suitable representation: %w", err)
84 }
85
86 if utf8 {
87 h.Add("X-Maddy-Sender", "utf8; "+sender)
88 } else {
89 h.Add("X-Maddy-Sender", "rfc822; "+sender)
90 }
91 }
92 if info.XMessageID != "" {
93 h.Add("X-Maddy-MsgID", info.XMessageID)
94 }
95
96 if !info.ArrivalDate.IsZero() {
97 h.Add("Arrival-Date", info.ArrivalDate.Format("Mon, 2 Jan 2006 15:04:05 -0700"))
98 }
99 if !info.ArrivalDate.IsZero() {
100 h.Add("Last-Attempt-Date", info.LastAttemptDate.Format("Mon, 2 Jan 2006 15:04:05 -0700"))
101 }
102
103 return textproto.WriteHeader(w, h)
104}
105
106type Action string
107

Callers

nothing calls this directly

Calls 3

SelectIDNAFunction · 0.92
SelectIDNAFunction · 0.92
AddMethod · 0.80

Tested by

no test coverage detected