mirror of
https://github.com/knadh/listmonk.git
synced 2024-09-20 07:16:33 +08:00
Refactor email domain blocklist config field in importer package.
This commit is contained in:
parent
476d5bebf2
commit
98729f63df
|
@ -70,7 +70,7 @@ type constants struct {
|
||||||
AllowExport bool `koanf:"allow_export"`
|
AllowExport bool `koanf:"allow_export"`
|
||||||
AllowWipe bool `koanf:"allow_wipe"`
|
AllowWipe bool `koanf:"allow_wipe"`
|
||||||
Exportable map[string]bool `koanf:"-"`
|
Exportable map[string]bool `koanf:"-"`
|
||||||
DomainBlocklist map[string]bool `koanf:"-"`
|
DomainBlocklist []string `koanf:"-"`
|
||||||
} `koanf:"privacy"`
|
} `koanf:"privacy"`
|
||||||
Security struct {
|
Security struct {
|
||||||
EnableCaptcha bool `koanf:"enable_captcha"`
|
EnableCaptcha bool `koanf:"enable_captcha"`
|
||||||
|
@ -370,7 +370,7 @@ func initConstants() *constants {
|
||||||
c.Lang = ko.String("app.lang")
|
c.Lang = ko.String("app.lang")
|
||||||
c.Privacy.Exportable = maps.StringSliceToLookupMap(ko.Strings("privacy.exportable"))
|
c.Privacy.Exportable = maps.StringSliceToLookupMap(ko.Strings("privacy.exportable"))
|
||||||
c.MediaProvider = ko.String("upload.provider")
|
c.MediaProvider = ko.String("upload.provider")
|
||||||
c.Privacy.DomainBlocklist = maps.StringSliceToLookupMap(ko.Strings("privacy.domain_blocklist"))
|
c.Privacy.DomainBlocklist = ko.Strings("privacy.domain_blocklist")
|
||||||
|
|
||||||
// Static URLS.
|
// Static URLS.
|
||||||
// url.com/subscription/{campaign_uuid}/{subscriber_uuid}
|
// url.com/subscription/{campaign_uuid}/{subscriber_uuid}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
|
"github.com/knadh/koanf/maps"
|
||||||
"github.com/knadh/listmonk/internal/i18n"
|
"github.com/knadh/listmonk/internal/i18n"
|
||||||
"github.com/knadh/listmonk/models"
|
"github.com/knadh/listmonk/models"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
|
@ -51,9 +52,10 @@ const (
|
||||||
|
|
||||||
// Importer represents the bulk CSV subscriber import system.
|
// Importer represents the bulk CSV subscriber import system.
|
||||||
type Importer struct {
|
type Importer struct {
|
||||||
opt Options
|
opt Options
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
i18n *i18n.I18n
|
i18n *i18n.I18n
|
||||||
|
domainBlocklist map[string]bool
|
||||||
|
|
||||||
stop chan bool
|
stop chan bool
|
||||||
status Status
|
status Status
|
||||||
|
@ -68,7 +70,7 @@ type Options struct {
|
||||||
NotifCB models.AdminNotifCallback
|
NotifCB models.AdminNotifCallback
|
||||||
|
|
||||||
// Lookup table for blocklisted domains.
|
// Lookup table for blocklisted domains.
|
||||||
DomainBlocklist map[string]bool
|
DomainBlocklist []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session represents a single import session.
|
// Session represents a single import session.
|
||||||
|
@ -130,11 +132,12 @@ var (
|
||||||
// New returns a new instance of Importer.
|
// New returns a new instance of Importer.
|
||||||
func New(opt Options, db *sql.DB, i *i18n.I18n) *Importer {
|
func New(opt Options, db *sql.DB, i *i18n.I18n) *Importer {
|
||||||
im := Importer{
|
im := Importer{
|
||||||
opt: opt,
|
opt: opt,
|
||||||
db: db,
|
db: db,
|
||||||
i18n: i,
|
i18n: i,
|
||||||
status: Status{Status: StatusNone, logBuf: bytes.NewBuffer(nil)},
|
domainBlocklist: maps.StringSliceToLookupMap(opt.DomainBlocklist),
|
||||||
stop: make(chan bool, 1),
|
status: Status{Status: StatusNone, logBuf: bytes.NewBuffer(nil)},
|
||||||
|
stop: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
return &im
|
return &im
|
||||||
}
|
}
|
||||||
|
@ -587,7 +590,7 @@ func (im *Importer) SanitizeEmail(email string) (string, error) {
|
||||||
// Check if the e-mail's domain is blocklisted.
|
// Check if the e-mail's domain is blocklisted.
|
||||||
d := strings.Split(em.Address, "@")
|
d := strings.Split(em.Address, "@")
|
||||||
if len(d) == 2 {
|
if len(d) == 2 {
|
||||||
_, ok := im.opt.DomainBlocklist[d[1]]
|
_, ok := im.domainBlocklist[d[1]]
|
||||||
if ok {
|
if ok {
|
||||||
return "", errors.New(im.i18n.T("subscribers.domainBlocklisted"))
|
return "", errors.New(im.i18n.T("subscribers.domainBlocklisted"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue