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

Function DeliverInbound

internal/loopback/loopback.go:215–251  ·  view source on GitHub ↗

DeliverInbound writes the recipient-side row for a loopback self-send and returns an identity.SendResult shaped for the ApproveAndSend send callback (or the worker's ExpireApproveAndSend send callback). Does NOT write the outbound row — the caller is one of: - HITL approval: the held outbound row a

(ctx context.Context, store InboundWriter, agent *identity.AgentIdentity, req outbound.SendRequest, fromDomain string)

Source from the content-addressed store, hash-verified

213// - Domain verification + rate limit are enforced upstream by the
214// caller. Loopback isn't a backdoor for those gates.
215func DeliverInbound(ctx context.Context, store InboundWriter, agent *identity.AgentIdentity, req outbound.SendRequest, fromDomain string) (identity.SendResult, error) {
216 providerID := ProviderID(fromDomain)
217 email := agent.EmailAddress()
218
219 rawMessage, err := ComposeMIME(agent, req, providerID, fromDomain)
220 if err != nil {
221 return identity.SendResult{}, fmt.Errorf("loopback compose: %w", err)
222 }
223 if _, err := store.CreateInboundMessage(
224 ctx,
225 "", // generate fresh id; mirrors the SMTP path which never reuses outbound ids
226 agent.ID,
227 email, // sender
228 email, // recipient (per-delivery target)
229 providerID,
230 req.Subject,
231 req.ConversationID,
232 "unread",
233 rawMessage,
234 nil, // no DKIM/SPF auth headers on a synthetic loopback
235 nil, // no auth verdict on a synthetic loopback
236 false, // not flagged: loopback self-send bypasses the inbound policy gate
237 "", // no flag reason
238 []string{email},
239 nil, // cc
240 nil, // reply_to
241 identity.InboundScreening{}, // loopback self-send: not externally screened
242 ); err != nil {
243 return identity.SendResult{}, fmt.Errorf("loopback inbound row: %w", err)
244 }
245
246 return identity.SendResult{
247 ProviderMessageID: providerID,
248 Method: "loopback",
249 To: []string{email},
250 }, nil
251}

Callers 2

autoApproveMethod · 0.92

Calls 4

ProviderIDFunction · 0.85
ComposeMIMEFunction · 0.85
EmailAddressMethod · 0.80
CreateInboundMessageMethod · 0.65

Tested by

no test coverage detected