diff options
| author | Bobby <[email protected]> | 2026-03-08 18:17:23 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-08 18:17:23 +0530 |
| commit | 1136af49815be77a0aca151f3b8ec7348bf4b4c8 (patch) | |
| tree | ca4d94f981be59c51fa7d160e32be978a8d4b4fb /utils | |
| parent | f48054e9bc5e4fb36b9aba9126c6ace9c5b1f470 (diff) | |
| download | dove-1136af49815be77a0aca151f3b8ec7348bf4b4c8.tar.xz dove-1136af49815be77a0aca151f3b8ec7348bf4b4c8.zip | |
feat(dns): add update functionality for DNS records (MX, SRV, TXT)
- Implemented UpdateMXRecord, UpdateSRVRecord, and UpdateTXTRecord functions in their respective repositories.
- Added UpdateRecord method in dns service to handle updates for various DNS record types.
- Updated router to include a new route for updating DNS records.
- Enhanced error messages for record updates in messages.go.
- Modified the frontend forms to support editing DNS records with improved UI components.
- Refactored existing domain management code to remove unused update functionality.
- Improved email handling by adding MX record validation during email delivery.
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/email/defaults.go | 2 | ||||
| -rw-r--r-- | utils/smtp/messages.go | 1 | ||||
| -rw-r--r-- | utils/smtp/session.go | 25 |
3 files changed, 27 insertions, 1 deletions
diff --git a/utils/email/defaults.go b/utils/email/defaults.go index 56bee21..5aa11de 100644 --- a/utils/email/defaults.go +++ b/utils/email/defaults.go @@ -4,4 +4,4 @@ const ( AddressJoiner = ", " LogPrefix = "Email" SnippetLength = 200 -)
\ No newline at end of file +) diff --git a/utils/smtp/messages.go b/utils/smtp/messages.go index 1c82ab6..0fd280b 100644 --- a/utils/smtp/messages.go +++ b/utils/smtp/messages.go @@ -7,6 +7,7 @@ const ( InvalidCredentials = "Invalid credentials." ListenFailed = "Failed to start %s listener: %v" MailFrom = "Mail from: %s" + MXLookupFailed = "MX lookup failed for %s: %v" MessageParseFailed = "Failed to parse incoming message: %v" MessageReceived = "Message received (%d bytes) from %s to %v." MessageStoreFailed = "Failed to store message: %v" diff --git a/utils/smtp/session.go b/utils/smtp/session.go index ef5ddc7..e9efbd9 100644 --- a/utils/smtp/session.go +++ b/utils/smtp/session.go @@ -10,6 +10,7 @@ import ( "dove/utils/storage" "fmt" "io" + "net" "strings" "time" @@ -63,6 +64,12 @@ func (self *Session) Data(messageReader io.Reader) error { deliveredToLocal := false for _, recipientAddress := range self.toAddresses { + recipientDomain := extractDomain(recipientAddress) + if recipientDomain == "" || !domainHasMXRecords(recipientDomain) { + logger.Warnf(LogPrefix, UnknownRecipientDomain, recipientDomain) + continue + } + recipientMailbox := mailRepo.FindMailboxByAddress(recipientAddress) if recipientMailbox == nil { aliasMailbox := mailRepo.FindMailboxByAlias(recipientAddress) @@ -164,3 +171,21 @@ func deliverToLocalMailbox(mailbox *mailModel.Mailbox, parsedEmail *email.Parsed return nil } + +func extractDomain(emailAddress string) string { + atIndex := strings.LastIndex(emailAddress, "@") + if atIndex < 0 || atIndex >= len(emailAddress)-1 { + return "" + } + return emailAddress[atIndex+1:] +} + +func domainHasMXRecords(domainName string) bool { + mxRecords, lookupError := net.LookupMX(domainName) + if lookupError != nil { + logger.Debugf(LogPrefix, MXLookupFailed, domainName, lookupError) + return false + } + + return len(mxRecords) > 0 +} |
