MCPcopy
hub / github.com/pocketbase/pocketbase / resolveEmailTemplate

Function resolveEmailTemplate

mails/record.go:251–303  ·  view source on GitHub ↗
(
	app core.App,
	authRecord *core.Record,
	emailTemplate core.EmailTemplate,
	placeholders map[string]any,
)

Source from the content-addressed store, hash-verified

249}
250
251func resolveEmailTemplate(
252 app core.App,
253 authRecord *core.Record,
254 emailTemplate core.EmailTemplate,
255 placeholders map[string]any,
256) (subject string, body string, err error) {
257 if placeholders == nil {
258 placeholders = map[string]any{}
259 }
260
261 // register default system placeholders
262 if _, ok := placeholders[core.EmailPlaceholderAppName]; !ok {
263 placeholders[core.EmailPlaceholderAppName] = app.Settings().Meta.AppName
264 }
265 if _, ok := placeholders[core.EmailPlaceholderAppURL]; !ok {
266 placeholders[core.EmailPlaceholderAppURL] = app.Settings().Meta.AppURL
267 }
268
269 // register default auth record placeholders
270 for _, field := range authRecord.Collection().Fields {
271 if field.GetHidden() {
272 continue
273 }
274
275 fieldPlacehodler := "{RECORD:" + field.GetName() + "}"
276 if _, ok := placeholders[fieldPlacehodler]; !ok {
277 val := authRecord.GetString(field.GetName())
278
279 // note: the escaping is not strictly necessary but for just in case
280 // the user decide to store and render the email as plain html
281 if !slices.Contains(nonescapeTypes, field.Type()) {
282 val = html.EscapeString(val)
283 }
284
285 placeholders[fieldPlacehodler] = val
286 }
287 }
288
289 subject, rawBody := emailTemplate.Resolve(placeholders)
290
291 params := struct {
292 HTMLContent template.HTML
293 }{
294 HTMLContent: template.HTML(rawBody),
295 }
296
297 body, err = resolveTemplateContent(params, templates.Layout, templates.HTMLBody)
298 if err != nil {
299 return "", "", err
300 }
301
302 return subject, body, nil
303}

Callers 5

SendRecordAuthAlertFunction · 0.85
SendRecordOTPFunction · 0.85
SendRecordPasswordResetFunction · 0.85
SendRecordVerificationFunction · 0.85
SendRecordChangeEmailFunction · 0.85

Calls 9

resolveTemplateContentFunction · 0.85
CollectionMethod · 0.80
GetStringMethod · 0.80
HTMLMethod · 0.80
SettingsMethod · 0.65
GetHiddenMethod · 0.65
GetNameMethod · 0.65
TypeMethod · 0.65
ResolveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…