-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
66 lines (63 loc) · 1.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// fakereceive reads a message from stdin and hands it to wppsvr as if wppsvr
// had read it from a BBS. Any response messages are emitted to stdout.
//
// usage: fakereceive frommailbox frombbs < messagetext
package main
import (
"fmt"
"io"
"log"
"os"
"time"
"github.com/rothskeller/packet/xscmsg"
"github.com/rothskeller/wppsvr/analyze"
"github.com/rothskeller/wppsvr/config"
"github.com/rothskeller/wppsvr/store"
)
func main() {
var (
mailbox string
bbs string
st *store.Store
session *store.Session
rawmsg []byte
err error
)
xscmsg.Register()
if len(os.Args) != 3 {
fmt.Fprintf(os.Stderr, "usage: fakereceive frommailbox frombbs < messagetext\n")
os.Exit(2)
}
mailbox, bbs = os.Args[1], os.Args[2]
if err = config.Read(); err != nil {
log.Fatal(err)
}
if st, err = store.Open(); err != nil {
log.Fatal(err)
}
if _, ok := config.Get().BBSes[bbs]; !ok {
fmt.Fprintf(os.Stderr, "ERROR: bbs %q is not defined in configuration\n", bbs)
os.Exit(1)
}
for _, s := range st.GetRunningSessions() {
if s.CallSign == mailbox {
session = s
break
}
}
if session == nil {
fmt.Fprintf(os.Stderr, "ERROR: no running session for mailbox %q\n", mailbox)
os.Exit(1)
}
rawmsg, _ = io.ReadAll(os.Stdin)
analysis := analyze.Analyze(st, session, bbs, string(rawmsg))
responses := analysis.Responses(st)
for _, response := range responses {
response.SendTime = time.Now()
}
analysis.Commit(st)
for _, response := range responses {
st.SaveResponse(response)
fmt.Printf("To: %s\nSubject: %s\n\n%s", response.To, response.Subject, response.Body)
}
}