修复按收件用户拦截黑名单邮件并补齐历史邮件警示
This commit is contained in:
1 parent
05947180d8
commit
2026816369
10 files changed
+136
-10
No files matched your search
@@ -1,6 +1,13 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// UserContact 保存单个用户的厇史写信收仴人,用于写信页自动补全与遗系人管理
|
||||
type UserContact struct {
|
||||
@@ -29,3 +36,32 @@ type UserTrustedSender struct {
|
||||
}
|
||||
|
||||
func (UserTrustedSender) TableName() string { return "user_trusted_sender" }
|
||||
|
||||
func BlacklistedRecipientIDs(session *xorm.Session, userIDs []int, addresses ...string) (map[int]bool, error) {
|
||||
blocked := make(map[int]bool)
|
||||
if session == nil {
|
||||
return nil, fmt.Errorf("sender filter database session is unavailable")
|
||||
}
|
||||
var normalized []string
|
||||
for _, address := range addresses {
|
||||
if address = strings.ToLower(strings.TrimSpace(address)); address != "" {
|
||||
normalized = append(normalized, address)
|
||||
}
|
||||
}
|
||||
if len(userIDs) == 0 || len(normalized) == 0 {
|
||||
return blocked, nil
|
||||
}
|
||||
var filters []UserTrustedSender
|
||||
err := session.Table(new(UserTrustedSender)).Where(builder.And(
|
||||
builder.In("user_id", userIDs),
|
||||
builder.In("LOWER(email)", normalized),
|
||||
builder.Eq{"filter_type": FilterTypeBlacklist},
|
||||
)).Find(&filters)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load recipient sender filters: %w", err)
|
||||
}
|
||||
for _, filter := range filters {
|
||||
blocked[filter.UserID] = true
|
||||
}
|
||||
return blocked, nil
|
||||
}
|
||||
Reference in new issue
Block a user