feat: 支持第三方发信自定义发信名称并简化系统发信地址,发布V2.13.0部署包
This commit is contained in:
1 parent
8fd67812b3
commit
1ce9f708e3
17 files changed
+161
-33
No files matched your search
@@ -172,7 +172,7 @@ func TestAdminPluginRestartScope(t *testing.T) {
|
||||
|
||||
func TestManagementEndpointCatalog(t *testing.T) {
|
||||
endpoints := ManagementEndpoints()
|
||||
if len(endpoints) != 47 {
|
||||
if len(endpoints) != 49 {
|
||||
t.Fatalf("unexpected endpoint count: %d", len(endpoints))
|
||||
}
|
||||
seen := map[string]struct{}{}
|
||||
|
||||
@@ -65,3 +65,10 @@ func (s *ProtocolSession) ReserveNotification(recipients int) error {
|
||||
}
|
||||
return s.notification.Reserve(db.Instance, recipients, time.Now())
|
||||
}
|
||||
|
||||
func (s *ProtocolSession) NotificationSenderName() string {
|
||||
if !s.IsNotification() {
|
||||
return ""
|
||||
}
|
||||
return s.notification.SenderName()
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func Configured(item models.NotificationGrant, user models.User) bool {
|
||||
}
|
||||
|
||||
// SetAuthorization 使用版本条件避免覆盖其他管理员的修改;关闭时永久清除旧凭据。
|
||||
func SetAuthorization(engine *xorm.Engine, user models.User, expected int, enabled bool, minuteLimit, dayLimit int, guards ...accountgroup.WriteGuard) error {
|
||||
func SetAuthorization(engine *xorm.Engine, user models.User, expected int, enabled bool, minuteLimit, dayLimit int, senderName string, guards ...accountgroup.WriteGuard) error {
|
||||
if minuteLimit < 1 || minuteLimit > 100 || dayLimit < minuteLimit || dayLimit > 10000 {
|
||||
return ErrLimits
|
||||
}
|
||||
@@ -93,6 +93,11 @@ func SetAuthorization(engine *xorm.Engine, user models.User, expected int, enabl
|
||||
item.CodeHash = ""
|
||||
item.CodeCiphertext = ""
|
||||
}
|
||||
senderName = strings.TrimSpace(senderName)
|
||||
if len(senderName) > 64 {
|
||||
senderName = senderName[:64]
|
||||
}
|
||||
item.SenderName = senderName
|
||||
item.MinuteLimit, item.DayLimit = minuteLimit, dayLimit
|
||||
item.CodeVersion++
|
||||
if expected == 0 {
|
||||
@@ -102,7 +107,7 @@ func SetAuthorization(engine *xorm.Engine, user models.User, expected int, enabl
|
||||
return tx.Commit()
|
||||
}
|
||||
affected, err := tx.ID(user.ID).Where("code_version = ?", expected).
|
||||
Cols("enabled", "code_hash", "code_ciphertext", "code_version", "minute_limit", "day_limit").Update(&item)
|
||||
Cols("enabled", "code_hash", "code_ciphertext", "code_version", "minute_limit", "day_limit", "sender_name").Update(&item)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -214,6 +219,14 @@ type Grant struct {
|
||||
hash string
|
||||
sessionVersion int
|
||||
securityVersion int
|
||||
senderName string
|
||||
}
|
||||
|
||||
func (g *Grant) SenderName() string {
|
||||
if g == nil {
|
||||
return ""
|
||||
}
|
||||
return g.senderName
|
||||
}
|
||||
|
||||
func (g *Grant) QueueBinding() (string, int, int, string) {
|
||||
@@ -234,7 +247,7 @@ func Authenticate(engine *xorm.Engine, user models.User, plain string) (*Grant,
|
||||
if subtle.ConstantTimeCompare([]byte(item.CodeHash), []byte(digest(plain))) != 1 {
|
||||
return nil, ErrDenied
|
||||
}
|
||||
return &Grant{engine, user.ID, item.CodeVersion, item.CodeHash, item.SessionVersion, item.SecurityVersion}, nil
|
||||
return &Grant{engine, user.ID, item.CodeVersion, item.CodeHash, item.SessionVersion, item.SecurityVersion, item.SenderName}, nil
|
||||
}
|
||||
|
||||
func (g *Grant) Valid(engine *xorm.Engine) bool {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -185,9 +184,10 @@ func authorizedQueuedSender(submission Submission, message *parsemail.Email, use
|
||||
}
|
||||
domains := config.CurrentMailDomains()
|
||||
if submission.Authorization.Kind == "notification" {
|
||||
sender := validation.NotificationAddress(domains.Primary)
|
||||
return sender != "" && strings.EqualFold(submission.EnvelopeFrom, sender) &&
|
||||
strings.EqualFold(message.From.EmailAddress, sender) && strings.EqualFold(message.Sender.EmailAddress, sender)
|
||||
primaryDomain := domains.Primary
|
||||
return primaryDomain != "" && validation.IsAuthorizedNotificationSender(submission.EnvelopeFrom, primaryDomain) &&
|
||||
validation.IsAuthorizedNotificationSender(message.From.EmailAddress, primaryDomain) &&
|
||||
validation.IsAuthorizedNotificationSender(message.Sender.EmailAddress, primaryDomain)
|
||||
}
|
||||
allowAlias := user.EffectiveRole() == access.RoleSuperAdmin
|
||||
return validation.IsAuthorizedSender(message.From.EmailAddress, user.Account, allowAlias, domains.Accepted) &&
|
||||
|
||||
Reference in new issue
Block a user