#!/usr/bin/awk
# $Id: sm_slox_merge,v 1.5 2003/12/02 15:43:18 sesam Exp $
# Sesam Server module for searching "Subject" lines in not file and append it 
# to lis file 
BEGIN {
file=ARGV[2]
FS="\\.:[ ]|Subject: ./"
}

/sbc-3201/ { 
  found=0
  while (getline line <file > 0)
  { 
  split(line,filename,"\"")
  if (filename[2] == $2".")
   {
    gsub("/","_",$3) 
    gsub("*","_",$3) 
    sub(/[0-9]*\./,$3" (&)",line) 
    sub("var/spool/imap","IMAP:",line) 
    sub("IMAP:/","IMAP:",line) 
    sub(" f "," M ",line) 
    print line
    found=1
    break
   }
  }
  if (found != 1)
  {
   close(file)
   while (getline line <file > 0)
  { 
  split(line,filename,"\"")
  if (filename[2] == $2".")
   {
    gsub("/","_",$3) 
    sub(/[0-9]*\./,$3" (&)",line) 
    sub("var/spool/imap/user","IMAP:",line) 
    sub("IMAP:/","IMAP:",line) 
    sub(" f "," M ",line) 
    print line
    found=1
    break
   }
  }
  print "Not found ! :",$2
 }
}
