| 334 | } |
| 335 | |
| 336 | func (s *Session) Rcpt(to string, opts *smtp.RcptOptions) error { |
| 337 | s.msgLock.Lock() |
| 338 | defer s.msgLock.Unlock() |
| 339 | |
| 340 | // deferServerReject = true and this is the first RCPT TO command. |
| 341 | if s.delivery == nil { |
| 342 | // If we already attempted to initialize the delivery - |
| 343 | // fail again. |
| 344 | if s.deliveryErr != nil { |
| 345 | s.repeatedMailErrs++ |
| 346 | // The deliveryErr is already wrapped. |
| 347 | return s.deliveryErr |
| 348 | } |
| 349 | |
| 350 | // It will initialize s.msgCtx. |
| 351 | msgID, err := s.startDelivery(s.sessionCtx, s.mailFrom, s.opts) |
| 352 | if err != nil { |
| 353 | if !errors.Is(err, context.DeadlineExceeded) { |
| 354 | s.log.Error("MAIL FROM error (deferred)", err, "rcpt", to, "msg_id", msgID) |
| 355 | } |
| 356 | s.deliveryErr = s.endp.wrapErr(msgID, !s.opts.UTF8, "RCPT", err) |
| 357 | return s.deliveryErr |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | rcptCtx, rcptTask := trace.NewTask(s.msgCtx, "RCPT TO") |
| 362 | defer rcptTask.End() |
| 363 | |
| 364 | if err := s.rcpt(rcptCtx, to, opts); err != nil { |
| 365 | if s.loggedRcptErrors < s.endp.maxLoggedRcptErrors { |
| 366 | s.log.Error("RCPT error", err, "rcpt", to, "msg_id", s.msgMeta.ID) |
| 367 | s.loggedRcptErrors++ |
| 368 | if s.loggedRcptErrors == s.endp.maxLoggedRcptErrors { |
| 369 | s.log.Msg("too many RCPT errors, possible dictonary attack", "src_ip", s.connState.RemoteAddr, "msg_id", s.msgMeta.ID) |
| 370 | } |
| 371 | } |
| 372 | return s.endp.wrapErr(s.msgMeta.ID, !s.opts.UTF8, "RCPT", err) |
| 373 | } |
| 374 | s.endp.log.Msg("RCPT ok", "rcpt", to, "msg_id", s.msgMeta.ID) |
| 375 | return nil |
| 376 | } |
| 377 | |
| 378 | func (s *Session) rcpt(ctx context.Context, to string, opts *smtp.RcptOptions) error { |
| 379 | // INTERNATIONALIZATION: Do not permit non-ASCII addresses unless SMTPUTF8 is |