CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged between them; they stack on phones. HTML export and import keep them (also Notion column lists and Confluence page layouts). - Suggesting mode: edits become suggested insertions and deletions that editors accept or reject one by one or all at once. Text only. - Verified pages: editors verify a page for a while or without end; the verifier is notified when it runs out (migration 1764700000). - Scanned PDFs attached to pages are read by AI for search where a workspace turns it on. - The server writes error messages, emails, digests and phone notifications in English, Polish, German, French and Spanish; the apps send their language with each request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// Package mail sends Docwell's own emails (invites, notifications, test
|
|
// mails). They go out over SMTP with the same mail server configuration
|
|
// PocketBase uses for its auth emails (see SMTPSender).
|
|
package mail
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
"strings"
|
|
texttemplate "text/template"
|
|
)
|
|
|
|
// Message is one email. HTML and Text are alternative bodies.
|
|
type Message struct {
|
|
To string `json:"to"`
|
|
Subject string `json:"subject"`
|
|
HTML string `json:"html"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
// Sender delivers a message.
|
|
type Sender interface {
|
|
Send(ctx context.Context, m Message) error
|
|
}
|
|
|
|
//go:embed templates
|
|
var files embed.FS
|
|
|
|
var (
|
|
htmlTemplates = template.Must(template.ParseFS(files, "templates/*.html"))
|
|
textTemplates = texttemplate.Must(texttemplate.ParseFS(files, "templates/*.txt"))
|
|
)
|
|
|
|
// Render builds a message from the templates named name.html and name.txt.
|
|
// The first line of the text template is the subject.
|
|
func Render(to, name string, data any) (Message, error) { return RenderIn("", to, name, data) }
|
|
|
|
// RenderIn is Render in a language: from name.<lang>.html and
|
|
// name.<lang>.txt when there are such templates, else the English ones.
|
|
func RenderIn(lang, to, name string, data any) (Message, error) {
|
|
textName, htmlName := name+".txt", name+".html"
|
|
if lang != "" && textTemplates.Lookup(name+"."+lang+".txt") != nil && htmlTemplates.Lookup(name+"."+lang+".html") != nil {
|
|
textName, htmlName = name+"."+lang+".txt", name+"."+lang+".html"
|
|
}
|
|
var text, html bytes.Buffer
|
|
if err := textTemplates.ExecuteTemplate(&text, textName, data); err != nil {
|
|
return Message{}, fmt.Errorf("mail: %s: %w", textName, err)
|
|
}
|
|
if err := htmlTemplates.ExecuteTemplate(&html, htmlName, data); err != nil {
|
|
return Message{}, fmt.Errorf("mail: %s: %w", htmlName, err)
|
|
}
|
|
subject, body, _ := strings.Cut(text.String(), "\n")
|
|
return Message{To: to, Subject: strings.TrimSpace(subject), HTML: html.String(), Text: strings.TrimSpace(body) + "\n"}, nil
|
|
}
|