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

Function ComposeMIME

internal/loopback/loopback.go:116–180  ·  view source on GitHub ↗

ComposeMIME builds the RFC 5322 / 2046 message bytes the inbound row will store as raw_message. Delegates to the same composer the real SMTP path uses (outbound.ComposeMessageWithAttachments) so the produced message is byte-equivalent to what an external roundtrip would have generated — same header

(agent *identity.AgentIdentity, req outbound.SendRequest, providerID, fromDomain string)

Source from the content-addressed store, hash-verified

114// approval finalizer preserve In-Reply-To / References headers — same
115// shape an SMTP-routed reply would carry.
116func ComposeMIME(agent *identity.AgentIdentity, req outbound.SendRequest, providerID, fromDomain string) ([]byte, error) {
117 email := agent.EmailAddress()
118 headerFrom := fmt.Sprintf("%q <%s>", agent.Name, email)
119 if agent.Name == "" {
120 headerFrom = email
121 }
122
123 var msg []byte
124 var err error
125 if len(req.Attachments) > 0 {
126 msg, err = outbound.ComposeMessageWithAttachments(
127 headerFrom,
128 []string{email},
129 nil, // cc
130 req.Subject,
131 req.Body,
132 req.HTMLBody,
133 req.ReplyToMessageID,
134 req.References,
135 fromDomain,
136 "", // reply_to header
137 req.ConversationID,
138 req.Attachments,
139 )
140 } else {
141 // No attachments → simpler single-part path. Lets us keep the
142 // stored MIME small for the common "note to self" case rather
143 // than always emitting a multipart envelope.
144 contentType := "text/plain"
145 body := req.Body
146 if req.HTMLBody != "" {
147 contentType = "text/html"
148 body = req.HTMLBody
149 }
150 msg, err = outbound.ComposeMessage(
151 headerFrom,
152 []string{email},
153 nil, // cc
154 req.Subject,
155 body,
156 contentType,
157 req.ReplyToMessageID,
158 req.References,
159 fromDomain,
160 "", // reply_to header
161 req.ConversationID,
162 )
163 }
164 if err != nil {
165 return nil, err
166 }
167
168 host := fromDomain
169 if host == "" {
170 host = "e2a.local"
171 }
172 received := fmt.Sprintf(
173 "Received: by %s (e2a) with loopback id %s for <%s>;\r\n\t%s\r\n",

Callers 2

performSelfSendMethod · 0.92
DeliverInboundFunction · 0.85

Calls 3

ComposeMessageFunction · 0.92
EmailAddressMethod · 0.80

Tested by

no test coverage detected