Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package email
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func newUnsubscribeToken() (string, error) {
|
||||
b := make([]byte, 32)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base64.RawURLEncoding.EncodeToString(b), nil
|
||||
}
|
||||
|
||||
func UnsubscribeURL(publicAPIURL, token string) string {
|
||||
base := strings.TrimRight(strings.TrimSpace(publicAPIURL), "/")
|
||||
if base == "" {
|
||||
base = "http://localhost:8080"
|
||||
}
|
||||
return fmt.Sprintf("%s/api/public/unsubscribe?token=%s", base, token)
|
||||
}
|
||||
|
||||
func UnsubscribePageURL(webOrigin, token string) string {
|
||||
base := strings.TrimRight(strings.TrimSpace(webOrigin), "/")
|
||||
if base == "" {
|
||||
base = "http://localhost:5174"
|
||||
}
|
||||
return fmt.Sprintf("%s/unsubscribe?token=%s", base, token)
|
||||
}
|
||||
|
||||
func listUnsubscribeHeaders(oneClickURL, mailtoFallback string) map[string]string {
|
||||
h := map[string]string{
|
||||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
}
|
||||
parts := make([]string, 0, 2)
|
||||
if oneClickURL != "" {
|
||||
parts = append(parts, "<"+oneClickURL+">")
|
||||
}
|
||||
if mailtoFallback != "" {
|
||||
parts = append(parts, "<mailto:"+mailtoFallback+">")
|
||||
}
|
||||
if len(parts) > 0 {
|
||||
h["List-Unsubscribe"] = strings.Join(parts, ", ")
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
func injectUnsubscribeFooter(html, text, pageURL string) (string, string) {
|
||||
link := strings.TrimSpace(pageURL)
|
||||
if link == "" {
|
||||
return html, text
|
||||
}
|
||||
footerHTML := fmt.Sprintf(
|
||||
`<hr style="border:none;border-top:1px solid #e5e7eb;margin:24px 0"/><p style="font-size:12px;color:#6b7280">You received this email because you opted in to marketing from this store. <a href="%s">Unsubscribe</a>.</p>`,
|
||||
link,
|
||||
)
|
||||
footerText := fmt.Sprintf("\n\n---\nUnsubscribe: %s\n", link)
|
||||
if strings.TrimSpace(html) != "" && !strings.Contains(strings.ToLower(html), "unsubscribe") {
|
||||
html = html + footerHTML
|
||||
}
|
||||
if strings.TrimSpace(text) != "" && !strings.Contains(strings.ToLower(text), "unsubscribe") {
|
||||
text = text + footerText
|
||||
} else if strings.TrimSpace(text) == "" && strings.TrimSpace(html) != "" {
|
||||
text = "Unsubscribe: " + link
|
||||
}
|
||||
return html, text
|
||||
}
|
||||
Reference in New Issue
Block a user