diff --git a/core/mail.go b/core/mail.go
index 59ff38a..ac75ea2 100644
--- a/core/mail.go
+++ b/core/mail.go
@@ -10,6 +10,7 @@ import (
"github.com/kirsle/blog/core/models/comments"
"github.com/kirsle/blog/core/models/settings"
+ "github.com/microcosm-cc/bluemonday"
gomail "gopkg.in/gomail.v2"
)
@@ -51,11 +52,28 @@ func (b *Blog) SendEmail(email Email) {
log.Error("SendEmail: template execution error: %s", err.Error())
}
+ // Condense the body down to plain text, lazily. Who even has a plain text
+ // email client anymore?
+ rawLines := strings.Split(
+ bluemonday.StrictPolicy().Sanitize(html.String()),
+ "\n",
+ )
+ var lines []string
+ for _, line := range rawLines {
+ line = strings.TrimSpace(line)
+ if len(line) == 0 {
+ continue
+ }
+ lines = append(lines, line)
+ }
+ plaintext := strings.Join(lines, "\n\n")
+
m := gomail.NewMessage()
- m.SetHeader("From", s.Mail.Sender)
+ m.SetHeader("From", fmt.Sprintf("%s <%s>", s.Site.Title, s.Mail.Sender))
m.SetHeader("To", email.To)
m.SetHeader("Subject", email.Subject)
- m.SetBody("text/html", html.String())
+ m.SetBody("text/plain", plaintext)
+ m.AddAlternative("text/html", html.String())
d := gomail.NewDialer(s.Mail.Host, s.Mail.Port, s.Mail.Username, s.Mail.Password)
if b.Debug {
diff --git a/core/middleware.go b/core/middleware.go
index 9d58f9a..dee3194 100644
--- a/core/middleware.go
+++ b/core/middleware.go
@@ -21,8 +21,6 @@ const (
// Request context.
func (b *Blog) SessionLoader(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
session, _ := b.store.Get(r, "session")
-
- log.Debug("REQUEST START: %s %s", r.Method, r.URL.Path)
ctx := context.WithValue(r.Context(), sessionKey, session)
next(w, r.WithContext(ctx))
}
@@ -95,7 +93,6 @@ func (b *Blog) LoggedIn(r *http.Request) bool {
func (b *Blog) AuthMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
u, err := b.CurrentUser(r)
if err != nil {
- log.Error("Error loading user from session: %v", err)
next(w, r)
return
}
diff --git a/core/models/comments/comments.go b/core/models/comments/comments.go
index c18a1ef..9f136d7 100644
--- a/core/models/comments/comments.go
+++ b/core/models/comments/comments.go
@@ -156,7 +156,6 @@ func (c *Comment) ParseForm(r *http.Request) {
// attribute is currently empty.
define := func(target *string, value string) {
if value != "" {
- log.Info("SET DEFINE: %s", value)
*target = value
}
}
diff --git a/core/pages.go b/core/pages.go
index 259fb47..7656d20 100644
--- a/core/pages.go
+++ b/core/pages.go
@@ -35,7 +35,7 @@ func (b *Blog) PageHandler(w http.ResponseWriter, r *http.Request) {
filepath, err := b.ResolvePath(path)
if err != nil {
// See if it resolves as a blog entry.
- err = b.viewPost(w, r, path)
+ err = b.viewPost(w, r, strings.TrimLeft(path, "/"))
if err != nil {
b.NotFound(w, r, "The page you were looking for was not found.")
}
diff --git a/root/.email/comment.gohtml b/root/.email/comment.gohtml
index 4c7c403..e930651 100644
--- a/root/.email/comment.gohtml
+++ b/root/.email/comment.gohtml
@@ -42,7 +42,7 @@
{{ if .UnsubscribeURL }}
- To unsubscribe from this message, visit {{ .UnsubscribeURL }}
+ To unsubscribe from this comment thread, visit {{ .UnsubscribeURL }}
{{ end }}