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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
############################################################################
#
# File: reply.icn
#
# Subject: Program to reply to news-articles or mail
#
# Author: Ronald Florence
#
# Date: March 8, 1991
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# Version: 1.4
#
############################################################################
#
# This program creates the appropriate headers and attribution,
# quotes a news or mail message, and uses system() calls to put the
# user in an editor and then to mail the reply. The default prefix
# for quoted text is ` > '.
#
# usage: reply [prefix] < news-article or mail-item
#
# If a smarthost is defined, Internet addresses are converted to bang
# paths (name@site.domain -> site.domain!name). The mail is routed
# to a domained smarthost as address@smarthost.domain, otherwise to
# smarthost!address.
#
# The default editor can be overridden with the EDITOR environment variable.
#
############################################################################
procedure main(arg)
local smarthost, editor, console, tmpdir, tmpfile, reply, fullname
local address, quoter, date, id, subject, newsgroup, refs, edstr, stdin
local mailstr
smarthost := ""
editor := "vi"
if find("UNIX", &features) then {
console := "/dev/tty"
tmpdir := "/tmp/"
}
else if find("MS-DOS", &features) then {
console := "CON"
tmpdir := ""
}
(\console & \tmpdir) | stop("reply: missing system information")
every tmpfile := tmpdir || "reply." || right(1 to 999,3,"0") do
close(open(tmpfile)) | break
reply := open(tmpfile, "w") | stop("reply: cannot write temp file")
# Case-insensitive matches for headers.
every !&input ? {
tab(match("from: " | "reply-to: ", map(&subject))) & {
if find("<") then {
fullname := tab(upto('<'))
address := (move(1), tab(find(">")))
}
else {
address := trim(tab(upto('(') | 0))
fullname := (move(1), tab(find(")")))
}
while match(" ", \fullname, *fullname) do fullname ?:= tab(-1)
quoter := if *\fullname > 0 then fullname else address
}
tab(match("date: ", map(&subject))) & date := tab(0)
tab(match("message-id: ", map(&subject))) & id := tab(0)
match("subject: ", map(&subject)) & subject := tab(0)
match("newsgroups: ", map(&subject)) & newsgroup := tab(upto(',') | 0)
match("references: ", map(&subject)) & refs := tab(0)
(\address & *&subject = 0) & {
\subject & write(reply, subject)
\newsgroup & write(reply, newsgroup)
\refs & write(reply, refs, " ", id)
write(reply, "In-reply-to: ", quoter, "'s message of ", date);
write(reply, "\nIn ", id, ", ", quoter, " writes:\n")
break
}
}
every write(reply, \arg[1] | " > ", !&input)
edstr := (getenv("EDITOR") | editor) || " " || tmpfile || " < " || console
system(edstr)
stdin := open(console)
writes("Send y/n? ")
upto('nN', read(stdin)) & {
writes("Save your draft reply y/n? ")
if upto('yY', read(stdin)) then
stop("Your draft reply is saved in ", tmpfile)
else {
remove(tmpfile)
stop("Reply aborted.")
}
}
(*smarthost > 0) & not find(map(smarthost), map(address)) & {
find("@", address) & address ? {
name := tab(upto('@'))
address := (move(1), tab(upto(' ') | 0)) || "!" || name
}
if find(".", smarthost) then address ||:= "@" || smarthost
else address := smarthost || "!" || address
}
mailstr := "mail " || address || " < " || tmpfile
system(mailstr)
write("Reply sent to " || address)
remove(tmpfile)
end
|