home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / reply.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  116 lines

  1. ############################################################################
  2. #
  3. #    File:     reply.icn
  4. #
  5. #    Subject:  Program to reply to news-articles or mail
  6. #
  7. #    Author:   Ronald Florence
  8. #
  9. #    Date:     March 8, 1991
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    Version:  1.4
  18. #
  19. ############################################################################
  20. #
  21. #  This program creates the appropriate headers and attribution, 
  22. #  quotes a news or mail message, and uses system() calls to put the
  23. #  user in an editor and then to mail the reply.  The default prefix 
  24. #  for quoted text is ` > '. 
  25. #
  26. #      usage: reply [prefix] < news-article or mail-item
  27. #
  28. #  If a smarthost is defined, Internet addresses are converted to bang
  29. #  paths (name@site.domain -> site.domain!name).  The mail is routed
  30. #  to a domained smarthost as address@smarthost.domain, otherwise to
  31. #  smarthost!address.
  32. #
  33. #  The default editor can be overridden with the EDITOR environment variable.
  34. #
  35. ############################################################################
  36.  
  37. procedure main(arg)
  38.   local smarthost, editor, console, tmpdir, tmpfile, reply, fullname
  39.   local address, quoter, date, id, subject, newsgroup, refs, edstr, stdin
  40.   local mailstr
  41.   
  42.   smarthost := ""
  43.   editor := "vi"
  44.  
  45.   if find("UNIX", &features) then {
  46.     console := "/dev/tty"
  47.     tmpdir := "/tmp/"
  48.   }
  49.   else if find("MS-DOS", &features) then {
  50.     console := "CON"
  51.     tmpdir := ""
  52.   }
  53.   (\console & \tmpdir) | stop("reply: missing system information")
  54.  
  55.   every tmpfile := tmpdir || "reply." || right(1 to 999,3,"0") do
  56.     close(open(tmpfile)) | break
  57.   reply := open(tmpfile, "w") | stop("reply: cannot write temp file")
  58.  
  59.                 # Case-insensitive matches for headers.
  60.   every !&input ? {
  61.     tab(match("from: " | "reply-to: ", map(&subject))) & {
  62.       if find("<") then {
  63.     fullname := tab(upto('<'))
  64.     address := (move(1), tab(find(">")))
  65.       }
  66.       else {
  67.     address := trim(tab(upto('(') | 0))
  68.     fullname := (move(1), tab(find(")")))
  69.       }
  70.       while match(" ", \fullname, *fullname) do fullname ?:= tab(-1)
  71.       quoter := if *\fullname > 0 then fullname else address
  72.     }
  73.     tab(match("date: ", map(&subject))) & date := tab(0)
  74.     tab(match("message-id: ", map(&subject))) & id := tab(0)
  75.     match("subject: ", map(&subject)) & subject := tab(0)
  76.     match("newsgroups: ", map(&subject)) & newsgroup := tab(upto(',') | 0)
  77.     match("references: ", map(&subject)) & refs := tab(0)
  78.     (\address & *&subject = 0) & {
  79.       \subject & write(reply, subject)
  80.       \newsgroup & write(reply, newsgroup)
  81.       \refs & write(reply, refs, " ", id)
  82.       write(reply, "In-reply-to: ", quoter, "'s message of ", date);
  83.       write(reply, "\nIn ", id, ", ", quoter, " writes:\n")
  84.       break
  85.     }
  86.   }
  87.  
  88.   every write(reply, \arg[1] | " > ", !&input)
  89.   edstr := (getenv("EDITOR") | editor) || " " || tmpfile || " < " || console
  90.   system(edstr)
  91.   stdin := open(console)
  92.   writes("Send y/n? ")
  93.   upto('nN', read(stdin)) & {
  94.     writes("Save your draft reply y/n? ")
  95.     if upto('yY', read(stdin)) then 
  96.       stop("Your draft reply is saved in ", tmpfile)
  97.     else {
  98.       remove(tmpfile)
  99.       stop("Reply aborted.")
  100.     }
  101.   }
  102.  
  103.   (*smarthost > 0) & not find(map(smarthost), map(address)) & {
  104.     find("@", address) & address ? {
  105.       name := tab(upto('@'))
  106.       address := (move(1), tab(upto(' ') | 0)) || "!" || name
  107.     }
  108.     if find(".", smarthost) then address ||:= "@" || smarthost
  109.     else address := smarthost || "!" || address
  110.   }
  111.   mailstr := "mail " || address || " < " || tmpfile
  112.   system(mailstr)
  113.   write("Reply sent to " || address)
  114.   remove(tmpfile)
  115. end
  116.