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

Method performSelfSend

internal/agent/selfsend.go:50–107  ·  view source on GitHub ↗

performSelfSend writes the message as BOTH an outbound row (sender's sent history) and an inbound row (recipient's inbox). Mirrors the two-row shape the SMTP roundtrip would produce naturally, so list_messages, threading, and downstream tooling don't need any special-casing. This is the non-HITL fa

(
	ctx context.Context,
	agent *identity.AgentIdentity,
	req outbound.SendRequest,
	msgType string,
)

Source from the content-addressed store, hash-verified

48// fork the audit shape from the SMTP branch (which records the
49// caller's actual intent).
50func (a *API) performSelfSend(
51 ctx context.Context,
52 agent *identity.AgentIdentity,
53 req outbound.SendRequest,
54 msgType string,
55) (string, error) {
56 email := agent.EmailAddress()
57
58 // Allocate providerID up front so the outbound row and inbound row
59 // reference the same Message-ID — matching the two-row shape an
60 // SMTP roundtrip produces.
61 providerID := loopback.ProviderID(a.fromDomain)
62
63 if _, err := a.store.CreateOutboundMessage(
64 ctx,
65 agent.ID,
66 []string{email},
67 nil,
68 nil,
69 req.Subject,
70 msgType,
71 "loopback",
72 providerID,
73 req.ConversationID,
74 nil, // self-send body is retained on the inbound twin row; don't double-store
75 ); err != nil {
76 return "", fmt.Errorf("self-send outbound row: %w", err)
77 }
78
79 rawMessage, err := loopback.ComposeMIME(agent, req, providerID, a.fromDomain)
80 if err != nil {
81 return "", fmt.Errorf("self-send compose: %w", err)
82 }
83 if _, err := a.store.CreateInboundMessage(
84 ctx,
85 "",
86 agent.ID,
87 email,
88 email,
89 providerID,
90 req.Subject,
91 req.ConversationID,
92 "unread",
93 rawMessage,
94 nil,
95 nil,
96 false,
97 "",
98 []string{email},
99 nil,
100 nil,
101 identity.InboundScreening{}, // self-send: not externally screened
102 ); err != nil {
103 return "", fmt.Errorf("self-send inbound row: %w", err)
104 }
105
106 return providerID, nil
107}

Callers 1

DeliverOutboundMethod · 0.95

Calls 5

ProviderIDFunction · 0.92
ComposeMIMEFunction · 0.92
EmailAddressMethod · 0.80
CreateOutboundMessageMethod · 0.80
CreateInboundMessageMethod · 0.65

Tested by

no test coverage detected