MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / handleForward

Method handleForward

internal/httpapi/outbound.go:314–352  ·  view source on GitHub ↗
(ctx context.Context, in *forwardInput)

Source from the content-addressed store, hash-verified

312}
313
314func (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.
355func (s *Server) validateOutboundBody(subject, body string, to, cc, bcc []string, conversationID string) *ErrorEnvelope {

Callers

nothing calls this directly

Calls 14

loadInboundMethod · 0.95
deliverMethod · 0.95
ValidateRecipientsFunction · 0.92
BuildForwardSubjectFunction · 0.92
ExtractForwardContextFunction · 0.92
BuildForwardBodyFunction · 0.92
BuildForwardHTMLBodyFunction · 0.92
ForwardAttachmentsFunction · 0.92
StripAgentSelfAliasesFunction · 0.92
NewErrorFunction · 0.85
recipientCountErrorFunction · 0.85
EmailAddressMethod · 0.80

Tested by

no test coverage detected