remove email scrape

master
Bel LaPointe 2022-01-11 22:23:57 -05:00
parent 6569631928
commit 5a4bcecac7
4 changed files with 6 additions and 53 deletions

View File

@ -1,7 +1,7 @@
{
"Name": "pa",
"Interval": {
"Email": "10s..30s",
"Input": "10s..30s",
"OK": "6h0m0s..6h0m0s",
"Error": "6h0m0s..6h0m0s"
},
@ -34,14 +34,5 @@
"Username": "noeasyrunstrucking@gmail.com",
"Password": "thumper123"
}
},
"Emailer": {
"From": "breellocaldev@gmail.com",
"SMTP": "",
"POP3": "",
"IMAP": "imap.gmail.com:993",
"Password": "gojfkkfrkmtxzyro",
"Limit": 0
},
"EmailerEnabled": false
}
}

View File

@ -3,7 +3,6 @@ package config
import (
"encoding/json"
"io/ioutil"
"local/sandbox/contact/contact"
"local/storage"
"os"
"sync"
@ -12,7 +11,7 @@ import (
type Config struct {
Name string
Interval struct {
Email Duration
Input Duration
OK Duration
Error Duration
}
@ -40,8 +39,6 @@ type Config struct {
Password string
}
}
Emailer contact.Emailer
EmailerEnabled bool
lock sync.Mutex
db storage.DB

37
main.go
View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"local/storage"
"local/truckstop/broker"
"local/truckstop/config"
@ -12,7 +11,6 @@ import (
"log"
"regexp"
"sort"
"strings"
"sync"
"time"
)
@ -23,17 +21,10 @@ func main() {
lock := &sync.Mutex{}
go func() {
for {
time.Sleep(config.Get().Interval.Email.Get())
time.Sleep(config.Get().Interval.Input.Get())
if err := config.Refresh(); err != nil {
log.Println(err)
} else {
if config.Get().EmailerEnabled {
lock.Lock()
if err := email(); err != nil {
log.Print(err)
}
lock.Unlock()
}
if config.Get().Message.Matrix.ReceiveEnabled {
lock.Lock()
if err := matrixrecv(); err != nil {
@ -94,32 +85,6 @@ func setNewStates(states map[config.State]struct{}) {
}
}
func email() error {
log.Printf("checking email...")
ch, err := config.Get().Emailer.ReadIMAP()
if err != nil {
ch, err = config.Get().Emailer.ReadIMAP()
}
if err != nil {
return err
}
states := map[config.State]struct{}{}
for email := range ch {
if len(states) > 0 {
continue
}
if !strings.Contains(email.Header.Get("From"), config.Get().Client) {
continue
}
b, _ := ioutil.ReadAll(email.Body)
for _, state := range parseOutStates(b) {
states[state] = struct{}{}
}
}
setNewStates(states)
return nil
}
func parseOutStates(b []byte) []config.State {
var states []config.State
var state config.State

View File

@ -1,6 +1,4 @@
todo:
- send matrix msg on config change
- rm email
- modify old items once no longer available
- many users -> 1 ntg query
- accept after date
@ -18,6 +16,8 @@ todo:
- accept states via element for one system
- set up copy for caleb, broc
done:
- rm email
- send matrix msg on config change
- setup pa on element
- configurable email interval
- jitter on intervals, including dedicated err span