home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / relay / sh / defhdrs.awk < prev    next >
Text File  |  1989-10-14  |  3KB  |  110 lines

  1. # defhdrs.awk
  2. # pass 1 - note presence | absence of certain headers
  3. # a header keyword: remember it and its value
  4. /^[^\t ]*:/ {
  5.     hdrval[$1] = $0
  6.     keyword=$1
  7.     next
  8. }
  9. # a continuation: concatenate this line to the value
  10.     { hdrval[keyword] = hdrval[keyword] "\n" $0 }
  11.  
  12. END {
  13.     # pass 2 - cogitate & omit & emit headers
  14.     emptyhdrre = "^[^\t ]*:[\t ]*$"
  15.     subjname = "Subject:"
  16.     ctlname = "Control:"
  17.     ngname = "Newsgroups:"
  18.     msgidname = "Message-ID:"
  19.     typoname =  "Message-Id:"
  20.     pathname = "Path:"
  21.     datename = "Date:"
  22.     fromname = "From:"
  23.     orgname = "Organization:"
  24.     distrname = "Distribution:"
  25.     sendername = "Sender:"
  26.  
  27.     # nullify headers with empty contents
  28.     for (i in hdrval)
  29.         if (hdrval[i] ~ /^[^\t ]*:[\t ]*$/)
  30.             hdrval[i] = ""
  31.  
  32.     # fill in missing headers
  33.     if (hdrval[typoname] != "") {    # spelling hack
  34.         hdrval[msgidname] = hdrval[typoname]
  35.         hdrval[typoname] = ""
  36.         # fix spelling: Message-Id: -> Message-ID:
  37.         nf = split(hdrval[msgidname], fields);    # bust up
  38.         fields[1] = msgidname;        # fix spelling
  39.         hdrval[msgidname] = fields[1];    # reassemble...
  40.         for (i = 2; i <= nf; i++)
  41.             hdrval[msgidname] = hdrval[msgidname] " " fields[i]
  42.     }
  43.     if (hdrval[pathname] == "")
  44.         hdrval[pathname] = pathname " " defpath
  45.     if (hdrval[msgidname] == "")
  46.         hdrval[msgidname] = msgidname " " defmsgid
  47.     if (hdrval[datename] == "")
  48.         hdrval[datename] = datename " " defdate
  49.     if (hdrval[orgname] == "")
  50.         hdrval[orgname] = orgname " " deforg
  51.     if (hdrval[fromname] == "")
  52.         hdrval[fromname] = fromname " " deffrom
  53.     else if (hdrval[sendername] == "")
  54.         hdrval[sendername] = sendername " " deffrom
  55.  
  56.     # replace user's headers (if any) [this is not currently done]
  57.  
  58.     # snuff some headers
  59.     distworld = distrname " world"
  60.     if (hdrval[distrname] == distworld)
  61.         hdrval[distrname] = ""
  62.  
  63.     # the vile cmsg hack, for the sake of the news readers *only*
  64.     if (hdrval[ctlname] == "" && \
  65.         substr(hdrval[subjname], 1, 14) == "Subject: cmsg ")
  66.         hdrval[ctlname] = ctlname " " substr(hdrval[subjname], 15)
  67.  
  68.     # warn if no Newsgroups:
  69.     if (hdrval[ngname] == "")
  70.         print "no newsgroups header!" | "cat >&2"
  71.  
  72.     # field the all.all.ctl hack, for the sake of the backward only:
  73.     # clone Subject: to make Control:
  74.     if (hdrval[ctlname] == "" && hdrval[ngname] ~ /\.ctl(,|$)/)
  75.         hdrval[ctlname] = ctlname " " substr(hdrval[subjname], 8)
  76.  
  77.     # reorder & emit headers
  78.  
  79.     # favour Control: & Newsgroups: for future benefit of rnews
  80.     if (hdrval[ctlname] != "") {
  81.         print hdrval[ctlname]
  82.         hdrval[ctlname] = ""    # no Control: to print now
  83.     }
  84.     if (hdrval[ngname] != "") {
  85.         print hdrval[ngname]
  86.         hdrval[ngname] = ""    # no Newsgroups: to print now
  87.     }
  88.  
  89.     # B inews kludgery: print Path: before From: to avoid confusing it
  90.     if (hdrval[pathname] != "") {
  91.         print hdrval[pathname]
  92.         hdrval[pathname] = ""    # no Path: to print now
  93.     }
  94.     if (hdrval[fromname] != "") {
  95.         print hdrval[fromname]
  96.         hdrval[fromname] = ""    # no From: to print now
  97.     }
  98.  
  99.     # have pity on readers: put Subject: next
  100.     if (hdrval[subjname] != "") {
  101.         print hdrval[subjname]
  102.         hdrval[subjname] = ""    # no Subject: to print now
  103.     }
  104.  
  105.     # print misc. non-empty headers in random order
  106.     for (i in hdrval)
  107.         if (hdrval[i] != "" && hdrval[i] !~ /^[^\t ]*:[\t ]*$/)
  108.             print hdrval[i]
  109. }
  110.