Fix santa bug, email subject encoding, closes #65
parent
9a0f1f22b8
commit
ec7e58a6a2
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"heckel.io/ntfy/util"
|
||||
"mime"
|
||||
"net"
|
||||
"net/smtp"
|
||||
"strings"
|
||||
|
@ -28,6 +29,7 @@ func (s *smtpMailer) Send(senderIP, to string, m *message) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
println(message)
|
||||
auth := smtp.PlainAuth("", s.config.SMTPUser, s.config.SMTPPass, host)
|
||||
return smtp.SendMail(s.config.SMTPAddr, auth, s.config.SMTPFrom, []string{to}, []byte(message))
|
||||
}
|
||||
|
@ -66,10 +68,11 @@ func formatMail(baseURL, senderIP, from, to string, m *message) (string, error)
|
|||
if trailer != "" {
|
||||
message += "\n\n" + trailer
|
||||
}
|
||||
body := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "{shortTopicURL}" <{from}>
|
||||
subject = mime.BEncoding.Encode("utf-8", subject)
|
||||
body := `From: "{shortTopicURL}" <{from}>
|
||||
To: {to}
|
||||
Subject: {subject}
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
{message}
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ func TestFormatMail_Basic(t *testing.T) {
|
|||
Topic: "alerts",
|
||||
Message: "A simple message",
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: A simple message
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A simple message
|
||||
|
||||
|
@ -34,10 +34,10 @@ func TestFormatMail_JustEmojis(t *testing.T) {
|
|||
Message: "A simple message",
|
||||
Tags: []string{"grinning"},
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: 😀 A simple message
|
||||
Subject: =?utf-8?b?8J+YgCBBIHNpbXBsZSBtZXNzYWdl?=
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A simple message
|
||||
|
||||
|
@ -55,10 +55,10 @@ func TestFormatMail_JustOtherTags(t *testing.T) {
|
|||
Message: "A simple message",
|
||||
Tags: []string{"not-an-emoji"},
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: A simple message
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A simple message
|
||||
|
||||
|
@ -78,10 +78,10 @@ func TestFormatMail_JustPriority(t *testing.T) {
|
|||
Message: "A simple message",
|
||||
Priority: 2,
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: A simple message
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A simple message
|
||||
|
||||
|
@ -101,10 +101,10 @@ func TestFormatMail_UTF8Subject(t *testing.T) {
|
|||
Message: "A simple message",
|
||||
Title: " :: A not so simple title öäüß ¡Hola, señor!",
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: :: A not so simple title öäüß ¡Hola, señor!
|
||||
Subject: =?utf-8?b?IDo6IEEgbm90IHNvIHNpbXBsZSB0aXRsZSDDtsOkw7zDnyDCoUhvbGEsIHNl?= =?utf-8?b?w7FvciE=?=
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A simple message
|
||||
|
||||
|
@ -124,10 +124,10 @@ func TestFormatMail_WithAllTheThings(t *testing.T) {
|
|||
Title: "Oh no 🙈\nThis is a message across\nmultiple lines",
|
||||
Message: "A message that contains monkeys 🙉\nNo really, though. Monkeys!",
|
||||
})
|
||||
expected := `Content-Type: text/plain; charset="utf-8"
|
||||
From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
expected := `From: "ntfy.sh/alerts" <ntfy@ntfy.sh>
|
||||
To: phil@example.com
|
||||
Subject: ⚠️ 💀 Oh no 🙈 This is a message across multiple lines
|
||||
Subject: =?utf-8?b?4pqg77iPIPCfkoAgT2ggbm8g8J+ZiCBUaGlzIGlzIGEgbWVzc2FnZSBhY3Jv?= =?utf-8?b?c3MgbXVsdGlwbGUgbGluZXM=?=
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
A message that contains monkeys 🙉
|
||||
No really, though. Monkeys!
|
||||
|
|
Loading…
Reference in New Issue