From e67c5ff3dc29ff5775a1ded57d761f19ff985903 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 12:30:20 +0000 Subject: [PATCH] CompuServe Mail on the BBS's private mail GO MAIL enters CompuServe Mail: menu, prompt and command (Mail!) modes, with the Options and Mode menus and the permanent-settings question that TAPCIS's PARAMS.SCR answers, kept as cis-mail* user settings. READ with Action! after each message, SCAN, COMPOSE, UPLOAD (TAPCIS's UPL/PRO:B/TYP:ASCII), DOWNLOAD by any protocol, DELETE, ADDRESS (NAME and a session address book), SET. Addresses take CompuServe's forms: names, User IDs, 'Name >NET:addr', INTERNET:ppn@compuserve.com for a member, FidoNet netmail; other networks are refused. /GO:MAIL at the User ID enters it. The library download's transfer is split out to share. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRRPWCkk1Ro91AuzXFM --- docs/cis/02-terminal-ux.md | 43 ++ docs/wiki/CompuServe.md | 47 +- internal/bbs/prefs.go | 5 + internal/cis/ascii.go | 22 +- internal/cis/cis.go | 1 + internal/cis/library.go | 29 +- internal/cis/mail.go | 1005 +++++++++++++++++++++++++++++++ internal/cis/pages.txt | 13 +- internal/server/cismail_test.go | 153 +++++ 9 files changed, 1296 insertions(+), 22 deletions(-) create mode 100644 internal/cis/mail.go create mode 100644 internal/server/cismail_test.go diff --git a/docs/cis/02-terminal-ux.md b/docs/cis/02-terminal-ux.md index 2392d77..9381134 100644 --- a/docs/cis/02-terminal-ux.md +++ b/docs/cis/02-terminal-ux.md @@ -16,6 +16,7 @@ Tags: **[V]** verbatim from a capture or period document (blank-line runs and AN | S6–S8 | 1993–94 Mac captures (logon, Mail, forum JOIN, RATES, BILLING, command summary). Discmaster item 19202 (`King.img`, `Alexander.img`). | | S9 | 1995 Navigator session. Discmaster item 20868. | | S10 | TAPCIS 5.3 (1990): manual TAPDOC.1–10, PARAMS.SCR, CIS.SCR, TYMNET.SCR, SPRINT24.SCR, strings in TAPCIS.EXE. | +| S19 | TAPCIS 5.42 (1994): PARAMS.SCR (5.4, 12/10/91), FRONTEND.SCR, TAPCIS.HLP, strings in TAPCIS.EXE. | | S11 | *Forum Software Version 4D Complete Command Listing*, May 1989. | | S12 | IBM PC SIG help text, Nov 1983. | | S13 | Conference/CB help, 1982–84. | @@ -569,6 +570,48 @@ Enter choice or for more ! - Error: `% Invalid command`. - Mode menu: `Mail Mode Menu 1 MENU 2 PROMPT 3 COMMAND`, followed by `Make changes permanent for future Mail sessions ? (Y or N)`. - Settings: `set edit noline`, `set page off`. + +**TAPCIS 5.42's Mail setup, verbatim from PARAMS.SCR** [V, S19]. Each line TAPCIS sends waits for `!`: + +``` +S go mail (the Mail Main Menu or "Mail!"; "No messages pending") +S no ("% Invalid command": an answer to "first visit in 30 days?") +S set edit noline +S set page off +S set retain YES (RETAIN: UNDELETE within 24 hours) +S set Mail Options Menu + [ ] Represents Current Setting + (yes/no options toggle) + 1 EDITOR uses line numbers [NO] + 2 MODE of operation is [MENU] + (MENU, PROMPT, COMMAND) + 3 Output is PAGED [NO] +S 2 Mail Mode Menu + 1 MENU - (Novice User) + List of choices in menu form. + 2 PROMPT - (Intermediate User) + Brief list of commands. + 3 COMMAND - (Expert User) + One word prompt. +S 3 (the Options Menu again, MODE [COMMAND]) +S Make changes permanent for + future Mail sessions ? (Y or N) +S Y +S ADD (the Address Book) +S NAME Enter a period to erase any information, or to leave it unchanged. + Typing "CANCEL" cancels all changes made and leaves editing mode. + Your CompuServe Mail name + Old: Harold Bender + New: (TAPCIS sends the name) + Do you want to enter your return address? (Y or N) ! +S ^C +``` + +The script's comments show the Address Book menu as `1 INSERT an entry 2 CHANGE an entry 3 DELETE an entry 4 LIST Address Book 5 Enter/Change your NAME`, and say that NOLINE and PAGE OFF "are essential settings for TAPCIS". + +**What TAPCIS.EXE waits for and sends in Mail** [V, S19, strings only, so the order is inferred]: it waits for `lex!` or `ail!` (EasyPlex! and Mail!), `ID):` (`Send to (Name or User ID):`), `ect:` (`Subject:`), `N)!` / `N)?`, `Action!` and `on!`. It reads with `read all` and `REA WAI`, matches `ate:`, `rom:` and `ubj:` in headers, downloads binary items with `dow/pro:b`, deletes with `DEL`, and sends with `Compose` and `/EX`, or with `UPL/PRO:B/TYP:ASCII MAIL%.TMP` (`/TYP:LATIN1` with its /LATIN1 option; "Be patient after UPL after Send? Y answer"). Addresses take `>INTERNET:`, `>FAX`, `>POSTAL`, `>X400`, `>MCIMAIL:`, `>MHS:` and `>TLX:`, a trailing `/R` for a return receipt, and `;` for another address. + +**The service's choices where the sources are silent** [I]: the send confirmation is `Send? (Y or N)!`, the result is `Message sent to Name [ppn]`, and the read prompt in command mode is `Action!`. - Return receipts cost a $0.25 surcharge [P]. **Address forms:** diff --git a/docs/wiki/CompuServe.md b/docs/wiki/CompuServe.md index 4dd0640..36bedb3 100644 --- a/docs/wiki/CompuServe.md +++ b/docs/wiki/CompuServe.md @@ -135,6 +135,50 @@ BPLUS.ZIP/binary 08-Nov-26 8700 Accesses: 1 Keywords: BPLUS PROTOCOL ``` +## Mail + +`GO MAIL` (or `EASY`, `EASYPLEX`) enters CompuServe Mail. It is the BBS's +private mail: what is sent here arrives in the BBS's mailbox, and the +other way round. A message is *pending* until it is read. Read messages +stay in the mailbox, as if saved, until they are deleted. + +Mail starts in menu mode, as CompuServe's did. `SET` opens the Options +Menu, where option 2 changes the mode to PROMPT or COMMAND, and the +answer to `Make changes permanent for future Mail sessions ? (Y or N) !` +keeps it with the account. TAPCIS's setup script (`PARAMS.SCR`, run by +Alt-P) does exactly this, then `set edit noline` and `set page off`, which +are kept too. In command mode the prompt is `Mail!`. + +| Command | Does | +|---|---| +| `READ [n\|ALL\|SAVED]` | read the pending messages (or the saved ones); `Action!` after each: CR next, `DELETE`, `SAVE`, `REREAD`, `REPLY`, `FORWARD [address]`, `DOWNLOAD [/PROTO:x]` | +| `SCAN [ALL\|SAVED]` | one line each: ` 1 alice/Testing` | +| `COMPOSE [address]` | write (EDIT, ending with `/EX`), then `Send to (Name or User ID):`, `Subject:` and `Send? (Y or N)!` | +| `UPLOAD [/PRO:B] [/TYP:ASCII\|LATIN1]` | a message's text by a protocol, then the same questions (TAPCIS's `UPL/PRO:B/TYP:ASCII MAIL%.TMP`) | +| `DOWNLOAD [n\|ALL\|SAVED] [/PROTO:x]` | messages as one text file, by a protocol | +| `DELETE n` | delete a message | +| `ADDRESS` | the address book, and `NAME` for your Mail name (both for this session only) | +| `SET`, `SET MODE x`, `SET EDIT x`, `SET PAGE x`, `MODE` | the options | +| `EXIT`, `T`, `GO x`, `OFF` | leave Mail | + +Addresses take CompuServe's forms: a BBS name, a User ID (`72000,1`), a +name and an ID (`Sysop 72000,2`, `Sysop [72000,2]`), or a name and a +network address after `>`. `INTERNET:72000.1@compuserve.com` is a member +here. Other Internet addresses, FAX, POSTAL, MCIMAIL, X.400 and MHS are +refused, with a message saying so. A FidoNet address (`Bob@1:234/5`) goes +out as netmail when the BBS is on FidoNet. An address ending in `;` asks +for another, and a `/R` (return receipt) is accepted but not acted on. + +A message reads like this: + +``` +Date: 08-Nov-26 12:40 UTC +From: alice [72000,1] +Subj: Testing + +Hello from Mail. +``` + ## What is there and what is coming | Done | Coming, in order | @@ -143,7 +187,8 @@ BPLUS.ZIP/binary 08-Nov-26 8700 Accesses: 1 | Forums on the message areas, with the forum command language | | | The CompuServe B, Quick B and B Plus protocols (`internal/xfer/cisb.go`) | B Plus resume (Tr) and file information (TI) | | Libraries on the file areas, with B+ downloads and uploads | | -| | CompuServe Mail, the CB Simulator, then CIM's HMI service | +| CompuServe Mail on the BBS's private mail | A kept address book, binary mail | +| | The CB Simulator, then CIM's HMI service | The research behind all this, with sources, is in [docs/cis](https://github.com/D-Modem/bbs/tree/main/docs/cis). diff --git a/internal/bbs/prefs.go b/internal/bbs/prefs.go index cacdec1..708e599 100644 --- a/internal/bbs/prefs.go +++ b/internal/bbs/prefs.go @@ -22,6 +22,11 @@ var prefValues = map[string][]string{ "width": {"40", "80"}, // a Commodore's columns "editor": {"full", "line"}, // the full-screen editor, or the line editor "expert": {"on", "off"}, // menus as their prompt alone (? for the rest) + + // CompuServe Mail's options (SET at "Mail!"), kept when the caller says + "cis-mailmode": {"menu", "prompt", "command"}, + "cis-mailedit": {"line", "noline"}, + "cis-mailpage": {"on", "off"}, } // PrefKeys are the settings' names, sorted. diff --git a/internal/cis/ascii.go b/internal/cis/ascii.go index 3b547b1..3fbee45 100644 --- a/internal/cis/ascii.go +++ b/internal/cis/ascii.go @@ -12,13 +12,19 @@ var errRelog = errors.New("cis: LOG") // ascii is the terminal service, from the banner to the logoff. func (s *session) ascii() error { s.banner() - first := s.pages.Get("TOP") - if s.firstGo != "" { - if p := s.pages.Get(s.firstGo); p != nil { - first = p + top := s.pages.Get("TOP") + switch p := s.pages.Get(s.firstGo); { + case s.firstGo == "" || !s.known(s.firstGo): + s.show(top) + case p != nil && p.ID != "MAIL": + s.show(p) + default: + // /GO:word to a forum or Mail: in it first, TOP when it is left + s.page, s.stack, s.menus = top, []*Page{top}, []*Page{top} + if err := s.goWord(s.firstGo); err != nil { + return err } } - s.show(first) for { line, err := s.prompt(s.promptFor()) if errors.Is(err, errAbort) { @@ -156,7 +162,11 @@ func (s *session) goWord(word string) error { if f := s.forum(word); f != nil && s.pages.Get(word) == nil { return s.enterForum(f) } - s.goTo(s.pages.Get(word)) + p := s.pages.Get(word) + if p != nil && p.ID == "MAIL" { + return s.enterMail() + } + s.goTo(p) return nil } diff --git a/internal/cis/cis.go b/internal/cis/cis.go index 91cb75b..bcac0b0 100644 --- a/internal/cis/cis.go +++ b/internal/cis/cis.go @@ -65,6 +65,7 @@ type session struct { firstGo string // /GO:word at the User ID byName bool // logged on with a BBS name, not a User ID fpage *Page // the FORUMS menu, as last made + mail *mailState pushed []byte // input put back cr bool // the last input byte was a CR (drop a LF or NUL after it) } diff --git a/internal/cis/library.go b/internal/cis/library.go index 96d2f85..694abe2 100644 --- a/internal/cis/library.go +++ b/internal/cis/library.go @@ -514,45 +514,54 @@ func (s *session) download(lib *store.FileArea, arg string) error { } defer in.Close() s.node.Doing("CompuServe: downloading " + f.Name) - binary := !textFile(f.Name) + if err := s.send(proto, xfer.Outgoing{Name: f.Name, Size: f.Size, ModTime: f.Created, Data: in}, !textFile(f.Name)); err != nil { + return nil + } + s.b.Downloaded(s.user, f) + s.b.Log.Printf("node %d: %s downloaded %q by %s (%d bytes)", s.node.Num, s.user.Name, f.Name, proto, f.Size) + return nil +} + +// send sends a file by a protocol of chooseProtocol's, and says how it +// went: an error is the transfer's, already told and logged. +func (s *session) send(proto string, o xfer.Outgoing, binary bool) error { p := port{s} + var err error switch proto { case "B", "QB": k := xfer.NewBLink(p) if err = k.Start(xfer.HostParams); err == nil { - _, err = k.SendFile(strings.ToUpper(f.Name), binary, in) + _, err = k.SendFile(strings.ToUpper(o.Name), binary, o.Data) } if errors.Is(err, xfer.ErrTimeout) && !k.Plus { s.out("\nYour terminal does not support the B protocol.\n") } case "XMODEM": s.out("Starting XMODEM transfer\n\nPlease initiate XMODEM transfer\nand press when the transfer\nis complete.\n") - err = xfer.SendXMODEM(p, xfer.Outgoing{Name: f.Name, Size: f.Size, ModTime: f.Created, Data: in}, false) + err = xfer.SendXMODEM(p, o, false) s.waitCR() case "KERMIT": s.out("Starting KERMIT transfer\n\nPlease initiate KERMIT transfer\nand press when the transfer\nis complete.\n") - err = xfer.SendKermit(p, []xfer.Outgoing{{Name: f.Name, Size: f.Size, ModTime: f.Created, Data: in}}) + err = xfer.SendKermit(p, []xfer.Outgoing{o}) s.waitCR() case "CAPTURE": if binary { s.out("Only ASCII files can be captured.\n") - return nil + return errors.New("binary capture") } s.line.Write([]byte{0x12}) // DC2: capture on var b []byte - if b, err = io.ReadAll(io.LimitReader(in, 4<<20)); err == nil { + if b, err = io.ReadAll(io.LimitReader(o.Data, 4<<20)); err == nil { s.out(strings.ReplaceAll(string(b), "\r\n", "\n")) } s.line.Write([]byte{0x14}) // DC4: capture off s.out("\n") } if err != nil { - s.b.Log.Printf("node %d: CompuServe: %s download of %s failed: %v", s.node.Num, proto, f.Name, err) + s.b.Log.Printf("node %d: CompuServe: %s download of %s failed: %v", s.node.Num, proto, o.Name, err) s.out("\nTransfer aborted.\n") - return nil + return err } - s.b.Downloaded(s.user, f) - s.b.Log.Printf("node %d: %s downloaded %q by %s (%d bytes)", s.node.Num, s.user.Name, f.Name, proto, f.Size) if proto != "B" && proto != "QB" { s.out("Transfer complete.\n") } diff --git a/internal/cis/mail.go b/internal/cis/mail.go new file mode 100644 index 0000000..bceb10d --- /dev/null +++ b/internal/cis/mail.go @@ -0,0 +1,1005 @@ +package cis + +import ( + "bytes" + "errors" + "fmt" + "strconv" + "strings" + "time" + "unicode/utf8" + + "github.com/D-Modem/bbs/internal/store" + "github.com/D-Modem/bbs/internal/xfer" +) + +// CompuServe Mail on the BBS's private mail. The wording is TAPCIS's: its +// PARAMS.SCR (5.4, 1991) and the strings it waits for ("Mail!", "ID):", +// "ect:", "Action!"), and 1993 captures of menu mode. A message is +// "pending" until it is read; read ones stay in the BBS's mailbox (as if +// SAVEd) until deleted. + +// Mail's modes of operation. +const ( + mailMenu = "menu" + mailPrompt = "prompt" + mailCommand = "command" +) + +// mailState is a session's Mail settings and its list of messages. +type mailState struct { + mode string + lineEdit bool // EDITOR uses line numbers + paged bool + retain bool + name string // the Mail name (ADDRESS NAME), for this session + book map[string]string // the address book: name to address, for this session + list []*store.Message // the messages as last listed, numbered from 1 +} + +// mailPrefs are the users' kept settings (bbs.Prefs). +const ( + prefMailMode = "cis-mailmode" + prefMailEdit = "cis-mailedit" + prefMailPage = "cis-mailpage" +) + +// errLeaveMail ends Mail, its leaving done by the func carried. +type leaveMail struct{ then func() error } + +func (l leaveMail) Error() string { return "cis: leaving Mail" } + +// mailSettings are the session's, from the kept ones the first time. +func (s *session) mailSettings() *mailState { + if s.mail != nil { + return s.mail + } + p := s.node.Prefs() + m := &mailState{mode: mailMenu, book: map[string]string{}} + switch p[prefMailMode] { + case mailPrompt, mailCommand: + m.mode = p[prefMailMode] + } + m.lineEdit = p[prefMailEdit] == "line" + m.paged = p[prefMailPage] == "on" + s.mail = m + return m +} + +// keepMailSettings makes the settings permanent. +func (s *session) keepMailSettings() { + m := s.mail + edit, page := "noline", "off" + if m.lineEdit { + edit = "line" + } + if m.paged { + page = "on" + } + for k, v := range map[string]string{prefMailMode: m.mode, prefMailEdit: edit, prefMailPage: page} { + if err := s.node.SetPref(k, v); err != nil { + s.b.Log.Printf("node %d: CompuServe: keeping %s: %v", s.node.Num, k, err) + } + } +} + +// pending are the user's unread messages. +func (s *session) pending() []*store.Message { + all, err := s.b.Store.Inbox(s.user.ID) + if err != nil { + s.b.Log.Printf("node %d: CompuServe: mail: %v", s.node.Num, err) + return nil + } + var out []*store.Message + for _, m := range all { + if !m.Read { + out = append(out, m) + } + } + return out +} + +// saved are the user's read messages. +func (s *session) saved() []*store.Message { + all, _ := s.b.Store.Inbox(s.user.ID) + var out []*store.Message + for _, m := range all { + if m.Read { + out = append(out, m) + } + } + return out +} + +func pendingLine(n int) string { + switch n { + case 0: + return "No messages pending" + case 1: + return "1 message pending" + } + return fmt.Sprintf("%d messages pending", n) +} + +// enterMail is GO MAIL: its prompt (or menu) until the caller leaves. +func (s *session) enterMail() error { + m := s.mailSettings() + s.node.Doing("CompuServe: Mail") + m.list = s.pending() + s.out("\nCompuServe Mail\n\n") + if m.mode == mailMenu { + s.mailMenu() + } else { + s.out(pendingLine(len(m.list)) + "\n\n") + } + for { + line, err := s.prompt(s.mailPromptFor()) + if errors.Is(err, errAbort) { + continue + } + if err != nil { + return err + } + if err := s.mailCommands(line); err != nil { + var l leaveMail + if errors.As(err, &l) { + return l.then() + } + return err + } + } +} + +func (s *session) mailPromptFor() string { + switch s.mail.mode { + case mailMenu: + return s.choicePrompt("Enter choice !") + case mailPrompt: + s.out("READ, SCAN, COMPOSE, UPLOAD, DOWNLOAD, ADDRESS, SET, HELP or EXIT\n") + } + return "Mail!" +} + +// mailMenu is the Main Menu. +func (s *session) mailMenu() { + n := len(s.pending()) + s.out("CompuServe Mail Main Menu\n\n") + s.outf(" 1 READ mail, %s\n", strings.ToLower(pendingLine(n)[:1])+pendingLine(n)[1:]) + s.out(" 2 COMPOSE a new message\n 3 UPLOAD a message\n 4 USE a file from PER area\n 5 ADDRESS Book\n 6 SET options\n\n") +} + +// mailCommands does a line of Mail commands, separated by ";". +func (s *session) mailCommands(line string) error { + for _, c := range strings.Split(line, ";") { + if err := s.mailCommand(strings.TrimSpace(c)); err != nil { + return err + } + } + return nil +} + +// mailCommand does a Mail command. At the menu, a number is its choice. +func (s *session) mailCommand(c string) error { + m := s.mail + verb, arg := splitVerb(c) + if m.mode == mailMenu && isNumber(verb) { + switch verb { + case "1": + return s.readMenu() + case "2": + return s.compose("", nil) + case "3": + return s.mailUpload("") + case "4": + s.out("There is no PER area on this service.\n") + case "5": + return s.addressBook() + case "6": + return s.mailOptions() + default: + s.out(verb + " is not a choice !\n") + } + return nil + } + switch { + case c == "": + if m.mode == mailMenu { + s.mailMenu() + } + case is(verb, "READ", 2): + return s.mailRead(arg) + case is(verb, "SCAN", 2) || is(verb, "LIST", 2) || is(verb, "DIRECTORY", 3): + s.mailScan(arg) + case is(verb, "COMPOSE", 3) || is(verb, "CREATE", 2) || is(verb, "SEND", 3): + return s.compose(arg, nil) + case is(verb, "UPLOAD", 3): + return s.mailUpload(arg) + case is(verb, "DOWNLOAD", 3): + n, rest := mailArg(arg) + return s.mailDownload(s.mailPick(n), rest) + case is(verb, "DELETE", 3) || is(verb, "ERASE", 2): + ms := s.mailPick(arg) + if len(ms) == 0 { + s.out("% No such message\n") + } + for _, msg := range ms { + s.mailDelete(msg) + } + case is(verb, "ADDRESS", 3): + if arg != "" { + return s.addressCommand(arg) + } + return s.addressBook() + case is(verb, "SET", 3): + if arg == "" { + return s.mailOptions() + } + s.mailSet(arg) + case is(verb, "MODE", 2): + return s.mailMode() + case verb == "M" || is(verb, "MENU", 4) || is(verb, "MAIN", 4): + s.mailMenu() + case is(verb, "HELP", 1) || verb == "?": + s.mailHelp() + case is(verb, "EXIT", 2) || is(verb, "QUIT", 4): + return leaveMail{func() error { s.show(s.page); return nil }} + case verb == "T" || is(verb, "TOP", 3): + return leaveMail{func() error { s.goTo(s.pages.Get("TOP")); return nil }} + case verb == "G" || is(verb, "GO", 2): + w := arg + return leaveMail{func() error { return s.command("GO " + w) }} + case is(verb, "OFF", 3) || is(verb, "BYE", 3): + return leaveMail{func() error { s.logoff(); return errHangup }} + case is(verb, "LOG", 3): + return leaveMail{func() error { s.logoff(); return errRelog }} + default: + s.out("% Invalid command\n") + } + return nil +} + +// mailArg splits "3 /PRO:B" into "3", "/PRO:B". +func mailArg(arg string) (string, string) { + if i := strings.Index(arg, "/"); i >= 0 { + return strings.TrimSpace(arg[:i]), arg[i:] + } + return strings.TrimSpace(arg), "" +} + +// mailPick is the messages an argument names: numbers of the list (or +// ALL, or none for all pending). +func (s *session) mailPick(arg string) []*store.Message { + m := s.mail + arg = strings.ToUpper(strings.TrimSpace(arg)) + switch arg { + case "", "ALL", "NEW", "WAITING", "WAI", "PENDING": + m.list = s.pending() + return m.list + case "SAVED", "SAV", "OLD", "FILED": + m.list = s.saved() + return m.list + } + var out []*store.Message + for _, f := range strings.FieldsFunc(arg, func(r rune) bool { return r == ',' || r == ' ' }) { + lo, hi, isRange := strings.Cut(f, "-") + a, err := strconv.Atoi(lo) + if err != nil { + continue + } + b := a + if isRange { + if b, err = strconv.Atoi(hi); err != nil { + b = len(m.list) + } + } + for i := a; i <= b && i <= len(m.list); i++ { + if i >= 1 { + out = append(out, m.list[i-1]) + } + } + } + return out +} + +// fromLine is a message's sender: "Name [72000,1]". +func fromLine(msg *store.Message) string { + if msg.FromID > 0 { + return fmt.Sprintf("%s [%s]", msg.From, PPN(msg.FromID)) + } + return msg.From +} + +// mailScan lists messages as the Read Menu does: " 1 Name/Subject". +func (s *session) mailScan(arg string) { + ms := s.mailPick(arg) + if len(ms) == 0 { + s.out("No messages pending\n") + return + } + for i, msg := range ms { + s.outf("%s %s/%s\n", padNum(i+1, len(ms)), msg.From, msg.Subject) + } +} + +// readMenu is the menu's READ: the list, then a choice. +func (s *session) readMenu() error { + m := s.mail + m.list = s.pending() + if len(m.list) == 0 { + s.out("No messages pending\n") + return nil + } + s.out("CompuServe Mail Read Menu\n\n") + for i, msg := range m.list { + s.outf("%3d %s/%s\n", i+1, msg.From, msg.Subject) + } + s.outf("\n 0 READ ALL %d messages\n", len(m.list)) + for { + c, err := s.prompt(s.choicePrompt("Last page. Enter choice or M for CompuServe Mail main menu !")) + if err != nil { + return s.abortOK0(err) + } + c = strings.ToUpper(strings.TrimSpace(c)) + switch { + case c == "M" || c == "": + s.mailMenu() + return nil + case c == "0": + return s.readMessages(m.list) + case isNumber(c): + ms := s.mailPick(c) + if len(ms) == 0 { + s.out(c + " is not a choice !\n") + continue + } + return s.readMessages(ms) + default: + return s.mailCommand(c) + } + } +} + +// mailRead is READ [n|ALL|SAVED]. +func (s *session) mailRead(arg string) error { + ms := s.mailPick(arg) + if len(ms) == 0 { + if strings.TrimSpace(arg) == "" || strings.EqualFold(strings.TrimSpace(arg), "ALL") { + s.out("No messages pending\n") + } else { + s.out("% No such message\n") + } + return nil + } + return s.readMessages(ms) +} + +// mailText is a message as it is read and downloaded: +// +// Date: 18-Apr-93 22:19 EDT +// From: Deron Kazmaier [76317,3633] +// Subj: Hello +func mailText(msg *store.Message) []string { + lines := []string{ + "Date: " + msg.Created.Format("02-Jan-06 15:04 MST"), + "From: " + fromLine(msg), + "Subj: " + msg.Subject, + "", + } + body := strings.TrimRight(strings.ReplaceAll(msg.Body, "\r\n", "\n"), "\n") + return append(lines, strings.Split(body, "\n")...) +} + +// readMessages reads messages one by one, each with its action prompt. +func (s *session) readMessages(ms []*store.Message) error { + for i := 0; i < len(ms); i++ { + msg := ms[i] + s.out("\n") + lines := mailText(msg) + if s.mail.paged && s.lines > 0 { + s.pageOut(lines) + } else { + for _, l := range lines { + s.out(l + "\n") + } + } + s.out("\n") + if !msg.Read { + s.b.Store.MarkMailRead(s.user.ID, msg.ID) + msg.Read = true + } + again, rest, err := s.mailAction(msg) + if err != nil { + return err + } + if again { + i-- + continue + } + if rest != "" { + return s.mailCommands(rest) + } + } + if s.mail.mode == mailMenu { + s.mailMenu() + } + return nil +} + +// mailAction is what to do with a message read: CR for the next, or +// DELETE, SAVE, REREAD, REPLY, FORWARD, DOWNLOAD. Anything else ends the +// reading and is done as a Mail command (rest). +func (s *session) mailAction(msg *store.Message) (again bool, rest string, err error) { + menu := s.mail.mode == mailMenu + p := "Action!" + if menu { + s.out(" 1 DELETE this message\n 2 FILE in PER area\n 3 FORWARD\n 4 REREAD message\n 5 REPLY\n 6 SAVE in mailbox\n 7 DOWNLOAD message\n\n") + p = s.choicePrompt("Enter choice or for next !") + } + for { + c, err := s.prompt(p) + if errors.Is(err, errAbort) { + return false, "", nil + } + if err != nil { + return false, "", err + } + c = strings.TrimSpace(c) + verb, arg := splitVerb(c) + if menu { + if n, ok := map[string]string{"1": "DELETE", "2": "FILE", "3": "FORWARD", "4": "REREAD", "5": "REPLY", "6": "SAVE", "7": "DOWNLOAD"}[verb]; ok { + verb = n + } + } + switch { + case c == "" || verb == "N" || is(verb, "NEXT", 2): + return false, "", nil + case is(verb, "DELETE", 3): + s.mailDelete(msg) + return false, "", nil + case is(verb, "SAVE", 2) || is(verb, "KEEP", 2): + s.out("Message saved\n") + return false, "", nil + case is(verb, "REREAD", 3): + return true, "", nil + case is(verb, "REPLY", 3): + return false, "", s.compose(fromAddress(msg), msg) + case is(verb, "FORWARD", 3): + return false, "", s.forward(msg, arg) + case is(verb, "DOWNLOAD", 3): + return false, "", s.mailDownload([]*store.Message{msg}, arg) + case is(verb, "FILE", 2): + s.out("There is no PER area on this service.\n") + case menu && isNumber(verb): + s.out(verb + " is not a choice !\n") + default: + return false, c, nil + } + } +} + +// fromAddress is where a reply to a message goes. +func fromAddress(msg *store.Message) string { + if msg.FromID > 0 { + return msg.From + " " + PPN(msg.FromID) + } + return msg.From +} + +func (s *session) mailDelete(msg *store.Message) { + if err := s.b.Store.DeleteMail(s.user.ID, msg.ID); err != nil { + s.out("% Cannot delete message\n") + return + } + s.out("Message deleted\n") +} + +// mailDownload sends messages as a text file, by a protocol. +func (s *session) mailDownload(ms []*store.Message, arg string) error { + if len(ms) == 0 { + s.out("No messages pending\n") + return nil + } + var b bytes.Buffer + for _, msg := range ms { + for _, l := range mailText(msg) { + b.WriteString(l + "\r\n") + } + b.WriteString("\r\n") + } + s.outf("%d message%s and %d characters ready for download\n", len(ms), plural(len(ms)), b.Len()) + proto, err := s.chooseProtocol(protoArg(arg)) + if err != nil || proto == "" { + return err + } + s.node.Doing("CompuServe: downloading mail") + if err := s.send(proto, xfer.Outgoing{Name: "MAIL.TXT", Size: int64(b.Len()), ModTime: time.Now(), Data: &b}, false); err != nil { + return nil + } + for _, msg := range ms { + if !msg.Read { + s.b.Store.MarkMailRead(s.user.ID, msg.ID) + msg.Read = true + } + } + s.out("*** File Transfer Completed! ***\n") + return nil +} + +func plural(n int) string { + if n == 1 { + return "" + } + return "s" +} + +// protoArg is /PROTO:x (or /PRO:x) of an argument, in capitals. +func protoArg(arg string) string { + for _, f := range strings.FieldsFunc(arg, func(r rune) bool { return r == ' ' || r == '/' }) { + if k, v, ok := strings.Cut(f, ":"); ok && is(strings.ToUpper(k), "PROTOCOL", 3) { + return strings.ToUpper(v) + } + } + return "" +} + +// recipient is an address resolved: the name the BBS's mail takes, and +// how it is shown. +type recipient struct{ to, shown string } + +// resolveAddress reads an address in CompuServe's forms: +// +// 72000,1 Alice 72000,1 Alice [72000,1] alice +// Alice >INTERNET:72000.1@compuserve.com Bob@1:234/5 (FidoNet) +// +// A name in the address book is its address. +func (s *session) resolveAddress(a string) (recipient, error) { + a = strings.TrimSpace(a) + if i := strings.Index(strings.ToUpper(a), "/R"); i >= 0 && i == len(a)-2 { + a = strings.TrimSpace(a[:i]) // return receipt: not kept + } + if addr, ok := s.mail.book[strings.ToUpper(a)]; ok { + a = addr + } + name := "" + if i := strings.Index(a, ">"); i >= 0 { + name, a = strings.TrimSpace(a[:i]), strings.TrimSpace(a[i+1:]) + } else if i := strings.LastIndex(a, " "); i >= 0 { + if _, ok := ParsePPN(strings.Trim(a[i+1:], "[]")); ok { + name, a = strings.TrimSpace(a[:i]), strings.Trim(a[i+1:], "[]") + } + } + a = strings.Trim(a, "[]") + if net, rest, ok := strings.Cut(a, ":"); ok && !strings.Contains(a, "@") || ok && strings.EqualFold(net, "INTERNET") { + switch strings.ToUpper(strings.TrimSpace(net)) { + case "INTERNET": + user, host, _ := strings.Cut(strings.TrimSpace(rest), "@") + if strings.EqualFold(host, "compuserve.com") { + if id, ok := ParsePPN(strings.Replace(user, ".", ",", 1)); ok { + a = PPN(id) + break + } + } + return recipient{}, errors.New("Internet mail is not offered on this service") + case "FAX", "POSTAL", "MCIMAIL", "X400", "MHS", "TLX", "TELEX", "EMS": + return recipient{}, fmt.Errorf("%s mail is not offered on this service", strings.ToUpper(net)) + default: + return recipient{}, errors.New("Invalid address") + } + } + if id, ok := ParsePPN(a); ok { + u, err := s.b.Store.UserByID(id) + if err != nil { + return recipient{}, errors.New("No such User ID") + } + return recipient{u.Name, u.Name + " [" + PPN(u.ID) + "]"}, nil + } + if a == "" { + a = name + } + if strings.Contains(a, "@") { + // FidoNet netmail: Name@zone:net/node + return recipient{a, a}, nil + } + u, err := s.b.Store.UserByName(a) + if err != nil { + return recipient{}, errors.New("No such user") + } + return recipient{u.Name, u.Name + " [" + PPN(u.ID) + "]"}, nil +} + +// askAddresses asks "Send to"; an entry ending in ";" asks for another. +func (s *session) askAddresses(given string) ([]recipient, error) { + var out []recipient + entry := given + for { + if entry == "" { + var err error + if entry, err = s.prompt("Send to (Name or User ID): "); err != nil { + return nil, err + } + entry = strings.TrimSpace(entry) + if entry == "" { + return out, nil + } + } + more := strings.HasSuffix(entry, ";") + for _, a := range strings.Split(strings.TrimSuffix(entry, ";"), ";") { + if strings.TrimSpace(a) == "" { + continue + } + r, err := s.resolveAddress(a) + if err != nil { + s.outf("%% %s: %s\n", err, strings.TrimSpace(a)) + more = true + continue + } + out = append(out, r) + } + if !more { + return out, nil + } + entry = "" + } +} + +// compose is COMPOSE [address]: the text, then where it goes and its +// subject, then sent. re is the message replied to. +func (s *session) compose(to string, re *store.Message) error { + body, _, err := s.edit() + if err != nil { + return s.abortMail(err) + } + return s.sendMail(to, re, body) +} + +// sendMail asks the addresses and the subject of a message, and sends it. +func (s *session) sendMail(to string, re *store.Message, body []string) error { + rcpts, err := s.askAddresses(to) + if err != nil { + return s.abortMail(err) + } + if len(rcpts) == 0 { + s.out("Message not sent\n") + return nil + } + subject := "" + if re != nil { + subject = re.Subject + s.outf("Subject: %s\n", subject) + } else if subject, err = s.prompt("Subject: "); err != nil { + return s.abortMail(err) + } + if strings.TrimSpace(subject) == "" { + subject = "(no subject)" + } + ok, err := s.prompt("Send? (Y or N)! ") + if err != nil { + return s.abortMail(err) + } + if !strings.HasPrefix(strings.ToUpper(strings.TrimSpace(ok)), "Y") { + s.out("Message not sent\n") + return nil + } + var replyTo int64 + if re != nil { + replyTo = re.ID + } + for _, r := range rcpts { + if err := s.node.SendMail(r.to, subject, body, replyTo); err != nil { + s.outf("%% Not sent to %s: %v\n", r.shown, err) + continue + } + s.outf("Message sent to %s\n", r.shown) + } + return nil +} + +// abortMail is an error of a prompt while writing: ^C gives up quietly. +func (s *session) abortMail(err error) error { + if errors.Is(err, errAbort) { + s.out("Message not sent\n") + return nil + } + return err +} + +// forward is FORWARD [address]: a message, with its header, to another. +func (s *session) forward(msg *store.Message, to string) error { + body := append([]string{"[Forwarded message]"}, mailText(msg)...) + re := &store.Message{Subject: msg.Subject} + return s.sendMail(strings.TrimSpace(to), re, body) +} + +// mailUpload is UPLOAD [/PRO:x] [/TYP:ASCII|LATIN1] [name]: a message's +// text by a protocol (TAPCIS's "UPL/PRO:B/TYP:ASCII MAIL%.TMP"), then sent. +func (s *session) mailUpload(arg string) error { + typ := "ASCII" + for _, f := range strings.FieldsFunc(arg, func(r rune) bool { return r == ' ' || r == '/' }) { + if k, v, ok := strings.Cut(f, ":"); ok && is(strings.ToUpper(k), "TYPE", 3) { + typ = strings.ToUpper(v) + } + } + if strings.HasPrefix(typ, "B") || strings.HasPrefix(typ, "GIF") { + s.out("Binary mail is not offered on this service.\n") + return nil + } + proto, err := s.chooseProtocol(protoArg(arg)) + if err != nil || proto == "" { + return err + } + if proto == "CAPTURE" { + s.out("Uploads are by XMODEM, Kermit or the B protocol.\n") + return nil + } + var buf bytes.Buffer + in := &incoming{w: &limited{&buf, 2 << 20}, abort: func() {}, commit: func() error { return nil }} + p := port{s} + s.node.Doing("CompuServe: uploading mail") + switch proto { + case "B", "QB": + k := xfer.NewBLink(p) + if err = k.Start(xfer.HostParams); err == nil { + _, err = k.ReceiveFile("MAIL.TXT", false, in, 2<<20) + } + default: + s.outf("Starting %s transfer\n\nPlease initiate %s transfer\nand press when the transfer\nis complete.\n", proto, proto) + sink := func(string, int64) (xfer.Incoming, error) { return in, nil } + if proto == "XMODEM" { + err = xfer.ReceiveXMODEM(p, sink) + } else { + err = xfer.ReceiveKermit(p, sink) + } + s.waitCR() + } + if err != nil { + s.b.Log.Printf("node %d: CompuServe: %s mail upload failed: %v", s.node.Num, proto, err) + s.out("\nTransfer aborted.\n") + return nil + } + data := buf.Bytes() + if proto == "XMODEM" { + data = bytes.TrimRight(data, "\x1a") // the last block's padding + } + text := string(data) + if typ == "LATIN1" || !utf8.ValidString(text) { + r := make([]rune, len(data)) + for i, c := range data { + r[i] = rune(c) + } + text = string(r) + } + text = strings.ReplaceAll(text, "\r\n", "\n") + body := strings.Split(strings.TrimRight(text, "\n"), "\n") + s.out("\n") + return s.sendMail("", nil, body) +} + +// limited is a writer that takes at most n bytes. +type limited struct { + b *bytes.Buffer + n int +} + +func (l *limited) Write(p []byte) (int, error) { + if l.b.Len()+len(p) > l.n { + return 0, errors.New("the message is too long") + } + return l.b.Write(p) +} + +// mailOptions is SET alone: the Options Menu, and at the end whether to +// keep the changes. +func (s *session) mailOptions() error { + m := s.mail + changed := false + for { + s.out("\nMail Options Menu\n\n[ ] Represents Current Setting\n (yes/no options toggle)\n\n") + s.outf(" 1 EDITOR uses line numbers [%s]\n", yesNo(m.lineEdit)) + s.outf(" 2 MODE of operation is [%s]\n (MENU, PROMPT, COMMAND)\n", strings.ToUpper(m.mode)) + s.outf(" 3 Output is PAGED [%s]\n\n", yesNo(m.paged)) + c, err := s.prompt(s.choicePrompt("Enter choice or to exit !")) + if err != nil { + return s.abortOK0(err) + } + switch strings.TrimSpace(c) { + case "": + if changed { + return s.askKeep() + } + return nil + case "1": + m.lineEdit, changed = !m.lineEdit, true + case "2": + if err := s.chooseMode(); err != nil { + return err + } + changed = true + case "3": + m.paged, changed = !m.paged, true + default: + s.out(strings.TrimSpace(c) + " is not a choice !\n") + } + } +} + +func yesNo(b bool) string { + if b { + return "YES" + } + return "NO" +} + +// chooseMode is the Mode Menu. +func (s *session) chooseMode() error { + s.out("\nMail Mode Menu\n\n 1 MENU - (Novice User)\n List of choices in menu form.\n 2 PROMPT - (Intermediate User)\n Brief list of commands.\n 3 COMMAND - (Expert User)\n One word prompt.\n\n") + c, err := s.prompt(s.choicePrompt("Enter choice !")) + if err != nil { + return s.abortOK0(err) + } + if mode, ok := map[string]string{"1": mailMenu, "2": mailPrompt, "3": mailCommand}[strings.TrimSpace(c)]; ok { + s.mail.mode = mode + } + return nil +} + +// mailMode is MODE: the Mode Menu, and whether to keep it. +func (s *session) mailMode() error { + if err := s.chooseMode(); err != nil { + return err + } + return s.askKeep() +} + +func (s *session) askKeep() error { + c, err := s.prompt("\nMake changes permanent for\nfuture Mail sessions ? (Y or N) !") + if err != nil { + return s.abortOK0(err) + } + if strings.HasPrefix(strings.ToUpper(strings.TrimSpace(c)), "Y") { + s.keepMailSettings() + } + return nil +} + +// mailSet is SET option value: EDIT LINE|NOLINE, PAGE ON|OFF, MODE x, +// RETAIN YES|NO. These are kept. +func (s *session) mailSet(arg string) { + m := s.mail + k, v, _ := strings.Cut(strings.ToUpper(strings.TrimSpace(arg)), " ") + v = strings.TrimSpace(v) + switch { + case is(k, "EDITOR", 2): + m.lineEdit = v == "LINE" || v == "LINEDIT" || v == "YES" || v == "ON" + case is(k, "PAGED", 3) || is(k, "PAGING", 3): + m.paged = v == "ON" || v == "YES" + case is(k, "RETAIN", 3): + m.retain = v != "NO" && v != "OFF" + return + case is(k, "MODE", 2): + mode, ok := map[string]string{"MENU": mailMenu, "PROMPT": mailPrompt, "COMMAND": mailCommand}[v] + if !ok { + s.out("% Invalid command\n") + return + } + m.mode = mode + default: + s.out("% Invalid command\n") + return + } + s.keepMailSettings() +} + +// addressBook is ADDRESS: the Address Book menu. +func (s *session) addressBook() error { + for { + s.out("\nMail Address Book\n\n 1 INSERT an entry\n 2 CHANGE an entry\n 3 DELETE an entry\n 4 LIST Address Book\n 5 Enter/Change your NAME\n\n") + c, err := s.prompt(s.choicePrompt("Enter choice or to exit !")) + if err != nil { + return s.abortOK0(err) + } + c = strings.TrimSpace(c) + if c == "" { + return nil + } + if w, ok := map[string]string{"1": "INSERT", "2": "CHANGE", "3": "DELETE", "4": "LIST", "5": "NAME"}[c]; ok { + c = w + } + if err := s.addressCommand(c); err != nil { + return err + } + } +} + +// addressCommand is an Address Book command (ADDRESS NAME, ...). The +// book and the name last for the session. +func (s *session) addressCommand(c string) error { + m := s.mail + verb, arg := splitVerb(c) + switch { + case is(verb, "NAME", 2): + old := m.name + if old == "" { + old = s.user.Name + } + s.out("\nEnter a period to erase any information, or to leave it unchanged.\nTyping \"CANCEL\" cancels all changes made and leaves editing mode.\n\n") + s.outf("Your CompuServe Mail name\n Old: %s\n", old) + n, err := s.prompt(" New: ") + if err != nil { + return s.abortOK0(err) + } + switch n = strings.TrimSpace(n); { + case strings.EqualFold(n, "CANCEL"): + return nil + case n == ".": + m.name = "" + case n != "": + m.name = n + } + yn, err := s.prompt("\nDo you want to enter your return address? (Y or N) !") + if err != nil { + return s.abortOK0(err) + } + if strings.HasPrefix(strings.ToUpper(strings.TrimSpace(yn)), "Y") { + s.out("Return addresses are not kept on this service.\n") + } + case is(verb, "INSERT", 3) || is(verb, "CHANGE", 3) || is(verb, "ADD", 3): + name := strings.TrimSpace(arg) + if name == "" { + var err error + if name, err = s.prompt("Name: "); err != nil { + return s.abortOK0(err) + } + } + addr, err := s.prompt("Address: ") + if err != nil { + return s.abortOK0(err) + } + if strings.TrimSpace(name) != "" && strings.TrimSpace(addr) != "" { + m.book[strings.ToUpper(strings.TrimSpace(name))] = strings.TrimSpace(addr) + } + case is(verb, "DELETE", 3): + name := strings.TrimSpace(arg) + if name == "" { + var err error + if name, err = s.prompt("Name: "); err != nil { + return s.abortOK0(err) + } + } + delete(m.book, strings.ToUpper(strings.TrimSpace(name))) + case is(verb, "LIST", 2): + if len(m.book) == 0 { + s.out("Your Address Book is empty.\n") + } + for i, k := range sortedKeys(m.book) { + s.outf("%2d %-20s %s\n", i+1, k, m.book[k]) + } + default: + s.out("% Invalid command\n") + } + return nil +} + +func sortedKeys(m map[string]string) []string { + var out []string + for k := range m { + out = append(out, k) + } + for i := 1; i < len(out); i++ { + for j := i; j > 0 && out[j] < out[j-1]; j-- { + out[j], out[j-1] = out[j-1], out[j] + } + } + return out +} + +func (s *session) mailHelp() { + s.out(`CompuServe Mail commands: + READ [n|ALL|SAVED] read messages (then CR, DELETE, SAVE, REREAD, + REPLY, FORWARD or DOWNLOAD at "Action!") + SCAN [ALL|SAVED] list messages DELETE n delete one + COMPOSE [address] write and send UPLOAD send a file's text + DOWNLOAD [n] [/PROTO:B] ADDRESS the address book + SET [EDIT|PAGE|MODE x] EXIT, T, GO word, OFF +Addresses: a name, a User ID (72000,1), Name >INTERNET:72000.1@compuserve.com +`) +} diff --git a/internal/cis/pages.txt b/internal/cis/pages.txt index 0fa3431..6b9475a 100644 --- a/internal/cis/pages.txt +++ b/internal/cis/pages.txt @@ -60,8 +60,12 @@ downloads and uploads by the CompuServe B and B Plus protocols, XMODEM and Kermit. - On their way, in this order: CompuServe Mail, the CB Simulator, and - the CompuServe Information Manager (CIM) graphical service. + CompuServe Mail (GO MAIL) is the BBS's private mail, in menu, + prompt or command mode (SET), with downloads and uploads of mail by + the B protocols. Send to a name, a User ID, or a FidoNet address. + + On their way, in this order: the CB Simulator, and the CompuServe + Information Manager (CIM) graphical service. :RATES CHARGES BILLING NEWBIL =CompuServe @@ -131,10 +135,9 @@ 3 CB Simulator > CB 4 Member Directory > DIRECTORY -:MAIL EASY EASYPLEX +:MAIL EASY EASYPLEX MAILRATES =CompuServe Mail - CompuServe Mail is on its way. Until then, read and send your mail - on the BBS itself. + (Going here enters CompuServe Mail, on the BBS's private mail.) :FORUMS SIGS =CompuServe diff --git a/internal/server/cismail_test.go b/internal/server/cismail_test.go new file mode 100644 index 0000000..33e7cd4 --- /dev/null +++ b/internal/server/cismail_test.go @@ -0,0 +1,153 @@ +package server + +import ( + "bytes" + "io" + "strings" + "testing" + + "github.com/D-Modem/bbs/internal/ui3270" + "github.com/D-Modem/bbs/internal/xfer" +) + +// TestCompuServeMail: TAPCIS's PARAMS.SCR setup of Mail, a message sent +// to a User ID and read by its recipient in command mode, a download of +// it by B Plus, and a message uploaded TAPCIS's way. +func TestCompuServeMail(t *testing.T) { + e := startFull(t, ui3270.Graphics{}, nil, nil, cisListener()) + + d := cisLogin(e, "72000,1", "alicepass1") + // PARAMS.SCR, as TAPCIS 5.4 sends it: every reply waits for "!" + d.send("go mail\r") + d.expect("CompuServe Mail Main Menu") + d.expect("Enter choice !") + d.send("no\r") + d.expect("% Invalid command\r\n") + d.expect("!") + for _, c := range []string{"set edit noline", "set page off", "set retain YES"} { + d.send(c + "\r") + d.expect("Enter choice !") + } + d.send("set\r") + d.expect(" 2 MODE of operation is [MENU]") + d.expect("!") + d.send("2\r") + d.expect("Mail Mode Menu") + d.expect("!") + d.send("3\r") + d.expect(" 2 MODE of operation is [COMMAND]") + d.expect("!") + d.send("\r") + d.expect("future Mail sessions ? (Y or N) !") + d.send("Y\r") + d.expect("Mail!") + d.send("ADD\r") + d.expect("!") + d.send("NAME\r") + d.expect(" Old: alice\r\n New: ") + d.send("Alice A. [TAPCIS]\r") + d.expect("return address? (Y or N) !") + d.send("\x03") + d.expect("!") + d.send("\r") // the Address Book menu's exit + d.expect("Mail!") + + // a message to the sysop by User ID, with a bad address first + d.send("COMPOSE\r") + d.expect("Enter /EX to exit EDIT\r\n") + d.send("Hello from Mail.\r/ex\r") + d.expect("Send to (Name or User ID): ") + d.send("Bob >FAX:301-555-1212;\r") + d.expect("% FAX mail is not offered on this service: Bob >FAX:301-555-1212\r\n") + d.expect("Send to (Name or User ID): ") + d.send("Sysop 72000,2\r") + d.expect("Subject: ") + d.send("Testing\r") + d.expect("Send? (Y or N)! ") + d.send("Y\r") + d.expect("Message sent to sysop [72000,2]\r\n") + d.expect("Mail!") + d.send("OFF\r") + d.expect("Thank you for using CompuServe!") + + d = cisLogin(e, "72000,2", "sysoppass1") + d.expect("") // the banner came before the menu + d.send("GO MAIL\r") + d.expect("CompuServe Mail Main Menu") + d.expect(" 1 READ mail, 1 message pending") + d.expect("Enter choice !") + d.send("SET MODE COMMAND\r") + d.expect("Mail!") + d.send("SCAN\r") + d.expect(" 1 alice/Testing\r\n") + d.expect("Mail!") + d.send("read all\r") + d.expect("Date: ") + d.expect("\r\nFrom: alice [72000,1]\r\nSubj: Testing\r\n\r\nHello from Mail.\r\n") + d.expect("Action!") + d.send("\r") + d.expect("Mail!") + d.send("SCAN\r") + d.expect("No messages pending") + d.expect("Mail!") + d.send("DOW SAVED /PROTO:B\r") + d.expect("1 message and ") + d.expect(" characters ready for download\r\n") + term := xfer.NewBLink(d.port()) + if err := term.AnswerENQ(&xfer.BParams{WS: 1, WR: 1, BS: 8, CM: xfer.CheckCRC16}); err != nil { + t.Fatal(err) + } + var got bytes.Buffer + if err := term.Terminal(func(string, bool) (io.Writer, error) { return &got, nil }, nil); err != nil { + t.Fatal(err) + } + d.got = term.Rest() + if !strings.Contains(got.String(), "Subj: Testing\r\n\r\nHello from Mail.\r\n") { + t.Errorf("downloaded %q", got.String()) + } + d.expect("*** File Transfer Completed! ***") + d.expect("Mail!") + + // TAPCIS's upload of a reply + d.send("UPL/PRO:B/TYP:ASCII MAIL%.TMP\r") + d.expect("MAIL%.TMP\r\n") + term = xfer.NewBLink(d.port()) + if err := term.AnswerENQ(nil); err != nil { + t.Fatal(err) + } + if err := term.Terminal(nil, func(string) (io.Reader, error) { + return strings.NewReader("Got it.\r\nThanks.\r\n"), nil + }); err != nil { + t.Fatal(err) + } + d.got = term.Rest() + d.expect("Send to (Name or User ID): ") + d.send(">INTERNET:72000.1@compuserve.com\r") + d.expect("Subject: ") + d.send("Re: Testing\r") + d.expect("Send? (Y or N)! ") + d.send("y\r") + d.expect("Message sent to alice [72000,1]") + d.expect("Mail!") + d.send("READ SAVED\r") + d.expect("Hello from Mail.") + d.expect("Action!") + d.send("DELETE\r") + d.expect("Message deleted") + d.expect("Mail!") + d.send("EXIT\r") + d.expect("Enter choice !") + d.send("OFF\r") + d.expect("Thank you for using CompuServe!") + + // alice's mode was kept: straight to "Mail!", and the reply is there + d = cisLogin(e, "72000,1", "alicepass1") + d.send("GO MAIL\r") + d.expect("1 message pending") + d.expect("Mail!") + d.send("REA\r") + d.expect("From: sysop [72000,2]\r\nSubj: Re: Testing\r\n\r\nGot it.\r\nThanks.\r\n") + d.expect("Action!") + d.send("OFF\r") + d.expect("Thank you for using CompuServe!") +}