Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!hsi!mlfarm!ron From: ron@mlfarm.com (Ronald Florence) Newsgroups: comp.lang.icon Subject: Re: Message conventions Message-ID: <678@mlfarm.com> Date: 5 Jan 91 18:05:11 GMT References: <675@mlfarm.com> Sender: ron@mlfarm.com Distribution: comp Organization: Maple Lawn Farm, Stonington, CT Lines: 97 In-reply-to: ron@mlfarm.com's message of 2 Jan 91 11:57:01 GMT The version of reply.icn I posted earlier contained a subtle bug that could break on some obscure headers. The version below fixes the bug, adds additional functionality, and thanks to Richard Goerwitz, includes more robust code to create a temporary filename. I've also substituted some of Richard's elegant constructions for my quick and dirty Icon hacks. [Ralph -- use this version, please.] ----------------------------[reply.icn, 1.1]--------------------------- # reply.icn - replies to news or mail # version 1.1 (ron@mlfarm.com, 5 Jan 91) # # usage: reply [quote-prefix] < news-article or mail-item # # Configuration: # - change smarthost to the name of your upstream mail feed. # - change the default editor for your operating system, or use the # EDITOR environment variable. # - if your upstream mail feed will not accept addresses in the format # site.domain!user@upstream-host.domain, you may need to change the # address parsing code. # # The default quote-prefix is " > ". procedure main(arg) smarthost := "mlfarm.com" if find("UNIX", &features) then { console := "/dev/tty" tmpdir := "/tmp/" editor := "/bin/vi" } else if find("MS-DOS", &features) then { console := "CON" tmpdir := "" editor := "edlin" } else stop("reply: unsupported operating system") every tmpfile := tmpdir || "reply." || right(1 to 999,3,"0") do close(open(tmpfile)) | break reply := open(tmpfile, "w") | stop("reply: cannot open temp file") every s := !&input do s ? { =("From: " | "Reply-To: ") & { if find("<") then { fullname := trim(tab(upto('<'))) address := (move(1), tab(find(">"))) } else { address := trim(tab(upto('(') | 0)) fullname := (move(1), tab(find(")"))) } quoter := (\fullname | address) } =("Date: ") & date := tab(0) =("Message-Id: ") & id := (tab(find("<")), tab(find(">")+1)) match("Subject: ") & subject := s match("Newsgroups: ") & newsgroup := tab(upto(',') | 0) match("References: ") & refs := s (\address & *s = 0) & { write(reply, "In-reply-to: ", quoter, "'s message of ", date); \subject & write(reply, subject) \newsgroup & write(reply, newsgroup) \refs & write(reply, refs || " " || id) write(reply, "\nIn ", id, ", ", quoter, " writes:\n") break } } prefix := \arg[1] | " > " every write(reply, prefix, !&input) edstr := (getenv("EDITOR") | editor) || " " || tmpfile || " < " || console system(edstr) stdin := open(console, "r") writes("Send y/n? ") upto('nN',read(stdin)) & { remove(tmpfile) stop("Reply aborted.") } find("@",address) & address ? { name := tab(upto('@')) address := (move(1), tab(upto(' ') | 0)) || "!" || name } address ||:= "@" || smarthost mailstr := "mail " || address || " < " || tmpfile system(mailstr) write("Reply sent to " || address) remove(tmpfile) end ----------------------------------[eof]-------------------------------- -- Ronald Florence ron@mlfarm.com