use postmoogle as general purpose SMTP server and allow other apps or scripts to send emails through it
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"crypto"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||
|
||||
// MTA is mail transfer agent
|
||||
type MTA interface {
|
||||
Send(from, to, data string) error
|
||||
@@ -46,6 +49,11 @@ type ContentOptions struct {
|
||||
FromKey string
|
||||
}
|
||||
|
||||
// AddressValid checks if email address is valid
|
||||
func AddressValid(email string) bool {
|
||||
return !emailRegex.MatchString(email)
|
||||
}
|
||||
|
||||
// NewEmail constructs Email object
|
||||
func NewEmail(messageID, inReplyTo, subject, from, to, text, html string, files []*File) *Email {
|
||||
email := &Email{
|
||||
@@ -71,6 +79,14 @@ func NewEmail(messageID, inReplyTo, subject, from, to, text, html string, files
|
||||
return email
|
||||
}
|
||||
|
||||
// Mailbox returns postmoogle's mailbox, parsing it from FROM (if local=false) or TO (local=true)
|
||||
func (e *Email) Mailbox(local bool) string {
|
||||
if local {
|
||||
return Mailbox(e.To)
|
||||
}
|
||||
return Mailbox(e.From)
|
||||
}
|
||||
|
||||
// Content converts the email object to a Matrix event content
|
||||
func (e *Email) Content(threadID id.EventID, options *ContentOptions) *event.Content {
|
||||
var text strings.Builder
|
||||
|
||||
Reference in New Issue
Block a user