(ctx context.Context, in *forwardInput)
| 312 | } |
| 313 | |
| 314 | func (s *Server) handleForward(ctx context.Context, in *forwardInput) (*sendOutput, error) { |
| 315 | ag, inbound, user, err := s.loadInbound(ctx, in.Address, in.ID) |
| 316 | if err != nil { |
| 317 | return nil, err |
| 318 | } |
| 319 | b := in.Body |
| 320 | if len(b.To) == 0 && len(b.CC) == 0 { |
| 321 | return nil, NewError(http.StatusBadRequest, "invalid_request", "at least one recipient in to or cc is required") |
| 322 | } |
| 323 | if env := recipientCountError(b.To, b.CC, b.BCC); env != nil { |
| 324 | return nil, env |
| 325 | } |
| 326 | if e := agent.ValidateRecipients(b.To, b.CC, b.BCC); e != nil { |
| 327 | return nil, NewError(http.StatusBadRequest, "invalid_recipient", e.Error()) |
| 328 | } |
| 329 | if e := validateConversationID(b.ConversationID); e != nil { |
| 330 | return nil, NewError(http.StatusBadRequest, "invalid_request", e.Error()) |
| 331 | } |
| 332 | subject := outbound.BuildForwardSubject(inbound.Subject) |
| 333 | fwdCtx := outbound.ExtractForwardContext(inbound.RawMessage) |
| 334 | composedBody := outbound.BuildForwardBody(b.Body, fwdCtx) |
| 335 | var composedHTML string |
| 336 | if b.HTMLBody != "" || fwdCtx.HTML != "" || fwdCtx.Text != "" { |
| 337 | composedHTML = outbound.BuildForwardHTMLBody(b.HTMLBody, fwdCtx) |
| 338 | } |
| 339 | // Carry the source message's attachment parts by default (#298): a |
| 340 | // forward should ship the original files the way mail clients do, without |
| 341 | // the caller re-fetching and re-encoding each one. Caller-supplied |
| 342 | // attachments are additive on top of the originals. |
| 343 | attachments := outbound.ForwardAttachments(inbound.RawMessage) |
| 344 | attachments = append(attachments, b.Attachments...) |
| 345 | req := outbound.SendRequest{ |
| 346 | To: b.To, CC: b.CC, BCC: b.BCC, Subject: subject, Body: composedBody, HTMLBody: composedHTML, |
| 347 | ConversationID: b.ConversationID, Attachments: attachments, |
| 348 | } |
| 349 | req.CC = agent.StripAgentSelfAliases(req.CC, ag.EmailAddress()) |
| 350 | req.BCC = agent.StripAgentSelfAliases(req.BCC, ag.EmailAddress()) |
| 351 | return s.deliver(ctx, user, ag, req, "forward", inbound.EmailMessageID, "/v1/forward/"+in.ID, in.IdempotencyKey, in.RawBody, inbound) |
| 352 | } |
| 353 | |
| 354 | // validateOutboundBody runs the shared pre-send validation. |
| 355 | func (s *Server) validateOutboundBody(subject, body string, to, cc, bcc []string, conversationID string) *ErrorEnvelope { |
nothing calls this directly
no test coverage detected