home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / std_unix / newstomail < prev    next >
Text File  |  1987-06-30  |  2KB  |  99 lines

  1. #!/bin/sh
  2. PATH=/usr/local:/usr/ucb:/bin:/usr/bin
  3. export PATH
  4.  
  5. case $1 in
  6. "")
  7.     echo "Usage:  newstomail address"
  8.     exit 1
  9.     ;;
  10. *)
  11.     to=$1
  12.     shift
  13.     ;;
  14. esac
  15.  
  16. awk '
  17. BEGIN {
  18.     header = 1;
  19.     date = "";
  20. }
  21. header == 1 && /^$/ {
  22.     header = 0;
  23.     if (pdate != "" && date ~ /GMT/ && pdate !~ /GMT/) {
  24.         print "Date: "pdate;
  25.         print "Posted-Date: "date;
  26.     } else {
  27.         if (date != "")
  28.             print "Date: "date;
  29.         if (pdate != "")
  30.             print "Posted-Date: "pdate;
  31.     }
  32. }
  33. header == 0 {
  34.     print $0;
  35.     next;
  36. }
  37. $1 == "Relay-Version:"        { next; }
  38. $1 == "Posting-Version:"    { next; }
  39. $1 == "Path:"        { next; }
  40. #$1 == "Newsgroups:"    { next; }
  41. $1 == "From"        { next; }
  42. $1 == "Date-Received:"    { next; }
  43. $1 == "Received-Date:"    { next; }
  44. #$1 == "Organization:"    { next; }
  45. $1 == "Approved:"    { next; }
  46. $1 == "Lines:"        { next; }
  47. $1 == "Date:" {
  48.     date = $2;
  49.     for (i = 3; i <= NF; i++)
  50.         date = date " " $i;
  51.     next;
  52. }
  53. $1 == "Posted-Date:" {
  54.     pdate = $2;
  55.     for (i = 3; i <= NF; i++)
  56.         pdate = pdate " " $i;
  57.     next;
  58. }
  59. $1 == "From:" {
  60.     address=$2;
  61.     name = "";
  62.     surround = 0;
  63.     for (f = 3; f <= NF; f++) {
  64.         if ($f ~ /,/)
  65.             surround=1;
  66.         if (split ($f, parts, "(") > 1)
  67.             it = parts[2];
  68.         else
  69.             it = $f;
  70.         if (split ($f, parts, ")") > 1)
  71.             it = parts[1];
  72.         if (name == "")
  73.             name = it;
  74.         else
  75.             name = name " " it;
  76.     }
  77.     if (address ~ /.UUCP$/) {
  78.         split(address, parts, "@");
  79.         address = sprintf ("%s%%%s@%s", \
  80.             parts[1], parts[2], "'`hostname`'");
  81.     }
  82.     if (surround != 0)
  83.         printf ("From: %s (%s)\n", address, name);
  84.     else
  85.         printf ("From: %s <%s>\n", name, address);
  86.     next;
  87. }
  88. {
  89.     print $0;
  90. }' |
  91. case $to in
  92. "-")
  93.     cat -u
  94.     ;;
  95. *)
  96.     /bin/mail $to
  97.     ;;
  98. esac
  99.