home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROGS.LZH
/
POST.ICN
< prev
next >
Wrap
Text File
|
1991-09-05
|
7KB
|
210 lines
############################################################################
#
# Name: post.icn
#
# Title: News Poster
#
# Author: Ronald Florence
#
# Version: 1.1
#
# Date: January 31, 1991
#
############################################################################
#
# This program posts a news article to Usenet via uux or mail.
# Given an optional argument (the name of a file containing a
# news article), it creates a follow-up article, with an
# attribution and quoted text.
#
# usage: post [news-article]
#
############################################################################
#
# Configure: smarthost, mode, unixtype, editor or EDITOR env. variable.
#
############################################################################
#
# Requires: UNIX or MS-DOS
# Bugs: MS-DOS requires hard-coded system information
# Does not check validity of Newsgroups or Distribution.
#
############################################################################
global sitename, domain, tz, tmpfile
procedure main(arg)
smarthost := "news-feed" # Your news feed.
mode := "uux" # Use "mail" for a sendnews feed.
unixtype := "bsd" # Use "usg" for "-Full Name(" passwd file.
domain := ".UUCP"
if (find("UNIX", &features) & find("pipes", &features)) then {
console := "/dev/tty"
tmpdir := "/tmp/"
(inf := open("logname", "pr")) & (logname := !inf) & close(inf)
# Uuname sometimes pads with spaces.
(inf := open("uuname -l", "pr")) & (sitename := trim(!inf)) & close(inf)
(tz := getenv("TZ")) & tz ?:= (tab(many(&letters)), tab(upto(&letters)))
\logname & (inf := open("/etc/passwd")) & every s := !inf do s ? {
=(logname) & {
every tab(upto(':')+1) \4
if unixtype == "bsd" then fullname := tab(upto(',:'))
else fullname := (tab(upto('-')+1), tab(upto('(:')))
close(inf)
break
}
}
sigfile := getenv("HOME") || "/.signature"
editor := "/bin/vi"
}
else if find("MS-DOS", &features) then {
console := "CON"
tmpdir := ""
logname := &null
sitename := &null
tz := &null # Hours off GMT.
fullname := &null
sigfile := &null
editor := "edlin"
}
(\logname & \sitename & \tz) | stop("post: missing system info")
article := open(tmpfile := tempname(tmpdir), "w") |
stop("post: cannot write temp file")
write(article, "Path: ", sitename, "!", logname)
writes(article, "From: ", logname, "@", sitename, domain)
\fullname & writes(article, " (", fullname, ")")
write(article)
if \arg[1] then {
inf := open(arg[1]) | {
remove(tmpfile)
stop("post: cannot read ", arg[1])
}
reply_headers(inf, article)
every write(article, " > ", !inf)
close(inf)
}
else {
write(article, query("Newsgroups: "))
write(article, query("Subject: "))
write(article, query("Distribution: "))
every write(article, req_headers())
write(article, "\n")
}
edstr := (getenv("EDITOR") | editor) || " " || tmpfile || " < " || console
system(edstr)
writes("Are you sure you want to post this to Usenet y/n? ")
stdin := open(console)
upto('nN', read(stdin)) & {
remove(tmpfile)
exit(1)
}
# Try to append the .signature.
\sigfile & (inf := open(sigfile)) & {
article := open(tmpfile, "a")
write(article, "--")
every write(article, !inf)
close(inf)
}
# Don't force an immediate poll.
if mode == "uux" then mode ||:= " - -r"
# Sendnews format requires an initial `N'.
else if mode == "mail" then {
inf := open(tmpfile)
outf := open(tmp2 := tempname(tmpdir), "w")
every write(outf, "N", !inf)
remove(tmpfile)
rename(tmp2, tmpfile)
}
mode ||:= " " || smarthost || "!rnews < " || tmpfile
(system(mode) = 0) & write("Article posted!")
remove(tmpfile)
end
procedure tempname(dir)
every temp_name := dir || "article." || right(1 to 999,3,"0") do {
close(open(temp_name)) & next
suspend \temp_name
}
end
procedure reply_headers(infile, art)
every s := !infile do s ? {
# Case-insensitive matches for headers.
tab(match("from: ", map(&subject))) & {
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)
}
tab(match("date: ", map(&subject))) & date := tab(0)
tab(match("message-id: ", map(&subject))) & id := tab(0)
match("subject: ", map(&subject)) & subject := s
match("distribution: ", map(&subject)) & distribution := s
match("newsgroups: " | "followup-to: ", map(&subject)) &
newsgroup := tab(upto(',') | 0)
match("references: ", map(&subject)) & refs := s
(\quoter & *s = 0) & {
find("poster", newsgroup) & {
write(quoter, " has requested followups by email.")
writes("Do you want to abort this posting y/n? ")
upto('yY', read()) & {
remove(tmpfile)
exit(1)
}
newsgroup := &null
}
# Newsgroup and subject are required.
write(art, \newsgroup | query("Newsgroup: "))
write(art, \subject | query("Subject: "))
write(art, \distribution | query("Distribution: "))
# Message-ID and Date go here.
every write(art, req_headers())
# Threaded readers need References.
write(art, \refs | "References:", " ", id)
write(art, "In-reply-to: ", quoter, "'s message of ", date)
write(art, "\nIn ", id, ", ", quoter, " writes:\n")
return
}
}
end
procedure req_headers()
# Crude, but it's a unique id.
uniq := "<"
&date || &clock ? while tab(upto(&digits)) do uniq ||:= tab(many(&digits))
uniq ||:= "@" || sitename || domain || ">"
# Date in RFC 822 format.
&dateline ? {
month := left((tab(find(" ")+1), tab(many(&letters))), 3) || " "
date := (tab(upto(&digits)), tab(many(&digits))) || " " || month
date ||:= (tab(upto(&digits)), right(tab(many(&digits)), 2))
}
# GMT would be better; this is allowed.
if (tz > 0) then zone := " -"
else zone := " +"
zone ||:= left(right(abs(tz), 2, "0"), 4, "0")
suspend "Message-ID: " || uniq
suspend "Date: " || date || " " || &clock || zone
end
procedure query(prompt)
writes(prompt)
ans := read()
return prompt || ans
end