MCPcopy
hub / github.com/writefreely/writefreely / emailPost

Function emailPost

email.go:320–473  ·  view source on GitHub ↗
(app *App, p *PublicPost, collID int64)

Source from the content-addressed store, hash-verified

318}
319
320func emailPost(app *App, p *PublicPost, collID int64) error {
321 p.augmentContent()
322
323 // Do some shortcode replacement.
324 // Since the user is receiving this email, we can assume they're subscribed via email.
325 p.Content = strings.Replace(p.Content, "<!--emailsub-->", `<p id="emailsub">You're subscribed to email updates.</p>`, -1)
326
327 if p.HTMLContent == template.HTML("") {
328 p.formatContent(app.cfg, false, false)
329 }
330 p.augmentReadingDestination()
331
332 title := p.Title.String
333 if title != "" {
334 title = p.Title.String + "\n\n"
335 }
336 plainMsg := title + "A new post from " + p.CanonicalURL(app.cfg.App.Host) + "\n\n" + stripmd.Strip(p.Content)
337 plainMsg += `
338
339---------------------------------------------------------------------------------
340
341Originally published on ` + p.Collection.DisplayTitle() + ` (` + p.Collection.CanonicalURL() + `), a blog you subscribe to.
342
343Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/unsubscribe/%recipient.id%?t=%recipient.token%`
344
345 mlr, err := mailer.New(app.cfg.Email)
346 if err != nil {
347 return err
348 }
349 m, err := mlr.NewMessage(p.Collection.DisplayTitle()+" <"+p.Collection.Alias+"@"+app.cfg.Email.Domain+">", stripmd.Strip(p.DisplayTitle()), plainMsg)
350 if err != nil {
351 return err
352 }
353 replyTo := app.db.GetCollectionAttribute(collID, collAttrLetterReplyTo)
354 if replyTo != "" {
355 m.SetReplyTo(replyTo)
356 }
357
358 subs, err := app.db.GetEmailSubscribers(collID, true)
359 if err != nil {
360 log.Error("Unable to get email subscribers: %v", err)
361 return err
362 }
363 if len(subs) == 0 {
364 return nil
365 }
366
367 if title != "" {
368 title = string(`<h2 id="title">` + p.FormattedDisplayTitle() + `</h2>`)
369 }
370 m.AddTag("New post")
371
372 fontFam := "Lora, Palatino, Baskerville, serif"
373 if p.IsSans() {
374 fontFam = `"Open Sans", Tahoma, Arial, sans-serif`
375 } else if p.IsMonospace() {
376 fontFam = `Hack, consolas, Menlo-Regular, Menlo, Monaco, monospace, monospace`
377 }

Callers 1

runJobsFunction · 0.85

Calls 15

SetReplyToMethod · 0.95
AddTagMethod · 0.95
SetHTMLMethod · 0.95
NewFunction · 0.92
NewMessageMethod · 0.80
GetEmailSubscribersMethod · 0.80
FormattedDisplayTitleMethod · 0.80
IsSansMethod · 0.80
IsMonospaceMethod · 0.80

Tested by

no test coverage detected