(app *App, p *PublicPost, collID int64)
| 318 | } |
| 319 | |
| 320 | func 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 | |
| 341 | Originally published on ` + p.Collection.DisplayTitle() + ` (` + p.Collection.CanonicalURL() + `), a blog you subscribe to. |
| 342 | |
| 343 | Sent 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 | } |
no test coverage detected