Archived
1
0
This commit is contained in:
Jeff Becker 2019-01-29 06:57:08 -05:00
parent bcddab9af6
commit 59068bb961
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 18 additions and 23 deletions

View File

@ -198,8 +198,6 @@ type ModEngine interface {
AllowBan(pubkey string) bool AllowBan(pubkey string) bool
// allow janitor // allow janitor
AllowJanitor(pubkey string) bool AllowJanitor(pubkey string) bool
// load a mod message
LoadMessage(msgid string) NNTPMessage
// execute 1 mod action line by a mod with pubkey // execute 1 mod action line by a mod with pubkey
Execute(ev ModEvent, pubkey string) Execute(ev ModEvent, pubkey string)
// do a mod event unconditionally // do a mod event unconditionally
@ -227,10 +225,6 @@ func (self *modEngine) MarkSpam(msgid string) (err error) {
return return
} }
func (self *modEngine) LoadMessage(msgid string) NNTPMessage {
return self.store.GetMessage(msgid)
}
func (self *modEngine) BanAddress(cidr string) (err error) { func (self *modEngine) BanAddress(cidr string) (err error) {
return self.database.BanAddr(cidr) return self.database.BanAddr(cidr)
} }
@ -345,22 +339,23 @@ func (self *modEngine) AllowDelete(pubkey, msgid string) (allow bool) {
} }
func (mod *modEngine) HandleMessage(msgid string) { func (mod *modEngine) HandleMessage(msgid string) {
nntp := mod.store.GetMessage(msgid) mod.store.GetMessage(msgid, func(nntp NNTPMessage) {
if nntp == nil { if nntp == nil {
log.Println("failed to load", msgid, "in mod engine, missing message") log.Println("failed to load", msgid, "in mod engine, missing message")
return return
} }
// sanity check // sanity check
if nntp.Newsgroup() == "ctl" { if nntp.Newsgroup() == "ctl" {
pubkey := nntp.Pubkey() pubkey := nntp.Pubkey()
for _, line := range strings.Split(nntp.Message(), "\n") { for _, line := range strings.Split(nntp.Message(), "\n") {
line = strings.Trim(line, "\r\t\n ") line = strings.Trim(line, "\r\t\n ")
if len(line) > 0 { if len(line) > 0 {
ev := ParseModEvent(line) ev := ParseModEvent(line)
mod.Execute(ev, pubkey) mod.Execute(ev, pubkey)
}
} }
} }
} })
} }
func (mod *modEngine) Do(ev ModEvent) { func (mod *modEngine) Do(ev ModEvent) {

View File

@ -75,7 +75,7 @@ type ArticleStore interface {
// register signed message // register signed message
RegisterSigned(msgid, pk string) error RegisterSigned(msgid, pk string) error
GetMessage(msgid string) NNTPMessage GetMessage(msgid string, visit func(NNTPMessage))
// get size of message on disk // get size of message on disk
GetMessageSize(msgid string) (int64, error) GetMessageSize(msgid string) (int64, error)
@ -584,7 +584,7 @@ func (self *articleStore) ProcessMessage(wr io.Writer, msg io.Reader, spamfilter
return return
} }
func (self *articleStore) GetMessage(msgid string) (nntp NNTPMessage) { func (self *articleStore) GetMessage(msgid string, visit func(NNTPMessage)) {
r, err := self.OpenMessage(msgid) r, err := self.OpenMessage(msgid)
if err == nil { if err == nil {
defer r.Close() defer r.Close()
@ -597,7 +597,7 @@ func (self *articleStore) GetMessage(msgid string) (nntp NNTPMessage) {
// inject pubkey for mod // inject pubkey for mod
n.Headers().Set("X-PubKey-Ed25519", hdr.Get("X-PubKey-Ed25519")) n.Headers().Set("X-PubKey-Ed25519", hdr.Get("X-PubKey-Ed25519"))
} }
nntp = n visit(n)
}) })
} }
} }