mirror of https://github.com/muety/wakapi.git
Compare commits
2 Commits
ce077f2efc
...
46a248ac30
Author | SHA1 | Date |
---|---|---|
Ferdinand Mütsch | 46a248ac30 | |
Ferdinand Mütsch | fde45a5138 |
|
@ -256,7 +256,7 @@ Wakapi plays well together with [WakaTime](https://wakatime.com). For one thing,
|
||||||
|
|
||||||
### GitHub Readme Stats integrations
|
### GitHub Readme Stats integrations
|
||||||
|
|
||||||
Wakapi also integrates with [GitHub Readme Stats](https://github.com/anuraghazra/github-readme-stats#wakatime-week-stats) to generate fancy cards for you. Here is an example.
|
Wakapi also integrates with [GitHub Readme Stats](https://github.com/anuraghazra/github-readme-stats#wakatime-week-stats) to generate fancy cards for you. Here is an example. To use this, don't forget to **enable public data** under [Settings -> Permissions](https://wakapi.dev/settings#permissions).
|
||||||
|
|
||||||
![](https://github-readme-stats.vercel.app/api/wakatime?username=n1try&api_domain=wakapi.dev&bg_color=2D3748&title_color=2F855A&icon_color=2F855A&text_color=ffffff&custom_title=Wakapi%20Week%20Stats&layout=compact)
|
![](https://github-readme-stats.vercel.app/api/wakatime?username=n1try&api_domain=wakapi.dev&bg_color=2D3748&title_color=2F855A&icon_color=2F855A&text_color=ffffff&custom_title=Wakapi%20Week%20Stats&layout=compact)
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ Wakapi also integrates with [GitHub Readme Stats](https://github.com/anuraghazra
|
||||||
|
|
||||||
### Github Readme Metrics integration
|
### Github Readme Metrics integration
|
||||||
|
|
||||||
There is a [WakaTime plugin](https://github.com/lowlighter/metrics/tree/master/source/plugins/wakatime) for GitHub [Metrics](https://github.com/lowlighter/metrics/) that is also compatible with Wakapi.
|
There is a [WakaTime plugin](https://github.com/lowlighter/metrics/tree/master/source/plugins/wakatime) for GitHub [Metrics](https://github.com/lowlighter/metrics/) that is also compatible with Wakapi. To use this, don't forget to **enable public data** under [Settings -> Permissions](https://wakapi.dev/settings#permissions).
|
||||||
|
|
||||||
Preview:
|
Preview:
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,22 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HtmlType = "text/html; charset=UTF-8"
|
const HtmlType = "text/html; charset=UTF-8"
|
||||||
const PlainType = "text/html; charset=UTF-8"
|
const PlainType = "text/html; charset=UTF-8"
|
||||||
|
|
||||||
type Mail struct {
|
type Mail struct {
|
||||||
From MailAddress
|
From MailAddress
|
||||||
To MailAddresses
|
To MailAddresses
|
||||||
Subject string
|
Subject string
|
||||||
Body string
|
Body string
|
||||||
Type string
|
Type string
|
||||||
|
Date time.Time
|
||||||
|
MessageID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mail) WithText(text string) *Mail {
|
func (m *Mail) WithText(text string) *Mail {
|
||||||
|
@ -28,17 +32,36 @@ func (m *Mail) WithHTML(html string) *Mail {
|
||||||
return m
|
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 {
|
func (m *Mail) String() string {
|
||||||
return fmt.Sprintf("To: %s\r\n"+
|
return fmt.Sprintf("To: %s\r\n"+
|
||||||
"From: %s\r\n"+
|
"From: %s\r\n"+
|
||||||
"Subject: %s\r\n"+
|
"Subject: %s\r\n"+
|
||||||
|
"Message-ID: %s\r\n"+
|
||||||
|
"MIME-Version: 1.0\r\n"+
|
||||||
"Content-Type: %s\r\n"+
|
"Content-Type: %s\r\n"+
|
||||||
|
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||||
|
"Date: %s\r\n"+
|
||||||
"\r\n"+
|
"\r\n"+
|
||||||
"%s\r\n",
|
"%s\r\n",
|
||||||
strings.Join(m.To.RawStrings(), ", "),
|
strings.Join(m.To.RawStrings(), ", "),
|
||||||
m.From.String(),
|
m.From.String(),
|
||||||
m.Subject,
|
m.Subject,
|
||||||
|
m.MessageID,
|
||||||
m.Type,
|
m.Type,
|
||||||
|
m.Date.Format(time.RFC1123Z),
|
||||||
m.Body,
|
m.Body,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "regexp"
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MailPattern = "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+"
|
MailPattern = "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+"
|
||||||
|
@ -36,6 +39,14 @@ func (m MailAddress) Raw() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m MailAddress) Domain() string {
|
||||||
|
split := strings.Split(m.Raw(), "@")
|
||||||
|
if len(split) != 2 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return split[1]
|
||||||
|
}
|
||||||
|
|
||||||
func (m MailAddress) Valid() bool {
|
func (m MailAddress) Valid() bool {
|
||||||
return emailAddrRegex.Match([]byte(m))
|
return emailAddrRegex.Match([]byte(m))
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ func NewSMTPSendingService(config conf.SMTPMailConfig) *SMTPSendingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SMTPSendingService) Send(mail *models.Mail) error {
|
func (s *SMTPSendingService) Send(mail *models.Mail) error {
|
||||||
|
mail = mail.Sanitized()
|
||||||
|
|
||||||
dial := smtp.Dial
|
dial := smtp.Dial
|
||||||
if s.config.TLS {
|
if s.config.TLS {
|
||||||
dial = func(addr string) (*smtp.Client, error) {
|
dial = func(addr string) (*smtp.Client, error) {
|
||||||
|
|
Loading…
Reference in New Issue