home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / gopher / gopher1.01 / misc / shell-utils / gateway next >
Text File  |  1991-12-02  |  2KB  |  142 lines

  1. #!/usr/local/bin/perl
  2.  
  3. sub dokill {
  4.     kill 9,$child if $child;
  5. }
  6.  
  7. sub Opengopher {
  8.  
  9.     local($them,$port) = @_;    
  10.     $them = 'localhost' unless $them;
  11.  
  12.     $AF_INET = 2;
  13.     $SOCK_STREAM = 1;
  14.  
  15.     $SIG{'INT'} = 'dokill';
  16.  
  17.     $sockaddr = 'S n a4 x8';
  18.  
  19.     chop($hostname = `hostname`);
  20.  
  21.     ($name,$aliases,$proto) = getprotobyname('tcp');
  22.     ($name,$aliases,$port) = getservbyname($port,'tcp')
  23.     unless $port =~ /^\d+$/;;
  24.     ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
  25.     ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
  26.  
  27.     $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
  28.     $that = pack($sockaddr, $AF_INET, $port, $thataddr);
  29.  
  30.     # Make the socket filehandle.
  31.     socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
  32.  
  33.     # Give the socket an address.
  34.     bind(S, $this) || die $!;
  35.  
  36.     # Call up the server.
  37.     connect(S,$that) || die $!;
  38.  
  39.     # Set socket to be command buffered.
  40.     select(S); $| = 1; select(STDOUT);
  41.  
  42. }
  43.  
  44.  
  45. sub ParseMail {
  46.     
  47.     # First parse out the header lines.
  48.  
  49.     while (<>) {
  50.     chop;
  51.  
  52.     if (/^$/) {
  53.         # end of headers
  54.         last;
  55.     }
  56.  
  57.     if (/^Reply-To: (.*)/) {
  58.         print "Mailaddr is $1\n";
  59.         }
  60.  
  61.     if (/^From: "(.*)" <(.*)>$/) {
  62.         print "Realname is $1, mailaddr is $2\n";
  63.     }
  64.  
  65.     elsif (/^From: (.*) <(.*)>$/) {
  66.         print "Realname is $1, mailaddr is $2\n";
  67.         $mailaddr = $2;
  68.     }
  69.  
  70.     elsif (/^From: (.*) \((.*)\)$/) {
  71.         print "Realname is $1, mailaddr is $2\n";
  72.     }
  73.  
  74.     elsif (/^From: (.*)$/) {
  75.         print "Realname is $1, mailaddr is $2\n";
  76.     }
  77.  
  78.     }
  79.  
  80.     # Start collecting search words
  81.  
  82.     while (<>) {
  83.     chop;
  84.     
  85.     if (/^--$/) {        # Usually denotes .signature
  86.         last;
  87.     }
  88.  
  89.     @linewords = split;
  90.     
  91.     foreach $i (@linewords) {
  92.         $i =~ s/[\.\!\?\:\,\-\~\/\\]*$//;
  93.  
  94.         if (length($i) >50) { # Probably some long ------ type of thing
  95.         next;
  96.         }
  97.  
  98.         if (length($i) <3) {
  99.         next;
  100.             }
  101.  
  102.         $indexwords{$i} ++;
  103.         
  104.     }
  105.     }
  106.  
  107.     @names = keys(indexwords);
  108.     
  109.     foreach $i (@names) {
  110.     print $i . " $indexwords{$i}\n";
  111.     }
  112. #
  113. # Open up the socket
  114. #
  115.  
  116.     &Opengopher("ashpool.micro.umn.edu", "158");
  117.  
  118.     foreach $i (@names) {
  119.     print S "$i or ";
  120.     }
  121.  
  122.  
  123. print S "\r\n";
  124.  
  125. while (<S>) {
  126.     chop;
  127.     chop;
  128.     print;
  129.     print "\n";
  130. }
  131.  
  132.  
  133.  
  134. while ($arg = shift(@ARGV)) {
  135.     if ($arg eq "-l") {
  136.     $LongFlag = 1;
  137.     }
  138. }
  139. }
  140.  
  141. &ParseMail;
  142.