mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: include missing mail headers (resolve #472)
This commit is contained in:
@ -2,18 +2,22 @@ package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const HtmlType = "text/html; charset=UTF-8"
|
||||
const PlainType = "text/html; charset=UTF-8"
|
||||
|
||||
type Mail struct {
|
||||
From MailAddress
|
||||
To MailAddresses
|
||||
Subject string
|
||||
Body string
|
||||
Type string
|
||||
From MailAddress
|
||||
To MailAddresses
|
||||
Subject string
|
||||
Body string
|
||||
Type string
|
||||
Date time.Time
|
||||
MessageID string
|
||||
}
|
||||
|
||||
func (m *Mail) WithText(text string) *Mail {
|
||||
@ -28,17 +32,36 @@ func (m *Mail) WithHTML(html string) *Mail {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) Sanitized() *Mail {
|
||||
if m.Type == "" {
|
||||
m.Type = PlainType
|
||||
}
|
||||
if m.Date.IsZero() {
|
||||
m.Date = time.Now()
|
||||
}
|
||||
if m.MessageID == "" {
|
||||
m.MessageID = fmt.Sprintf("<%s@%s>", uuid.NewV4().String(), m.From.Domain())
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) String() string {
|
||||
return fmt.Sprintf("To: %s\r\n"+
|
||||
"From: %s\r\n"+
|
||||
"Subject: %s\r\n"+
|
||||
"Message-ID: %s\r\n"+
|
||||
"MIME-Version: 1.0\r\n"+
|
||||
"Content-Type: %s\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"Date: %s\r\n"+
|
||||
"\r\n"+
|
||||
"%s\r\n",
|
||||
strings.Join(m.To.RawStrings(), ", "),
|
||||
m.From.String(),
|
||||
m.Subject,
|
||||
m.MessageID,
|
||||
m.Type,
|
||||
m.Date.Format(time.RFC1123Z),
|
||||
m.Body,
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user