MCPcopy Index your code
hub / github.com/foxcpp/maddy / CheckBody

Method CheckBody

internal/check/dkim/dkim.go:122–255  ·  view source on GitHub ↗
(ctx context.Context, header textproto.Header, body buffer.Buffer)

Source from the content-addressed store, hash-verified

120}
121
122func (d *dkimCheckState) CheckBody(ctx context.Context, header textproto.Header, body buffer.Buffer) module.CheckResult {
123 defer trace.StartRegion(ctx, "check.dkim/CheckBody").End()
124
125 if !header.Has("DKIM-Signature") {
126 if d.c.noSigAction.Reject || d.c.noSigAction.Quarantine {
127 d.log.Printf("no signatures present")
128 } else {
129 d.log.Debugf("no signatures present")
130 }
131 return d.c.noSigAction.Apply(module.CheckResult{
132 Reason: &exterrors.SMTPError{
133 Code: 550,
134 EnhancedCode: exterrors.EnhancedCode{5, 7, 20},
135 Message: "No DKIM signatures",
136 CheckName: "check.dkim",
137 },
138 AuthResult: []authres.Result{
139 &authres.DKIMResult{
140 Value: authres.ResultNone,
141 },
142 },
143 })
144 }
145
146 b := bytes.Buffer{}
147 _ = textproto.WriteHeader(&b, header)
148 bodyRdr, err := body.Open()
149 if err != nil {
150 return module.CheckResult{
151 Reject: true,
152 Reason: exterrors.WithTemporary(
153 exterrors.WithFields(err, map[string]interface{}{
154 "check": "check.dkim",
155 "smtp_msg": "Internal I/O error",
156 }),
157 true,
158 ),
159 }
160 }
161
162 verifications, err := dkim.VerifyWithOptions(io.MultiReader(&b, bodyRdr), &dkim.VerifyOptions{
163 LookupTXT: func(domain string) ([]string, error) {
164 return d.c.resolver.LookupTXT(ctx, domain)
165 },
166 })
167 if err != nil {
168 return module.CheckResult{
169 Reject: true,
170 Reason: exterrors.WithTemporary(
171 exterrors.WithFields(err, map[string]interface{}{
172 "check": "check.dkim",
173 "smtp_msg": "Internal error during policy check",
174 }),
175 true,
176 ),
177 }
178 }
179

Callers

nothing calls this directly

Calls 9

WithTemporaryFunction · 0.92
WithFieldsFunction · 0.92
DebugfMethod · 0.80
DebugMsgMethod · 0.80
OpenMethod · 0.65
LookupTXTMethod · 0.65
PrintfMethod · 0.45
ApplyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected