From bf9301d6bee4427c52bdb414aed1ebff8e9c1c9d Mon Sep 17 00:00:00 2001 From: Neo <321592+Neo-Desktop@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:37:08 -0800 Subject: [PATCH 1/2] msn test: wait for the switchboard to close before Carol writes (#39) TestIRC had alice send OUT on her switchboard and Carol write at once. When Carol's message beat the server's handling of OUT, it went to the old switchboard and no RNG came: a flake seen under load (menu's CI). The test now waits for the server to close the connection first. Claude-Session: https://claude.ai/code/session_01B82eRRm1WrfJdB863kw36V Signed-off-by: Claude Co-authored-by: Claude --- internal/msn/msn_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/msn/msn_test.go b/internal/msn/msn_test.go index dc759f7..fd80858 100644 --- a/internal/msn/msn_test.go +++ b/internal/msn/msn_test.go @@ -6,7 +6,9 @@ import ( "context" "crypto/md5" "encoding/hex" + "errors" "fmt" + "io" "log" "net" "path/filepath" @@ -187,6 +189,19 @@ func (cl *client) expect(want string) (string, string) { } } +// gone waits for the server to close the connection. +func (cl *client) gone() { + cl.t.Helper() + for { + if _, _, err := cl.line(); err != nil { + if !errors.Is(err, io.EOF) { + cl.t.Fatalf("waiting for the server to close: %v", err) + } + return + } + } +} + // quiet: nothing beginning with any of these comes for a moment. func (cl *client) quiet(not ...string) { cl.t.Helper() @@ -539,6 +554,7 @@ func TestIRC(t *testing.T) { } as.cmd("OUT") + as.gone() // the server has her out of the switchboard before Carol writes carol.send("PRIVMSG alice :still there?") rng, _ := alice.expect("RNG ") if !strings.HasSuffix(rng, " CarolAnn@bbs.test Carol%20Ann") { From 925d95571d402bbff7d03fe40b72fd509e8bfab8 Mon Sep 17 00:00:00 2001 From: Neo <321592+Neo-Desktop@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:46:13 -0800 Subject: [PATCH 2/2] AOL host: the client's own Read Mail, Old Mail and Sent Mail (#40) The client's mail tool asks for its lists with m7 (new), m9 (old) and m8 (sent), opens a mail with m3 (mip_preset_message_id, mip_read_mail) and changes mail with m2 (mip_change_message_status: 7 Ignore, 2 Keep As New, 4 Delete). All of this was read from the tool's code (AOLMIP.AOL). The host answers each list with a MIP message holding one message per mail (id, author, subject, date, an empty block), and a read with the whole mail. The atom order within a list entry is a best guess until a real 3.0 client tries it. store gains MarkMailUnread for Keep As New. Claude-Session: https://claude.ai/code/session_01B82eRRm1WrfJdB863kw36V Signed-off-by: Claude Co-authored-by: Claude --- TODO.md | 14 ++- docs/wiki/AOL.md | 11 +- internal/aol/aol_test.go | 80 +++++++++++++ internal/aol/readmail.go | 232 ++++++++++++++++++++++++++++++++++++++ internal/aol/session.go | 15 +++ internal/store/mailbox.go | 5 + 6 files changed, 350 insertions(+), 7 deletions(-) create mode 100644 internal/aol/readmail.go diff --git a/TODO.md b/TODO.md index f38847a..ef62d4d 100644 --- a/TODO.md +++ b/TODO.md @@ -55,11 +55,15 @@ client's `AmericaOnline.aol.com`) and by modem. the keywords Rooms and Room *name* to any chat room; message areas as boards (topics, posts, a post window whose Send is `de_ez_send_form` with token `Zp`), all host windows. -- **Tokens**, next: the client's own Read Mail list (`m7` and its MIP - answers); the client asks for art it lacks (`fh`): none is served yet. -- **Modem callers**: the client's CCL script expects a network's prompts - (SprintNet, Tymnet) before P3; emulate one, or ship a CCL that dials - straight in. +- **Read Mail** (done, untried with a real client): the client's own + New, Old and Sent Mail lists (`m7`, `m9`, `m8`) as MIP lists, `m3` + opens one, `m2` Ignore / Keep As New / Delete. The order of the atoms + in a list entry is a guess from the mail tool's code. +- **Modem callers** (done in menu, untried with a real modem): modemmenu + plays AOLnet, SprintNet or Tymnet as the client's CCL script expects, + then joins the line to the host. +- **Tokens**, next: the client asks for art it lacks (`fh`): none is + served yet. - **To decide**: AOL 4.0's RSA handshake (revival servers turn it off in the client); which client forms (32-xxxx) are in its own database and which the host must send. diff --git a/docs/wiki/AOL.md b/docs/wiki/AOL.md index 9cae3ef..d0cfcc6 100644 --- a/docs/wiki/AOL.md +++ b/docs/wiki/AOL.md @@ -67,8 +67,15 @@ signed on is shown in a message box. The keyword Mail opens the BBS's mailbox window, newest first with new mail marked `*`. A button reads a mail, which marks it read, and the mail's -window can delete it. The client's own Read Mail and Old Mail lists are -not served yet. +window can delete it. + +The client's own mail windows work too: Read New Mail on the toolbar +(`m7`), Old Mail (`m9`, mail already read) and Sent Mail (`m8`). Each is +filled with a MIP list, newest first. Opening a mail (`m3`) sends it +whole and marks it read. Ignore marks a mail read, Keep As New marks it +unread again, and Delete puts it in the BBS trash (`m2`). These answers +were worked out from the client's mail tool and have not yet been tried +with a real client. ## Message boards diff --git a/internal/aol/aol_test.go b/internal/aol/aol_test.go index 25f722b..8f120da 100644 --- a/internal/aol/aol_test.go +++ b/internal/aol/aol_test.go @@ -715,3 +715,83 @@ func TestBoards(t *testing.T) { t.Errorf("999:\n%s", s) } } + +func TestReadMail(t *testing.T) { + srv, _ := newServer(t) + st := srv.B.Store + if _, err := st.CreateUser("Carol Ann", "password1", "There", false); err != nil { + t.Fatal(err) + } + a := signedOn(t, srv, "alice") + a.send("m4", mailForm("CarolAnn", "Lunch", "Are you free?\r\nNoon?", false)[0]) + a.stream() + a.send("m4", mailForm("CarolAnn", "Later", "Or tea", false)[0]) + a.stream() + u, _ := st.UserByName("Carol Ann") + inbox, _ := st.Inbox(u.ID) + if len(inbox) != 2 { + t.Fatalf("inbox %v", inbox) + } + c := signedOn(t, srv, "CarolAnn") + + // the New Mail list: both, newest first, each a message of its own + c.send("m7", nil) + s := c.stream() + if strings.Count(s, "mip_start_message") != 3 || strings.Count(s, "mip_start_block") != 2 || + !strings.Contains(s, hexText("alice")) || strings.Index(s, hexText("Later")) > strings.Index(s, hexText("Lunch")) { + t.Errorf("new mail:\n%s", s) + } + c.send("m9", nil) + if s := c.stream(); !strings.Contains(s, "You have no old mail.") { + t.Errorf("old mail:\n%s", s) + } + + // reading one, with and without a stream id before the atoms + m3 := func(id int64) []byte { + return fdo.MustCompile(fmt.Sprintf("mip_preset_message_id <%d>\nmip_read_mail <1>\n", id)) + } + c.send("m3", m3(inbox[0].ID)) + s = c.stream() + if !strings.Contains(s, hexText("Lunch")) || !strings.Contains(s, hexText("Are you free?\r\nNoon?")) || !strings.Contains(s, "mip_end_message") { + t.Errorf("read:\n%s", s) + } + c.send("m3", append([]byte{0, 9}, m3(inbox[1].ID)...)) + if s := c.stream(); !strings.Contains(s, hexText("Or tea")) { + t.Errorf("read with a stream id:\n%s", s) + } + if n, _ := st.UnreadMail(u.ID); n != 0 { + t.Errorf("%d unread after reading both", n) + } + c.send("m9", nil) + if s := c.stream(); strings.Count(s, "mip_start_block") != 2 { + t.Errorf("old mail:\n%s", s) + } + // a mail not in her mailbox, nor sent by her + a.send("m3", m3(inbox[1].ID+100)) + if s := a.stream(); !strings.Contains(s, "not in your mailbox") { + t.Errorf("no such mail:\n%s", s) + } + // but alice sees what she sent + a.send("m8", nil) + if s := a.stream(); !strings.Contains(s, hexText("Carol Ann")) || strings.Count(s, "mip_start_block") != 2 { + t.Errorf("sent mail:\n%s", s) + } + + // Keep As New for the first, Delete for the second + c.send("m2", fdo.MustCompile(fmt.Sprintf("mip_preset_message_id <%d>\nmip_change_message_status <2>\n"+ + "mip_preset_message_id <%d>\nmip_change_message_status <4>\n", inbox[0].ID, inbox[1].ID))) + c.stream() + left, _ := st.Inbox(u.ID) + if len(left) != 1 || left[0].ID != inbox[0].ID || left[0].Read { + t.Errorf("after m2: %+v", left) + } +} + +// hexText is text as the decompiler shows a raw atom's data. +func hexText(s string) string { + var parts []string + for _, c := range []byte(s) { + parts = append(parts, fmt.Sprintf("%02xx", c)) + } + return strings.Join(parts, ", ") +} diff --git a/internal/aol/readmail.go b/internal/aol/readmail.go new file mode 100644 index 0000000..bf7e6bf --- /dev/null +++ b/internal/aol/readmail.go @@ -0,0 +1,232 @@ +package aol + +import ( + "errors" + "strings" + + "github.com/D-Modem/bbs/internal/aol/fdo" + "github.com/D-Modem/bbs/internal/store" +) + +// Read Mail: the client's own mail windows, which its mail tool +// (AOLMIP.AOL) fills from the host's MIP atoms. What is here comes from +// reading the tool's code, and has not yet been tried with a real client: +// +// m7 the New Mail list (the toolbar's Read New Mail); m9 the Old Mail +// list; m8 the Sent Mail list. None carries data. +// m3 read one mail: mip_preset_message_id , mip_read_mail . +// m2 change mail: per mail, mip_preset_message_id and +// mip_change_message_status : 7 Ignore (marked read), 2 Keep As +// New, 4 Delete. +// +// A list is one MIP message with, for each mail, a message of its own +// inside it: its id, author, subject and date, then an empty block. A +// mail read is a MIP message of its whole: id, author, addressee, +// subject, date and text. + +// The list tokens, and the mail each lists. +var mailLists = map[string]int{ + "m7": store.FolderUnread, + "m9": store.FolderInbox, + "m8": store.FolderSent, +} + +// The status changes in an m2. +const ( + mipStatusKeepNew = 2 + mipStatusDelete = 4 + mipStatusIgnore = 7 +) + +// mipListMax is the most mail a list holds. +const mipListMax = 100 + +// mipTextMax is the most text one mip_text or mip_data atom holds. +const mipTextMax = 0x4000 + +// mailList answers m7, m9 or m8: the mail of that list, newest first. +func (ss *session) mailList(tok string) { + folder := mailLists[tok] + all, err := ss.s.B.Store.Folder(ss.u.ID, folder) + if err != nil { + ss.logf("%s: %v", tok, err) + ss.notice("Your mail can't be listed just now.") + return + } + if folder == store.FolderInbox { + // Old Mail: what has been read; New Mail has the rest + read := all[:0:0] + for _, m := range all { + if m.Read { + read = append(read, m) + } + } + all = read + } + if len(all) == 0 { + ss.notice(map[int]string{ + store.FolderUnread: "You have no unread mail.", + store.FolderInbox: "You have no old mail.", + store.FolderSent: "You have sent no mail.", + }[folder]) + return + } + fs := []fdo.Frame{fdo.F("uni_start_stream"), fdo.F("mip_start_message")} + for i := len(all) - 1; i >= 0 && len(all)-i <= mipListMax; i-- { + m := all[i] + who := m.From + if folder == store.FolderSent { + who = m.To + } + fs = append(fs, + fdo.F("mip_start_message"), + fdo.F("mip_message_id", mipID(m.ID)...), + fdo.F("mip_author", fdo.Latin1(who)...), + fdo.F("mip_subject", fdo.Latin1(m.Subject)...), + fdo.F("mip_message_datestr", fdo.Latin1(m.Created.Format("01/02/06"))...), + fdo.F("mip_start_block"), + fdo.F("mip_end_block"), + fdo.F("mip_end_message")) + } + fs = append(fs, fdo.F("mip_end_message"), fdo.F("uni_wait_off"), fdo.F("uni_end_stream")) + ss.sendFrames(fs) +} + +// readMIP answers m3: one mail, whole, and marks it read. +func (ss *session) readMIP(body []byte) { + frames := mipFrames(body) + id, ok := mipNumber(frames, "mip_preset_message_id") + if !ok { + ss.logf("m3 without a message id: % x", body) + ss.notice("That mail could not be found.") + return + } + st := ss.s.B.Store + m, err := st.Mail(ss.u.ID, id) + if errors.Is(err, store.ErrNotFound) { + m, err = ss.sentMail(id) + } + if err != nil { + if !errors.Is(err, store.ErrNotFound) { + ss.logf("m3 %d: %v", id, err) + } + ss.notice("That mail is not in your mailbox.") + return + } + if !m.Read && m.ToID == ss.u.ID { + st.MarkMailRead(ss.u.ID, m.ID) + } + fs := []fdo.Frame{ + fdo.F("uni_start_stream"), + fdo.F("mip_start_message"), + fdo.F("mip_message_id", mipID(m.ID)...), + fdo.F("mip_author", fdo.Latin1(m.From)...), + fdo.F("mip_addressee", fdo.Latin1(m.To)...), + fdo.F("mip_subject", fdo.Latin1(m.Subject)...), + fdo.F("mip_message_datestr", fdo.Latin1(m.Created.Format("01/02/06 15:04"))...), + } + text := fdo.Latin1(strings.ReplaceAll(m.Body, "\n", "\r\n")) + for name := "mip_text"; ; name = "mip_data" { + n := min(len(text), mipTextMax) + fs = append(fs, fdo.F(name, text[:n]...)) + if text = text[n:]; len(text) == 0 { + break + } + } + fs = append(fs, fdo.F("mip_end_message"), fdo.F("uni_wait_off"), fdo.F("uni_end_stream")) + ss.sendFrames(fs) +} + +// sentMail is a mail the user sent, by id. +func (ss *session) sentMail(id int64) (*store.Message, error) { + sent, err := ss.s.B.Store.Folder(ss.u.ID, store.FolderSent) + if err != nil { + return nil, err + } + for _, m := range sent { + if m.ID == id { + return m, nil + } + } + return nil, store.ErrNotFound +} + +// changeMail answers m2: Ignore, Keep As New or Delete, for each mail +// the New Mail window had picked. +func (ss *session) changeMail(body []byte) { + st := ss.s.B.Store + var id int64 + have := false + for _, f := range mipFrames(body) { + switch f.Name() { + case "mip_preset_message_id": + id, have = bigEndian(f.Data), true + case "mip_change_message_status": + if !have { + continue + } + var err error + switch n := bigEndian(f.Data); n { + case mipStatusIgnore: + err = st.MarkMailRead(ss.u.ID, id) + case mipStatusKeepNew: + err = st.MarkMailUnread(ss.u.ID, id) + case mipStatusDelete: + err = st.DeleteMail(ss.u.ID, id) + default: + ss.logf("m2: mail %d: status %d (not served)", id, n) + } + if err != nil && !errors.Is(err, store.ErrNotFound) { + ss.logf("m2: mail %d: %v", id, err) + } + have = false + } + } + ss.send(waitOff) +} + +// mipFrames are the atoms of an m2 or m3, with or without a stream id +// before them. +func mipFrames(body []byte) []fdo.Frame { + for _, skip := range []int{2, 0} { + if len(body) < skip { + continue + } + if fs, err := fdo.Decode(body[skip:]); err == nil { + if _, ok := fdo.Find(fs, "mip_preset_message_id"); ok { + return fs + } + } + } + return nil +} + +// mipNumber is the number an atom carries. +func mipNumber(frames []fdo.Frame, name string) (int64, bool) { + f, ok := fdo.Find(frames, name) + if !ok || len(f.Data) == 0 { + return 0, false + } + return bigEndian(f.Data), true +} + +// bigEndian is up to four bytes as a number. +func bigEndian(b []byte) int64 { + var n int64 + for _, c := range b[max(0, len(b)-4):] { + n = n<<8 | int64(c) + } + return n +} + +// mipID is a message id as MIP carries it: four bytes. +func mipID(id int64) []byte { + return []byte{byte(id >> 24), byte(id >> 16), byte(id >> 8), byte(id)} +} + +// sendFrames sends atoms built as frames. +func (ss *session) sendFrames(fs []fdo.Frame) { + if err := ss.sendAtoms(fdo.Encode(fs)); err != nil { + ss.logf("send: %v", err) + } +} diff --git a/internal/aol/session.go b/internal/aol/session.go index 2a285a1..69abbdb 100644 --- a/internal/aol/session.go +++ b/internal/aol/session.go @@ -96,6 +96,21 @@ func (ss *session) token(tok string, body []byte) { } return } + switch tok { + case "m7", "m8", "m9", "m3", "m2": // the mail tool's buffers: no stream to piece together + if !ss.signedOn() { + return + } + switch tok { + case "m3": + ss.readMIP(body) + case "m2": + ss.changeMail(body) + default: + ss.mailList(tok) + } + return + } sid, atoms := splitStream(tok, body) if atoms = ss.whole(tok, sid, atoms); atoms == nil { return // more to come diff --git a/internal/store/mailbox.go b/internal/store/mailbox.go index 1ed5c38..12dbfb9 100644 --- a/internal/store/mailbox.go +++ b/internal/store/mailbox.go @@ -386,6 +386,11 @@ func (s *Store) MarkMailRead(user, id int64) error { return s.onReceived(user, id, `UPDATE mailbox SET "read" = TRUE WHERE id = ?`) } +// MarkMailUnread marks a mail of user's not yet read. +func (s *Store) MarkMailUnread(user, id int64) error { + return s.onReceived(user, id, `UPDATE mailbox SET "read" = FALSE WHERE id = ?`) +} + // DeleteMail puts a mail of user's in their trash. func (s *Store) DeleteMail(user, id int64) error { return s.onReceived(user, id, `UPDATE mailbox SET deleted = ? WHERE id = ?`, now())