aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-03-08 17:47:48 +0530
committerBobby <[email protected]>2026-03-08 17:47:48 +0530
commitf48054e9bc5e4fb36b9aba9126c6ace9c5b1f470 (patch)
tree0e993ddab1229ba7efccbb757987addb86effbe3 /utils
parent2d5fb5e2078e92e7ec19582c3954409dd93f89fd (diff)
downloaddove-f48054e9bc5e4fb36b9aba9126c6ace9c5b1f470.tar.xz
dove-f48054e9bc5e4fb36b9aba9126c6ace9c5b1f470.zip
feat(domains): enhance domain management UI with DNS records functionality
- Updated domain detail view to include DNS records management links. - Added new DNS records creation form with dynamic fields based on record type. - Implemented backend logic for creating and deleting DNS records. - Introduced new services and messages for DNS operations. - Refactored SMTP server initialization to streamline TLS configuration. - Added email composition and submission utilities for better email handling.
Diffstat (limited to 'utils')
-rw-r--r--utils/email/compose.go75
-rw-r--r--utils/email/messages.go7
-rw-r--r--utils/email/submit.go37
-rw-r--r--utils/smtp/messages.go3
-rw-r--r--utils/smtp/server.go38
5 files changed, 141 insertions, 19 deletions
diff --git a/utils/email/compose.go b/utils/email/compose.go
new file mode 100644
index 0000000..0537bbb
--- /dev/null
+++ b/utils/email/compose.go
@@ -0,0 +1,75 @@
+package email
+
+import (
+ "fmt"
+ "net/mail"
+ "strings"
+ "time"
+)
+
+type ComposeRequest struct {
+ MessageID string
+ FromAddress string
+ FromName string
+ ToAddresses string
+ CcAddresses string
+ Subject string
+ HTMLBody string
+}
+
+func Compose(request ComposeRequest) []byte {
+ var message strings.Builder
+
+ fromHeader := formatMailAddress(request.FromName, request.FromAddress)
+ message.WriteString(fmt.Sprintf("From: %s\r\n", fromHeader))
+ message.WriteString(fmt.Sprintf("To: %s\r\n", request.ToAddresses))
+
+ if request.CcAddresses != "" {
+ message.WriteString(fmt.Sprintf("Cc: %s\r\n", request.CcAddresses))
+ }
+
+ message.WriteString(fmt.Sprintf("Subject: %s\r\n", request.Subject))
+ message.WriteString(fmt.Sprintf("Date: %s\r\n", time.Now().Format(time.RFC1123Z)))
+ message.WriteString(fmt.Sprintf("Message-ID: %s\r\n", request.MessageID))
+ message.WriteString("MIME-Version: 1.0\r\n")
+ message.WriteString("Content-Type: text/html; charset=UTF-8\r\n")
+ message.WriteString("\r\n")
+ message.WriteString(request.HTMLBody)
+
+ return []byte(message.String())
+}
+
+func EnvelopeRecipients(toAddresses string, ccAddresses string, bccAddresses string) []string {
+ var recipients []string
+
+ for _, addressGroup := range []string{toAddresses, ccAddresses, bccAddresses} {
+ if addressGroup == "" {
+ continue
+ }
+
+ parsed, parseError := mail.ParseAddressList(addressGroup)
+ if parseError != nil {
+ for _, raw := range strings.Split(addressGroup, AddressJoiner) {
+ trimmed := strings.TrimSpace(raw)
+ if trimmed != "" {
+ recipients = append(recipients, trimmed)
+ }
+ }
+ continue
+ }
+
+ for _, address := range parsed {
+ recipients = append(recipients, address.Address)
+ }
+ }
+
+ return recipients
+}
+
+func formatMailAddress(displayName string, emailAddress string) string {
+ if displayName == "" {
+ return emailAddress
+ }
+
+ return fmt.Sprintf("\"%s\" <%s>", displayName, emailAddress)
+}
diff --git a/utils/email/messages.go b/utils/email/messages.go
new file mode 100644
index 0000000..e4b5a76
--- /dev/null
+++ b/utils/email/messages.go
@@ -0,0 +1,7 @@
+package email
+
+const (
+ SubmitFailed = "Failed to submit message through local SMTP: %v"
+ SubmitSuccess = "Message submitted from %s to %v."
+ SubmittingMessage = "Submitting message from %s to %v via %s."
+)
diff --git a/utils/email/submit.go b/utils/email/submit.go
new file mode 100644
index 0000000..255c630
--- /dev/null
+++ b/utils/email/submit.go
@@ -0,0 +1,37 @@
+package email
+
+import (
+ "dove/config"
+ "dove/utils/logger"
+ "fmt"
+ "net/smtp"
+)
+
+func Submit(senderAddress string, recipients []string, rawMessage []byte) error {
+ serverAddress := resolveLocalSMTPAddress()
+
+ logger.Debugf(LogPrefix, SubmittingMessage, senderAddress, recipients, serverAddress)
+
+ var smtpAuth smtp.Auth
+ if config.SMTP.AuthRequired {
+ smtpAuth = smtp.PlainAuth("", config.SMTP.Username, config.SMTP.Password, config.SMTP.Host)
+ }
+
+ sendError := smtp.SendMail(serverAddress, smtpAuth, senderAddress, recipients, rawMessage)
+ if sendError != nil {
+ logger.Errorf(LogPrefix, SubmitFailed, sendError)
+ return sendError
+ }
+
+ logger.Infof(LogPrefix, SubmitSuccess, senderAddress, recipients)
+ return nil
+}
+
+func resolveLocalSMTPAddress() string {
+ host := config.SMTP.Host
+ if host == "0.0.0.0" || host == "::" {
+ host = "127.0.0.1"
+ }
+
+ return fmt.Sprintf("%s:%d", host, config.SMTP.Port)
+}
diff --git a/utils/smtp/messages.go b/utils/smtp/messages.go
index 6441fde..1c82ab6 100644
--- a/utils/smtp/messages.go
+++ b/utils/smtp/messages.go
@@ -13,9 +13,6 @@ const (
NoLocalRecipients = "No local recipients found for message from %s."
Recipient = "Recipient: %s"
RecipientNotLocal = "Recipient %s is not a local mailbox."
- RelayDeliveryFailed = "Failed to relay message to %s: %v"
- RelayDeliverySuccess = "Relayed message to %s via %s:%d."
- RelayDisabled = "Relay disabled. External recipient %s will not receive the message."
ServerStarting = "%s listener started on %s."
SessionStarted = "New session from %s."
ShutdownComplete = "All listeners stopped."
diff --git a/utils/smtp/server.go b/utils/smtp/server.go
index 5260d20..0518ed7 100644
--- a/utils/smtp/server.go
+++ b/utils/smtp/server.go
@@ -18,28 +18,34 @@ type ServerInstance struct {
var activeServers []ServerInstance
func Start() {
+ var tlsConfig *tls.Config
+ if config.SMTP.TLSEnabled {
+ tlsConfig = loadTLSConfig()
+ }
+
plainAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.Port)
plainServer := createServer(plainAddress)
activeServers = append(activeServers, ServerInstance{Server: plainServer, Label: "SMTP"})
go startListener(plainServer, "SMTP", plainAddress)
- if config.SMTP.TLSEnabled {
- tlsConfig := loadTLSConfig()
- if tlsConfig != nil {
- smtpsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.SMTPSPort)
- smtpsServer := createServer(smtpsAddress)
- smtpsServer.TLSConfig = tlsConfig
- activeServers = append(activeServers, ServerInstance{Server: smtpsServer, Label: "SMTPS"})
- go startTLSListener(smtpsServer, "SMTPS", smtpsAddress)
-
- starttlsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.StartTLSPort)
- starttlsServer := createServer(starttlsAddress)
- starttlsServer.TLSConfig = tlsConfig
- starttlsServer.EnableSMTPUTF8 = true
- activeServers = append(activeServers, ServerInstance{Server: starttlsServer, Label: "STARTTLS"})
- go startListener(starttlsServer, "STARTTLS", starttlsAddress)
- }
+ smtpsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.SMTPSPort)
+ smtpsServer := createServer(smtpsAddress)
+ activeServers = append(activeServers, ServerInstance{Server: smtpsServer, Label: "SMTPS"})
+ if tlsConfig != nil {
+ smtpsServer.TLSConfig = tlsConfig
+ go startTLSListener(smtpsServer, "SMTPS", smtpsAddress)
+ } else {
+ go startListener(smtpsServer, "SMTPS", smtpsAddress)
+ }
+
+ starttlsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.StartTLSPort)
+ starttlsServer := createServer(starttlsAddress)
+ starttlsServer.EnableSMTPUTF8 = true
+ activeServers = append(activeServers, ServerInstance{Server: starttlsServer, Label: "STARTTLS"})
+ if tlsConfig != nil {
+ starttlsServer.TLSConfig = tlsConfig
}
+ go startListener(starttlsServer, "STARTTLS", starttlsAddress)
}
func Shutdown() {