BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Change an absolute path to a relative path Increase the mx value of the user's mailbox
lotkd5fa3e885abf
diff --git a/.gitignore b/.gitignoreindex e5b8c064..ff972a22 100644--- a/.gitignore+++ b/.gitignore@@ -6,7 +6,7 @@ idea/*.cursor/test/*config/*-data/*+core/data/*temp/ssl/*bmdiff --git a/core/api/mail_boxes/v1/mailboxes.go b/core/api/mail_boxes/v1/mailboxes.goindex 7639081d..6fe83f8b 100644--- a/core/api/mail_boxes/v1/mailboxes.go+++ b/core/api/mail_boxes/v1/mailboxes.go@@ -74,7 +74,10 @@ type DeleteMailboxReq struct {type DeleteMailboxRes struct {api_v1.StandardRes}-+type MailboxWithMxRecord struct {+ Mailbox+ MxRecord string `json:"mx" dc:"MX record for the domain"`+}type GetMailboxReq struct {g.Meta `path:"/mailbox/list" tags:"MailBox" method:"get" summary:"Get mailbox" in:"query"`Authorization string `json:"authorization" dc:"Authorization" in:"header"`@@ -87,8 +90,8 @@ type GetMailboxReq struct {type GetMailboxRes struct {api_v1.StandardResData struct {- Total int `json:"total"`- List []Mailbox `json:"list"`+ Total int `json:"total"`+ List []MailboxWithMxRecord `json:"list"`} `json:"data"`}diff --git a/core/api/mail_services/v1/common.go b/core/api/mail_services/v1/common.goindex 65604fb2..7f1379ba 100644--- a/core/api/mail_services/v1/common.go+++ b/core/api/mail_services/v1/common.go@@ -1,16 +1,18 @@package v1import (+ "billionmail-core/internal/service/public""billionmail-core/utility/types/api_v1""github.com/gogf/gf/v2/frame/g")type ServiceType string-const (- ServiceType_Postfix = "/opt/Billion-Mail/conf/postfix/main.cf"- ServiceType_Dovecot = "/opt/Billion-Mail/conf/dovecot/dovecot.conf"- ServiceType_Rspamd = "/opt/Billion-Mail/conf/rspamd/rspamd.conf"+var (+ BaseConfigDir = public.AbsPath("./conf")+ ServiceType_Postfix = BaseConfigDir + "/postfix/main.cf"+ ServiceType_Dovecot = BaseConfigDir + "/dovecot/dovecot.conf"+ ServiceType_Rspamd = BaseConfigDir + "/rspamd/rspamd.conf")type GetConfigFileReq struct {diff --git a/data/example_recipients.txt b/core/data/example_recipients.txtsimilarity index 100%rename from data/example_recipients.txtrename to core/data/example_recipients.txtdiff --git a/core/internal/controller/files/files_v1_download_file.go b/core/internal/controller/files/files_v1_download_file.goindex 9ccc6a74..b82caaca 100644--- a/core/internal/controller/files/files_v1_download_file.go+++ b/core/internal/controller/files/files_v1_download_file.go@@ -8,18 +8,24 @@ import ("github.com/gogf/gf/v2/frame/g""github.com/gogf/gf/v2/os/gfile""path/filepath"+ "strings")func (c *ControllerV1) DownloadFile(ctx context.Context, req *v1.DownloadFileReq) (res *v1.DownloadFileRes, err error) {- if err = c.validateFilePath(req.FilePath); err != nil {++ filePath := req.FilePath+ if strings.HasPrefix(filePath, "./") {+ filePath = public.AbsPath(filePath)+ }+ if err = c.validateFilePath(filePath); err != nil {return nil, err}- if !gfile.Exists(req.FilePath) {+ if !gfile.Exists(filePath) {return nil, gerror.New(public.LangCtx(ctx, "File not found"))}- fileName := filepath.Base(req.FilePath)+ fileName := filepath.Base(filePath)r := g.RequestFromCtx(ctx)@@ -27,7 +33,7 @@ func (c *ControllerV1) DownloadFile(ctx context.Context, req *v1.DownloadFileReqr.Response.Header().Set("Content-Type", "application/octet-stream")r.Response.Header().Set("Content-Disposition", "attachment; filename="+fileName)- r.Response.ServeFileDownload(req.FilePath, fileName)+ r.Response.ServeFileDownload(filePath, fileName)return nil, nil}diff --git a/core/internal/controller/mail_boxes/mail_boxes_v1_get_all_mailbox.go b/core/internal/controller/mail_boxes/mail_boxes_v1_get_all_mailbox.goindex 273115f3..13bc0784 100644--- a/core/internal/controller/mail_boxes/mail_boxes_v1_get_all_mailbox.go+++ b/core/internal/controller/mail_boxes/mail_boxes_v1_get_all_mailbox.go@@ -1,11 +1,10 @@package mail_boxesimport (+ "billionmail-core/api/mail_boxes/v1""billionmail-core/internal/service/mail_boxes""context""fmt"-- "billionmail-core/api/mail_boxes/v1")func (c *ControllerV1) GetAllMailbox(ctx context.Context, req *v1.GetAllMailboxReq) (res *v1.GetAllMailboxRes, err error) {diff --git a/core/internal/controller/mail_boxes/mail_boxes_v1_get_mailbox.go b/core/internal/controller/mail_boxes/mail_boxes_v1_get_mailbox.goindex b736dc22..5e0b6ef5 100644--- a/core/internal/controller/mail_boxes/mail_boxes_v1_get_mailbox.go+++ b/core/internal/controller/mail_boxes/mail_boxes_v1_get_mailbox.go@@ -1,8 +1,12 @@package mail_boxesimport (+ domainsV1 "billionmail-core/api/domains/v1"+ "billionmail-core/internal/service/domains""billionmail-core/internal/service/mail_boxes"+ "billionmail-core/internal/service/public""context"+ "fmt""billionmail-core/api/mail_boxes/v1")@@ -25,15 +29,45 @@ func (c *ControllerV1) GetMailbox(ctx context.Context, req *v1.GetMailboxReq) (rreturn nil, err}- // Handle sensitive information- for i := range mailboxList {- mailboxList[i].Password, _ = mail_boxes.PasswdDecode(ctx, mailboxList[i].PasswordEncode)+ // 转换为带 MxRecord 的结构体+ mailboxListWithMx := make([]v1.MailboxWithMxRecord, len(mailboxList))+ for i, mailbox := range mailboxList {+ mailboxListWithMx[i] = v1.MailboxWithMxRecord{+ Mailbox: mailbox,+ MxRecord: GenerateSPFRecord(mailbox.Domain), // 使用 GenerateSPFRecord 获取 MX 记录+ }+ // Handle sensitive information+ mailboxListWithMx[i].Password, _ = mail_boxes.PasswdDecode(ctx, mailboxListWithMx[i].PasswordEncode)}res.Data.Total = total- res.Data.List = mailboxList-+ res.Data.List = mailboxListWithMxres.SetSuccess("Success")return}++func buildCacheKey(domain, recordType string) string {+ return fmt.Sprintf("DOMAIN_DNS_RECORDS_:%s:_%s", domain, recordType)+}++// GenerateSPFRecord generates SPF record hints based on IP and host.+func GenerateSPFRecord(domain string) string {+ // Retrieve the current SPF record for the domain+ var existingValue string++ // Fetch SPF record from cache or domains service+ spfRecord := public.GetCache(buildCacheKey(domain, "MX"))++ if spfRecord != nil {+ if v, ok := spfRecord.(domainsV1.DNSRecord); ok {+ existingValue = v.Value+ }+ }+ if existingValue == "" {+ record, _ := domains.GetMXRecord(domain, false)+ existingValue = record.Value+ }++ return existingValue+}diff --git a/core/internal/controller/mail_services/mail_services.go b/core/internal/controller/mail_services/mail_services.goindex 20991032..0e7b6bd6 100644--- a/core/internal/controller/mail_services/mail_services.go+++ b/core/internal/controller/mail_services/mail_services.go@@ -41,7 +41,7 @@ func processForwardUsers(forwardUsers string) []string {func SyncBccToPostfix(ctx context.Context) error {// configPath- postfixConfigDir := "/opt/Billion-Mail/conf/postfix/conf"+ postfixConfigDir := public.AbsPath("./conf/postfix/conf")senderBccFile := path.Join(postfixConfigDir, "sender_bcc")recipientBccFile := path.Join(postfixConfigDir, "recipient_bcc")mainCfFile := path.Join(postfixConfigDir, "main.cf")diff --git a/core/internal/controller/relay/relay.go b/core/internal/controller/relay/relay.goindex b09b8757..2cd83dba 100644--- a/core/internal/controller/relay/relay.go+++ b/core/internal/controller/relay/relay.go@@ -25,9 +25,9 @@ import ("strings")-const (- // Postfix-related configuration paths- postfixConfigDir = "/opt/Billion-Mail/conf/postfix"+var (+ postfixConfigDir = public.AbsPath("./conf/postfix")+senderRelayFile = "/conf/sender_relay"saslPasswdFile = "/conf/sasl_passwd"senderTransportFile = "/conf/sender_transport_relay"